1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
32 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
36 void Foam::PtrList<T>::read(Istream& is, const INew& inewt)
38 is.fatalCheck("PtrList<T>::read(Istream&, const INew&)");
44 "PtrList<T>::read(Istream&, const INew&) : "
48 if (firstToken.isLabel())
51 label s = firstToken.labelToken();
55 // Read beginning of contents
56 char delimiter = is.readBeginList("PtrList");
60 if (delimiter == token::BEGIN_LIST)
68 "PtrList<T>::read(Istream&, const INew&) : "
75 T* tPtr = inewt(is).ptr();
80 "PtrList<T>::read(Istream&, const INew&) : "
81 "reading the single entry"
84 for (label i=1; i<s; i++)
86 set(i, tPtr->clone());
91 // Read end of contents
92 is.readEndList("PtrList");
94 else if (firstToken.isPunctuation())
96 if (firstToken.pToken() != token::BEGIN_LIST)
100 "PtrList<T>::read(Istream&, const INew&)",
102 ) << "incorrect first token, '(', found " << firstToken.info()
103 << exit(FatalIOError);
112 lastToken.isPunctuation()
113 && lastToken.pToken() == token::END_LIST
117 is.putBack(lastToken);
118 sllPtrs.append(inewt(is).ptr());
122 setSize(sllPtrs.size());
127 typename SLList<T*>::iterator iter = sllPtrs.begin();
128 iter != sllPtrs.end();
139 "PtrList<T>::read(Istream&, const INew&)",
141 ) << "incorrect first token, expected <int> or '(', found "
143 << exit(FatalIOError);
148 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
152 Foam::PtrList<T>::PtrList(Istream& is, const INew& inewt)
159 Foam::PtrList<T>::PtrList(Istream& is)
165 // * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
168 Foam::Istream& Foam::operator>>(Istream& is, PtrList<T>& L)
171 L.read(is, INew<T>());
177 // * * * * * * * * * * * * * * * Ostream Operators * * * * * * * * * * * * * //
180 Foam::Ostream& Foam::operator<<(Ostream& os, const PtrList<T>& L)
182 // Write size and start delimiter
183 os << nl << L.size() << nl << token::BEGIN_LIST;
191 // Write end delimiter
192 os << nl << token::END_LIST << nl;
194 // Check state of IOstream
195 os.check("Ostream& operator<<(Ostream&, const PtrList&)");
201 // ************************************************************************* //