mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Add peekBack() method to Istream.
This commit is contained in:
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user