1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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
27 \*---------------------------------------------------------------------------*/
29 #include "IOPosition.H"
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 template<class ParticleType>
34 Foam::IOPosition<ParticleType>::IOPosition
36 const Cloud<ParticleType>& c
54 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
56 template<class ParticleType>
57 bool Foam::IOPosition<ParticleType>::write() const
61 return regIOobject::write();
70 template<class ParticleType>
71 bool Foam::IOPosition<ParticleType>::writeData(Ostream& os) const
73 os<< cloud_.size() << nl << token::BEGIN_LIST << nl;
75 forAllConstIter(typename Cloud<ParticleType>, cloud_, iter)
77 os<< static_cast<const Particle<ParticleType>&>(iter()) << nl;
80 os<< token::END_LIST << endl;
86 template<class ParticleType>
87 void Foam::IOPosition<ParticleType>::readData
89 Cloud<ParticleType>& c,
93 Istream& is = readStream(checkClass ? typeName : "");
97 if (firstToken.isLabel())
99 label s = firstToken.labelToken();
101 // Read beginning of contents
102 is.readBeginList("Cloud<ParticleType>");
104 for (label i=0; i<s; i++)
106 c.append(new ParticleType(c, is, false));
109 // Read end of contents
110 is.readEndList("Cloud<ParticleType>");
112 else if (firstToken.isPunctuation())
114 if (firstToken.pToken() != token::BEGIN_LIST)
118 "void IOPosition<ParticleType>::readData"
119 "(Cloud<ParticleType>&, bool)",
121 ) << "incorrect first token, '(', found "
123 << exit(FatalIOError);
130 lastToken.isPunctuation()
131 && lastToken.pToken() == token::END_LIST
135 is.putBack(lastToken);
136 c.append(new ParticleType(c, is, false));
144 "void IOPosition<ParticleType>::readData"
145 "(Cloud<ParticleType>&, bool)",
147 ) << "incorrect first token, expected <int> or '(', found "
149 << exit(FatalIOError);
152 // Check state of IOstream
155 "void IOPosition<ParticleType>::readData(Cloud<ParticleType>&, bool)"
160 // ************************************************************************* //