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 \*---------------------------------------------------------------------------*/
33 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
37 void Foam::PtrList<T>::read(Istream& is, const INew& inewt)
39 is.fatalCheck("PtrList<T>::read(Istream&, const INew&)");
45 "PtrList<T>::read(Istream&, const INew&) : "
49 if (firstToken.isLabel())
52 label s = firstToken.labelToken();
56 // Read beginning of contents
57 char delimiter = is.readBeginList("PtrList");
61 if (delimiter == token::BEGIN_LIST)
69 "PtrList<T>::read(Istream&, const INew&) : "
76 T* tPtr = inewt(is).ptr();
81 "PtrList<T>::read(Istream&, const INew&) : "
82 "reading the single entry"
85 for (label i=1; i<s; i++)
87 set(i, tPtr->clone());
92 // Read end of contents
93 is.readEndList("PtrList");
95 else if (firstToken.isPunctuation())
97 if (firstToken.pToken() != token::BEGIN_LIST)
101 "PtrList<T>::read(Istream&, const INew&)",
103 ) << "incorrect first token, '(', found " << firstToken.info()
104 << exit(FatalIOError);
113 lastToken.isPunctuation()
114 && lastToken.pToken() == token::END_LIST
118 is.putBack(lastToken);
119 sllPtrs.append(inewt(is).ptr());
123 setSize(sllPtrs.size());
128 typename SLList<T*>::iterator iter = sllPtrs.begin();
129 iter != sllPtrs.end();
140 "PtrList<T>::read(Istream&, const INew&)",
142 ) << "incorrect first token, expected <int> or '(', found "
144 << exit(FatalIOError);
149 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
153 Foam::PtrList<T>::PtrList(Istream& is, const INew& inewt)
160 Foam::PtrList<T>::PtrList(Istream& is)
166 // * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
169 Foam::Istream& Foam::operator>>(Istream& is, PtrList<T>& L)
172 L.read(is, INew<T>());
178 // * * * * * * * * * * * * * * * Ostream Operators * * * * * * * * * * * * * //
181 Foam::Ostream& Foam::operator<<(Ostream& os, const PtrList<T>& L)
183 // Write size and start delimiter
184 os << nl << L.size() << nl << token::BEGIN_LIST;
192 // Write end delimiter
193 os << nl << token::END_LIST << nl;
195 // Check state of IOstream
196 os.check("Ostream& operator<<(Ostream&, const PtrList&)");
202 // ************************************************************************* //