1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
11 cfMesh 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 cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
30 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
32 template<class T, Foam::label Offset>
33 void Foam::LongList<T, Offset>::writeEntry(Ostream& os) const
38 token::compound::isCompound
40 "LongList<" + word(pTraits<T>::typeName) + '>'
44 os << word("LongList<" + word(pTraits<T>::typeName) + '>') << " ";
50 template<class T, Foam::label Offset>
51 void Foam::LongList<T, Offset>::writeEntry
57 os.writeKeyword(keyword);
59 os << token::END_STATEMENT << endl;
62 template<class T, Foam::label Offset>
63 Foam::Ostream& Foam::operator<<
66 const Foam::LongList<T, Offset>& DL
69 if( (os.format() == IOstream::ASCII) || !contiguous<T>() )
73 // Write size of list and start contents delimiter
74 os << DL.size() << token::BEGIN_LIST;
76 // Write list contents
79 if( i != 0 ) os << token::SPACE;
83 // Write end of contents delimiter
84 os << token::END_LIST;
88 // Write size of list and start contents delimiter
89 os << nl << DL.size() << nl << token::BEGIN_LIST;
91 // Write list contents
97 // Write end of contents delimiter
98 os << nl << token::END_LIST << nl;
103 os << nl << DL.nextFree_ << nl;
106 const label blockSize = 1<<DL.shift_;
111 while( currPos < DL.nextFree_ )
114 Foam::min(DL.nextFree_ - currPos, blockSize);
118 reinterpret_cast<const char*>(DL.dataPtr_[currBlock]),
128 // Check state of IOstream
129 os.check("Ostream& operator<<(Ostream&, const LongList&)");
135 template<class T, Foam::label Offset>
136 Foam::Istream& Foam::operator>>
139 Foam::LongList<T, Offset>& DL
145 is.fatalCheck("operator>>(Istream&, LongList<T, Offset>&)");
147 token firstToken(is);
151 "operator>>(Istream&, LongList<T, Offset>&) : reading first token"
154 if( firstToken.isLabel() )
156 const label size = firstToken.labelToken();
158 // Set list length to that read
161 // Read list contents depending on data format
162 if( (is.format() == IOstream::ASCII) || !contiguous<T>() )
164 // Read beginning of contents
165 char listDelimiter = is.readBeginList("List");
169 if( listDelimiter != token::BEGIN_LIST )
173 "template<class T, Foam::label Offset>"
175 "Foam::Istream& Foam::operator>>"
178 "Foam::LongList<T, Offset>& DL"
180 ) << "Missing ( after 0" << endl;
185 listDelimiter = is.readEndList("List");
186 if( listDelimiter != token::END_LIST )
190 "template<class T, Foam::label Offset>"
192 "Foam::Istream& Foam::operator>>"
195 "Foam::LongList<T, Offset>& DL"
197 ) << "Missing ) after 0(" << endl;
203 if( listDelimiter == token::BEGIN_LIST )
205 for(register label i=0;i<size;++i)
211 "operator>>(Istream&, List<T>&) : reading entry"
222 "operator>>(Istream&, List<T>&) : "
223 "reading the single entry"
226 for(register label i=0;i<size;++i)
232 // Read end of contents
233 is.readEndList("List");
237 const label blockSize = (1<<DL.shift_);
242 while( currPos < size )
244 const label bs = Foam::min(size - currPos, blockSize);
248 reinterpret_cast<char*>(DL.dataPtr_[currBlock]),
258 "operator>>(Istream&, LongList<T, Offset>&)"
259 ": reading the binary block"
265 FatalIOErrorIn("operator>>(Istream&, LongList<T, Offset>&)", is)
266 << "incorrect first token, expected <int>, found "
268 << exit(FatalIOError);
274 template<class T, Foam::label Offset>
275 void Foam::LongList<T, Offset>::appendFromStream(Istream& is)
277 is.fatalCheck("appendFromStream(Istream& is)");
279 token firstToken(is);
283 "appendFromStream(Istream& is) : reading first token"
286 if( firstToken.isLabel() )
288 const label size = firstToken.labelToken();
292 Pout << "Appending empty stream" << endl;
296 label origSize(this->size());
298 // Set list length to that read
299 setSize(origSize+size);
301 // Read list contents depending on data format
302 if( (is.format() == IOstream::ASCII) || !contiguous<T>() )
304 // Read beginning of contents
305 char listDelimiter = is.readBeginList("List");
307 if( listDelimiter == token::BEGIN_LIST )
309 for(register label i=0;i<size;++i)
311 is >> this->operator[](origSize);
316 "appendFromStream(Istream& is) : reading entry"
327 "appendFromStream(Istream& is) : "
328 "reading the single entry"
331 for(register label i=0;i<size;++i)
333 this->operator[](origSize) = element;
338 // Read end of contents
339 is.readEndList("List");
344 is.read(reinterpret_cast<char*>(buf.begin()), size * sizeof(T));
347 this->operator[](origSize++) = buf[i];
349 /*const label blockSize = 1<<shift_;
351 Info << "nextFree_ " << nextFree_ << endl;
353 //- append elements by reading binary block
354 while( origSize < nextFree_ )
356 const label currBlock = origSize >> shift_;
357 const label currPos = origSize & mask_;
359 Info << "Orig size " << origSize
360 << nl << "currBlock " << currBlock
361 << nl << "currPos " << currPos << endl;
363 T* data = &dataPtr_[currBlock][currPos];
365 label bs = Foam::min(nextFree_-origSize, blockSize);
366 bs = Foam::min(blockSize - currPos, bs);
368 Info << "bs " << bs << endl;
370 is.read(reinterpret_cast<char*>(data), bs * sizeof(T));
376 "appendFromStream(Istream& is)"
377 ": reading the binary block"
383 FatalIOErrorIn("appendFromStream(Istream& is)", is)
384 << "incorrect first token, expected <int>, found "
386 << exit(FatalIOError);
391 // ************************************************************************* //