1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
30 #include "contiguous.H"
32 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
34 // Construct from Istream
36 Foam::List<T>::List(Istream& is)
40 operator>>(is, *this);
45 Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
50 is.fatalCheck("operator>>(Istream&, List<T>&)");
54 is.fatalCheck("operator>>(Istream&, List<T>&) : reading first token");
56 if (firstToken.isCompound())
60 dynamicCast<token::Compound<List<T> > >
62 firstToken.transferCompoundToken()
66 else if (firstToken.isLabel())
68 label s = firstToken.labelToken();
70 // Set list length to that read
73 // Read list contents depending on data format
75 if (is.format() == IOstream::ASCII || !contiguous<T>())
77 // Read beginning of contents
78 char delimiter = is.readBeginList("List");
82 if (delimiter == token::BEGIN_LIST)
84 for (register label i=0; i<s; i++)
90 "operator>>(Istream&, List<T>&) : reading entry"
101 "operator>>(Istream&, List<T>&) : "
102 "reading the single entry"
105 for (register label i=0; i<s; i++)
112 // Read end of contents
113 is.readEndList("List");
119 is.read(reinterpret_cast<char*>(L.data()), s*sizeof(T));
123 "operator>>(Istream&, List<T>&) : reading the binary block"
128 else if (firstToken.isPunctuation())
130 if (firstToken.pToken() != token::BEGIN_LIST)
132 FatalIOErrorIn("operator>>(Istream&, List<T>&)", is)
133 << "incorrect first token, expected '(', found "
135 << exit(FatalIOError);
138 // Putback the openning bracket
139 is.putBack(firstToken);
141 // Now read as a singly-linked list
144 // Convert the singly-linked list to this list
149 FatalIOErrorIn("operator>>(Istream&, List<T>&)", is)
150 << "incorrect first token, expected <int> or '(', found "
152 << exit(FatalIOError);
160 Foam::List<T> Foam::readList(Istream& is)
163 token firstToken(is);
164 is.putBack(firstToken);
166 if (firstToken.isPunctuation())
168 if (firstToken.pToken() != token::BEGIN_LIST)
170 FatalIOErrorIn("readList<T>(Istream&)", is)
171 << "incorrect first token, expected '(', found "
173 << exit(FatalIOError);
176 // read via a singly-linked list
181 // create list with a single item
191 // ************************************************************************* //