diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.C b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.C index 4717894b79..7adc45a96a 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.C +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.C @@ -25,35 +25,9 @@ License \*---------------------------------------------------------------------------*/ #include "Istream.H" -#include "bool.H" -#include "token.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -// Set t to the put back token if there is one and return true, -// otherwise return false -bool Foam::Istream::getBack(token& t) -{ - if (bad()) - { - FatalIOErrorIn("void Istream::getBack(token&)", *this) - << "Attempt to get back from bad stream" - << exit(FatalIOError); - - return false; - } - else if (putBack_) - { - t = putBackToken_; - putBack_ = false; - return true; - } - - return false; -} - - -// Keep the put back token void Foam::Istream::putBack(const token& t) { if (bad()) @@ -76,6 +50,40 @@ void Foam::Istream::putBack(const token& t) } +bool Foam::Istream::getBack(token& t) +{ + if (bad()) + { + FatalIOErrorIn("void Istream::getBack(token&)", *this) + << "Attempt to get back from bad stream" + << exit(FatalIOError); + } + else if (putBack_) + { + t = putBackToken_; + putBack_ = false; + return true; + } + + return false; +} + + +bool Foam::Istream::peekBack(token& t) +{ + if (putBack_) + { + t = putBackToken_; + } + else + { + t = token::undefinedToken; + } + + return putBack_; +} + + // Functions for reading object delimiters ( ... ) Foam::Istream& Foam::Istream::readBegin(const char* funcName) diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H index 701c674b14..cf0f631ccb 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H @@ -62,7 +62,7 @@ class Istream { // Private data - //- Has a token been put back on the stream + //- Has a token been put back on the stream? bool putBack_; //- The last token put back on the stream @@ -97,12 +97,19 @@ public: // Read functions //- Put back token + // Only a single put back is permitted void putBack(const token&); - //- Get the put back token + //- Get the put back token if there is one and return true. + // Return false if no put back token is available. bool getBack(token&); - //- Return next token from stream + //- Peek at the put back token without removing it. + // Returns false if no put back token is available and set the + // token to undefined. + bool peekBack(token&); + + //- Return next token from stream virtual Istream& read(token&) = 0; //- Read a character