1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 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 \*---------------------------------------------------------------------------*/
32 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
34 template<class LListBase, class T>
36 void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew)
40 "LPtrList<LListBase, T>::read(Istream&, const INew&)"
47 "LPtrList<LListBase, T>::read(Istream&, const INew&) : "
51 if (firstToken.isLabel())
53 label s = firstToken.labelToken();
55 // Read beginning of contents
56 char delimiter = is.readBeginList("LPtrList<LListBase, T>");
60 if (delimiter == token::BEGIN_LIST)
62 for (label i=0; i<s; i++)
64 append(iNew(is).ptr());
68 "LPtrList<LListBase, T>::read(Istream&, const INew&) : "
75 T* tPtr = iNew(is).ptr();
80 "LPtrList<LListBase, T>::read(Istream&, const INew&) : "
84 for (label i=1; i<s; i++)
86 append(tPtr->clone().ptr());
91 // Read end of contents
92 is.readEndList("LPtrList<LListBase, T>");
94 else if (firstToken.isPunctuation())
96 if (firstToken.pToken() != token::BEGIN_LIST)
100 "LPtrList<LListBase, T>::read(Istream&, const INew&)",
102 ) << "incorrect first token, '(', found " << firstToken.info()
103 << exit(FatalIOError);
107 is.fatalCheck("LPtrList<LListBase, T>::read(Istream&, const INew&)");
112 lastToken.isPunctuation()
113 && lastToken.pToken() == token::END_LIST
117 is.putBack(lastToken);
118 append(iNew(is).ptr());
123 "LPtrList<LListBase, T>::read(Istream&, const INew&)"
131 "LPtrList<LListBase, T>::read(Istream&, const INew&)",
133 ) << "incorrect first token, expected <int> or '(', found "
135 << exit(FatalIOError);
138 is.fatalCheck("LPtrList<LListBase, T>::read(Istream&, const INew&)");
142 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
144 template<class LListBase, class T>
146 Foam::LPtrList<LListBase, T>::LPtrList(Istream& is, const INew& iNew)
152 template<class LListBase, class T>
153 Foam::LPtrList<LListBase, T>::LPtrList(Istream& is)
159 // * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
161 template<class LListBase, class T>
162 Foam::Istream& Foam::operator>>(Istream& is, LPtrList<LListBase, T>& L)
165 L.read(is, INew<T>());
171 // * * * * * * * * * * * * * * * Ostream Operators * * * * * * * * * * * * * //
173 template<class LListBase, class T>
174 Foam::Ostream& Foam::operator<<(Ostream& os, const LPtrList<LListBase, T>& lst)
177 os << nl << lst.size();
179 // Write beginning of contents
180 os << nl << token::BEGIN_LIST << nl;
185 typename LPtrList<LListBase, T>::const_iterator iter = lst.begin();
193 // Write end of contents
194 os << token::END_LIST;
196 // Check state of IOstream
197 os.check("Ostream& operator<<(Ostream&, const LPtrList<LListBase, T>&)");
202 // ************************************************************************* //