1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
27 #include "UIPstream.H"
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 inline void Foam::UIPstream::checkEof()
37 if (externalBufPosition_ == messageSize_)
45 inline void Foam::UIPstream::readFromBuffer(T& t)
47 const size_t align = sizeof(T);
48 externalBufPosition_ = align + ((externalBufPosition_ - 1) & ~(align - 1));
50 t = reinterpret_cast<T&>(externalBuf_[externalBufPosition_]);
51 externalBufPosition_ += sizeof(T);
56 inline void Foam::UIPstream::readFromBuffer
65 externalBufPosition_ =
67 + ((externalBufPosition_ - 1) & ~(align - 1));
70 register const char* bufPtr = &externalBuf_[externalBufPosition_];
71 register char* dataPtr = reinterpret_cast<char*>(data);
72 register size_t i = count;
73 while (i--) *dataPtr++ = *bufPtr++;
74 externalBufPosition_ += count;
79 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
81 Foam::UIPstream::~UIPstream()
83 if (clearAtEnd_ && eof())
87 Pout<< "UIPstream::~UIPstream() : clearing externalBuf_ of size "
88 << externalBuf_.size() << endl;
90 externalBuf_.clearStorage();
94 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
96 Foam::Istream& Foam::UIPstream::read(token& t)
98 // Return the put back token if it exists
99 if (Istream::getBack(t))
113 // Set the line number of this token to the current stream line number
114 t.lineNumber() = lineNumber();
116 // Analyse input starting with this character.
120 case token::END_STATEMENT :
121 case token::BEGIN_LIST :
122 case token::END_LIST :
123 case token::BEGIN_SQR :
124 case token::END_SQR :
125 case token::BEGIN_BLOCK :
126 case token::END_BLOCK :
131 case token::SUBTRACT :
132 case token::MULTIPLY :
135 t = token::punctuationToken(c);
142 word* pval = new word;
145 if (token::compound::isCompound(*pval))
147 t = token::compound::New(*pval, *this).ptr();
165 case token::VERBATIMSTRING :
167 string* pval = new string;
171 if (c == token::VERBATIMSTRING)
173 t.type() = token::VERBATIMSTRING;
200 case token::FLOAT_SCALAR :
215 case token::DOUBLE_SCALAR :
229 // Character (returned as a single character word) or error
247 Foam::Istream& Foam::UIPstream::read(char& c)
249 c = externalBuf_[externalBufPosition_];
250 externalBufPosition_++;
256 Foam::Istream& Foam::UIPstream::read(word& str)
260 str = &externalBuf_[externalBufPosition_];
261 externalBufPosition_ += len + 1;
267 Foam::Istream& Foam::UIPstream::read(string& str)
271 str = &externalBuf_[externalBufPosition_];
272 externalBufPosition_ += len + 1;
278 Foam::Istream& Foam::UIPstream::read(label& val)
285 Foam::Istream& Foam::UIPstream::read(floatScalar& val)
292 Foam::Istream& Foam::UIPstream::read(doubleScalar& val)
299 Foam::Istream& Foam::UIPstream::read(char* data, std::streamsize count)
301 if (format() != BINARY)
303 FatalErrorIn("UIPstream::read(char*, std::streamsize)")
304 << "stream format not binary"
305 << Foam::abort(FatalError);
308 readFromBuffer(data, count, 8);
313 Foam::Istream& Foam::UIPstream::rewind()
315 externalBufPosition_ = 0;
320 void Foam::UIPstream::print(Ostream& os) const
322 os << "Reading from processor " << fromProcNo_
323 << " to processor " << myProcNo() << Foam::endl;
327 // ************************************************************************* //