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 \*---------------------------------------------------------------------------*/
34 // * * * * * * * * * * * * * Private member functions * * * * * * * * * * * //
36 inline void Foam::IPstream::checkEof()
38 if (bufPosition_ == messageSize_)
46 inline void Foam::IPstream::readFromBuffer(T& t)
48 const size_t align = sizeof(T);
49 bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
51 t = reinterpret_cast<T&>(buf_[bufPosition_]);
52 bufPosition_ += sizeof(T);
57 inline void Foam::IPstream::readFromBuffer
66 bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
69 register const char* bufPtr = &buf_[bufPosition_];
70 register char* dataPtr = reinterpret_cast<char*>(data);
71 register size_t i = count;
72 while (i--) *dataPtr++ = *bufPtr++;
73 bufPosition_ += count;
78 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
80 Foam::IPstream::~IPstream()
85 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
87 Foam::Istream& Foam::IPstream::read(token& t)
89 // Return the put back token if it exists
90 if (Istream::getBack(t))
104 // Set the line number of this token to the current stream line number
105 t.lineNumber() = lineNumber();
107 // Analyse input starting with this character.
111 case token::END_STATEMENT :
112 case token::BEGIN_LIST :
113 case token::END_LIST :
114 case token::BEGIN_SQR :
115 case token::END_SQR :
116 case token::BEGIN_BLOCK :
117 case token::END_BLOCK :
122 case token::SUBTRACT :
123 case token::MULTIPLY :
126 t = token::punctuationToken(c);
133 word* pval = new word;
136 if (token::compound::isCompound(*pval))
138 t = token::compound::New(*pval, *this).ptr();
157 string* pval = new string;
186 case token::FLOAT_SCALAR :
201 case token::DOUBLE_SCALAR :
215 // Character (returned as a single character word) or error
233 Foam::Istream& Foam::IPstream::read(char& c)
235 c = buf_[bufPosition_];
242 Foam::Istream& Foam::IPstream::read(word& str)
246 str = &buf_[bufPosition_];
247 bufPosition_ += len + 1;
253 Foam::Istream& Foam::IPstream::read(string& str)
257 str = &buf_[bufPosition_];
258 bufPosition_ += len + 1;
264 Foam::Istream& Foam::IPstream::read(label& val)
271 Foam::Istream& Foam::IPstream::read(floatScalar& val)
278 Foam::Istream& Foam::IPstream::read(doubleScalar& val)
285 Foam::Istream& Foam::IPstream::read(char* data, std::streamsize count)
287 if (format() != BINARY)
289 FatalErrorIn("IPstream::read(char*, std::streamsize)")
290 << "stream format not binary"
291 << Foam::abort(FatalError);
294 readFromBuffer(data, count, 8);
299 Foam::Istream& Foam::IPstream::rewind()
306 // ************************************************************************* //