1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM 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 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
31 #include "contiguous.H"
33 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
35 // Construct from Istream
37 Foam::List<T>::List(Istream& is)
41 operator>>(is, *this);
46 Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
51 is.fatalCheck("operator>>(Istream&, List<T>&)");
55 is.fatalCheck("operator>>(Istream&, List<T>&) : reading first token");
57 if (firstToken.isCompound())
61 dynamicCast<token::Compound<List<T> > >
63 firstToken.transferCompoundToken()
67 else if (firstToken.isLabel())
69 label s = firstToken.labelToken();
71 // Set list length to that read
74 // Read list contents depending on data format
76 if (is.format() == IOstream::ASCII || !contiguous<T>())
78 // Read beginning of contents
79 char delimiter = is.readBeginList("List");
83 if (delimiter == token::BEGIN_LIST)
85 for (register label i=0; i<s; i++)
91 "operator>>(Istream&, List<T>&) : reading entry"
102 "operator>>(Istream&, List<T>&) : "
103 "reading the single entry"
106 for (register label i=0; i<s; i++)
113 // Read end of contents
114 is.readEndList("List");
120 is.read(reinterpret_cast<char*>(L.data()), s*sizeof(T));
124 "operator>>(Istream&, List<T>&) : reading the binary block"
129 else if (firstToken.isPunctuation())
131 if (firstToken.pToken() != token::BEGIN_LIST)
133 FatalIOErrorIn("operator>>(Istream&, List<T>&)", is)
134 << "incorrect first token, expected '(', found "
136 << exit(FatalIOError);
139 // Putback the openning bracket
140 is.putBack(firstToken);
142 // Now read as a singly-linked list
145 // Convert the singly-linked list to this list
150 FatalIOErrorIn("operator>>(Istream&, List<T>&)", is)
151 << "incorrect first token, expected <int> or '(', found "
153 << exit(FatalIOError);
161 Foam::List<T> Foam::readList(Istream& is)
164 token firstToken(is);
165 is.putBack(firstToken);
167 if (firstToken.isPunctuation())
169 if (firstToken.pToken() != token::BEGIN_LIST)
171 FatalIOErrorIn("readList<T>(Istream&)", is)
172 << "incorrect first token, expected '(', found "
174 << exit(FatalIOError);
177 // read via a singly-linked list
182 // create list with a single item
192 // ************************************************************************* //