# PhasicFlow: src/phasicFlow/streams/iStream/iIstream.cpp Source File

iIstream.cpp
Go to the documentation of this file.
#include "iIstream.hpp"
void pFlow::iIstream::putBack(const token& tok)
{
if (bad())
{
ioErrorInFile(name(), lineNumber()) <<
"stream is bad.\n";
fatalExit;
}
else if (putBack_)
{
fatalErrorInFunction <<
"putBack is already full. \n";
fatalExit;
}
else
{
putBackToken_ = tok;
putBack_ = true;
}
}
bool pFlow::iIstream::getBack(token& tok)
{
if (bad())
{
fatalErrorInFunction;
return false;
}
else if (putBack_)
{
tok = putBackToken_;
putBack_ = false;
return true;
}
return false;
}
bool pFlow::iIstream::peekBack(token& tok)
{
if (putBack_)
{
tok = putBackToken_;
}
else
{
tok.reset();
}
return putBack_;
}
bool pFlow::iIstream::findToken( const word & w )
{
rewind();
token next;
bool isFirstToken = true;
while( !eof() && good() )
{
read(next);
if(next.error())
{
fatalErrorInFunction <<
"error in reading stream " << name() <<
" at line number "<< lineNumber()<<endl;
return false;
}
if( next.isWord() && isFirstToken)
{
if(next.wordToken() == w ) return true;
}
if(next.isEndStatement()|| next.isEndBlock())
isFirstToken = true;
else
isFirstToken = false;
}
return false;
}
bool pFlow::iIstream::findTokenSilent( const word & w, int32 limitLine )
{
rewind();
token next;
bool isFirstToken = true;
while( !eof() && good() && lineNumber()<limitLine )
{
read(next);
if(next.error())
{
return false;
}
if( next.isWord() && isFirstToken)
{
if(next.wordToken() == w) return true;
}
if(next.isEndStatement()|| next.isEndBlock())
isFirstToken = true;
else
isFirstToken = false;
}
return false;
}
bool pFlow::iIstream::findTokenAndNext
(
const word& w,
word& nextW,
bool checkEndStatement
)
{
if( findToken(w) )
{
// next token
token next(*this);
if(next.error())
{
ioErrorInFile( name(), lineNumber());
return false;
}
if( next.isWord() )
{
nextW = next.wordToken();
if( checkEndStatement )
{
read(next);
if( !next.isEndStatement() )
{
ioErrorInFile(name(), lineNumber()) <<
" expected ; but found " << next;
return false;
}
}
return true;
}else
{
ioErrorInFile( name(), lineNumber() ) <<
" token is not a word" << next <<endl;
return false;
}
}
return false;
}
bool pFlow::iIstream::findTokenAndNextSilent(const word& w, word& nextW, int32 limitLine)
{
if( findTokenSilent(w, limitLine) )
{
// next token
token next(*this);
if(next.error())
{
return false;
}
if( next.isWord() )
{
nextW = next.wordToken();
read(next);
if( !next.isEndStatement() )
{
return false;
}
return true;
}else
{
return false;
}
}
return false;
}
bool pFlow::iIstream::readBegin(const char* funcName)
{
const token delimiter(*this);
if (delimiter != token::BEGIN_LIST)
{
setBad();
ioErrorInFile( name(), lineNumber() )
<< "Expected a '" << token::BEGIN_LIST
<< "' while reading " << funcName
<< ", found " << delimiter << endl;
fatalExit;
}
return true;
}
bool pFlow::iIstream::readEnd(const char* funcName)
{
const token delimiter(*this);
if (delimiter != token::END_LIST)
{
setBad();
ioErrorInFile( name(), lineNumber())
<< "Expected a '" << token::END_LIST
<< "' while reading " << funcName
<< ", found "
<< delimiter <<endl;
fatalExit;
}
return true;
}
bool pFlow::iIstream::readBeginSquare(const char* funcName)
{
const token delimiter(*this);
if (delimiter != token::BEGIN_SQR)
{
setBad();
ioErrorInFile( name(), lineNumber())
<< "Expected a '" << token::BEGIN_SQR
<< "' while reading " << funcName
<< ", found "
<< delimiter <<endl;
fatalExit;
}
return true;
}
bool pFlow::iIstream::readEndSquare(const char* funcName)
{
const token delimiter(*this);
if (delimiter != token::END_SQR)
{
setBad();
ioErrorInFile( name(), lineNumber())
<< "Expected a '" << token::END_SQR
<< "' while reading " << funcName
<< ", found "
<< delimiter <<endl;
fatalExit;
}
return true;
}
char pFlow::iIstream::readBeginList(const char* funcName)
{
const token delimiter(*this);
if (delimiter != token::BEGIN_LIST && delimiter != token::BEGIN_BLOCK)
{
setBad();
ioErrorInFile( name(), lineNumber() )
<< "Expected a '" << token::BEGIN_LIST
<< "' or a '" << token::BEGIN_BLOCK
<< "' while reading " << funcName
<< ", found " << delimiter<<endl;
fatalExit;
return '\0';
}
return delimiter.pToken();
}
char pFlow::iIstream::readEndList(const char* funcName)
{
const token delimiter(*this);
if (delimiter != token::END_LIST && delimiter != token::END_BLOCK)
{
setBad();
ioErrorInFile( name(), lineNumber() )
<< "Expected a '" << token::END_LIST
<< "' or a '" << token::END_BLOCK
<< "' while reading " << funcName
<< ", found " << delimiter
<< " at stream position " << endl;
fatalExit;
return '\0';
}
return delimiter.pToken();
}
char pFlow::iIstream::readEndStatement(const char* funcName)
{
CONSUME_PARAM(funcName);
const token delimiter(*this);
if (!delimiter.isEndStatement())
{
setBad();
ioErrorInFile( name(), lineNumber() ) <<
" expected ; but found " << delimiter << endl;
fatalExit;
return '\0';
}
return delimiter.pToken();
}
pFlow::iIstream& pFlow::iIstream::operator()() const
{
if (!good())
{
check("iIstream::operator()");
fatalExit;
}
return const_cast< iIstream&>(*this);
}
pFlow::iIstream::readBegin
bool readBegin(const char *funcName)
Definition: iIstream.cpp:203
pFlow::iIstream::findTokenAndNextSilent
virtual bool findTokenAndNextSilent(const word &w, word &nextW, int32 limitLine=100)
Definition: iIstream.cpp:168
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::token
Definition: token.hpp:42
pFlow::token::pToken
punctuationToken pToken() const
Definition: tokenI.hpp:452
iIstream.hpp
pFlow::token::isEndBlock
bool isEndBlock() const
Definition: tokenI.hpp:442
pFlow::token::END_BLOCK
@ END_BLOCK
End block [isseparator].
Definition: token.hpp:94
pFlow::token::error
bool error() const
Definition: tokenI.hpp:384
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::iIstream::readEnd
bool readEnd(const char *funcName)
Definition: iIstream.cpp:223
pFlow::iIstream::readEndStatement
char readEndStatement(const char *funcName)
Definition: iIstream.cpp:324
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::token::BEGIN_BLOCK
@ BEGIN_BLOCK
Begin block [isseparator].
Definition: token.hpp:93
pFlow::iIstream::findTokenSilent
virtual bool findTokenSilent(const word &w, int32 limitLine=100)
Definition: iIstream.cpp:93
pFlow::token::reset
void reset()
Definition: tokenI.hpp:245
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::IOstream::bad
bool bad() const
Definition: IOstream.hpp:168
pFlow::iIstream::getBack
bool getBack(token &tok)
Definition: iIstream.cpp:27
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::iIstream::readBeginList
char readBeginList(const char *funcName)
Definition: iIstream.cpp:280
pFlow::iIstream::putBack_
bool putBack_
Definition: iIstream.hpp:41
pFlow::iIstream::putBack
void putBack(const token &tok)
Definition: iIstream.cpp:5
pFlow::iIstream::findTokenAndNext
virtual bool findTokenAndNext(const word &w, word &nextW, bool checkEndStatement=true)
Definition: iIstream.cpp:122
pFlow::token::END_LIST
@ END_LIST
End list [isseparator].
Definition: token.hpp:90
pFlow::iIstream::operator()
iIstream & operator()() const
Definition: iIstream.cpp:342
pFlow::IOstream::name
virtual const word & name() const
Definition: IOstream.cpp:31
pFlow::iIstream::readBeginSquare
bool readBeginSquare(const char *funcName)
Definition: iIstream.cpp:242
pFlow::token::BEGIN_LIST
@ BEGIN_LIST
Begin list [isseparator].
Definition: token.hpp:89
pFlow::token::BEGIN_SQR
@ BEGIN_SQR
Begin dimensions [isseparator].
Definition: token.hpp:91
pFlow::iIstream::putBackToken_
token putBackToken_
Definition: iIstream.hpp:44
pFlow::iIstream::readEndList
char readEndList(const char *funcName)
Definition: iIstream.cpp:301
CONSUME_PARAM
#define CONSUME_PARAM(x)
Definition: pFlowMacros.hpp:38
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
pFlow::iIstream::findToken
virtual bool findToken(const word &w)
Definition: iIstream.cpp:60
pFlow::token::isEndStatement
bool isEndStatement() const
Definition: tokenI.hpp:431
pFlow::token::END_SQR
@ END_SQR
End dimensions [isseparator].
Definition: token.hpp:92
pFlow::token::wordToken
const word & wordToken() const
Definition: tokenI.hpp:600
pFlow::token::isWord
bool isWord() const
Definition: tokenI.hpp:584
pFlow::iIstream::readEndSquare
bool readEndSquare(const char *funcName)
Definition: iIstream.cpp:261
pFlow::iIstream::peekBack
bool peekBack(token &tok)
Definition: iIstream.cpp:46