1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "IOPosition.H"
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 template<class ParticleType>
31 Foam::IOPosition<ParticleType>::IOPosition
33 const Cloud<ParticleType>& c
51 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
53 template<class ParticleType>
54 bool Foam::IOPosition<ParticleType>::write() const
58 return regIOobject::write();
67 template<class ParticleType>
68 bool Foam::IOPosition<ParticleType>::writeData(Ostream& os) const
70 os<< cloud_.size() << nl << token::BEGIN_LIST << nl;
72 forAllConstIter(typename Cloud<ParticleType>, cloud_, iter)
74 // Prevent writing additional fields
75 static_cast<const Particle<ParticleType>&>(iter()).write
83 os<< token::END_LIST << endl;
89 template<class ParticleType>
90 void Foam::IOPosition<ParticleType>::readData
92 Cloud<ParticleType>& c,
96 Istream& is = readStream(checkClass ? typeName : "");
100 if (firstToken.isLabel())
102 label s = firstToken.labelToken();
104 // Read beginning of contents
105 is.readBeginList("Cloud<ParticleType>");
107 for (label i=0; i<s; i++)
109 // Do not read any fields, position only
110 c.append(new ParticleType(c, is, false));
113 // Read end of contents
114 is.readEndList("Cloud<ParticleType>");
116 else if (firstToken.isPunctuation())
118 if (firstToken.pToken() != token::BEGIN_LIST)
122 "void IOPosition<ParticleType>::readData"
123 "(Cloud<ParticleType>&, bool)",
125 ) << "incorrect first token, '(', found "
127 << exit(FatalIOError);
134 lastToken.isPunctuation()
135 && lastToken.pToken() == token::END_LIST
139 is.putBack(lastToken);
140 // Do not read any fields, position only
141 c.append(new ParticleType(c, is, false));
149 "void IOPosition<ParticleType>::readData"
150 "(Cloud<ParticleType>&, bool)",
152 ) << "incorrect first token, expected <int> or '(', found "
154 << exit(FatalIOError);
157 // Check state of IOstream
160 "void IOPosition<ParticleType>::readData(Cloud<ParticleType>&, bool)"
165 // ************************************************************************* //