Commit 7c8316df authored by Mark Olesen's avatar Mark Olesen
Browse files

Add peekBack() method to Istream.

parent 497ec32e
......@@ -25,13 +25,31 @@ 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
void Foam::Istream::putBack(const token& t)
{
if (bad())
{
FatalIOErrorIn("void Istream::putBack(const token&)", *this)
<< "Attempt to put back onto bad stream"
<< exit(FatalIOError);
}
else if (putBack_)
{
FatalIOErrorIn("void Istream::putBack(const token&)", *this)
<< "Attempt to put back another token"
<< exit(FatalIOError);
}
else
{
putBackToken_ = t;
putBack_ = true;
}
}
bool Foam::Istream::getBack(token& t)
{
if (bad())
......@@ -39,8 +57,6 @@ bool Foam::Istream::getBack(token& t)
FatalIOErrorIn("void Istream::getBack(token&)", *this)
<< "Attempt to get back from bad stream"
<< exit(FatalIOError);
return false;
}
else if (putBack_)
{
......@@ -53,26 +69,18 @@ bool Foam::Istream::getBack(token& t)
}
// Keep the put back token
void Foam::Istream::putBack(const token& t)
bool Foam::Istream::peekBack(token& t)
{
if (bad())
if (putBack_)
{
FatalIOErrorIn("void Istream::putBack(const token&)", *this)
<< "Attempt to put back onto bad stream"
<< exit(FatalIOError);
}
else if (putBack_)
{
FatalIOErrorIn("void Istream::putBack(const token&)", *this)
<< "Attempt to put back another token"
<< exit(FatalIOError);
t = putBackToken_;
}
else
{
putBackToken_ = t;
putBack_ = true;
t = token::undefinedToken;
}
return putBack_;
}
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment