Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
7c8316df
Commit
7c8316df
authored
Dec 12, 2009
by
Mark Olesen
Browse files
Add peekBack() method to Istream.
parent
497ec32e
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/OpenFOAM/db/IOstreams/IOstreams/Istream.C
View file @
7c8316df
...
...
@@ -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_
;
}
...
...
src/OpenFOAM/db/IOstreams/IOstreams/Istream.H
View file @
7c8316df
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment