# PhasicFlow: src/phasicFlow/streams/iStream/iIstream.cpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

iIstream.cpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#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_;
}
size_t pFlow::iIstream::findBinaryBlockStart()
{
notImplementedFunction;
return 0;
}
bool pFlow::iIstream::findToken( const word & w )
{
rewind();
return findTokenResume(w);
}
bool pFlow::iIstream::findTokenResume(const word& w)
{
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();
return findTokenResumeSilent(w,limitLine);
}
bool pFlow::iIstream::findTokenResumeSilent( const word & w, int32 limitLine )
{
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)
Begin read of data chunk, starts with '('.
Definition: iIstream.cpp:238
notImplementedFunction
#define notImplementedFunction
Report that a function is yet not implemented.
Definition: error.hpp:84
pFlow::iIstream::findTokenAndNextSilent
virtual bool findTokenAndNextSilent(const word &w, word &nextW, int32 limitLine=100)
Definition: iIstream.cpp:203
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::token
Token class based on OpenFOAM stream, with some modifications/simplifications to be tailored to our n...
Definition: token.hpp:44
pFlow::token::pToken
punctuationToken pToken() const
Return punctuation character.
Definition: tokenI.hpp:470
iIstream.hpp
pFlow::token::isEndBlock
bool isEndBlock() const
Token is end endBlock.
Definition: tokenI.hpp:460
pFlow::token::END_BLOCK
@ END_BLOCK
Begin block [isseparator].
Definition: token.hpp:96
pFlow::token::error
bool error() const
Token is ERROR.
Definition: tokenI.hpp:402
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::iIstream::readEnd
bool readEnd(const char *funcName)
End read of data chunk, ends with ')' return true or FatalIOError.
Definition: iIstream.cpp:258
pFlow::iIstream::readEndStatement
char readEndStatement(const char *funcName)
End statement character ;.
Definition: iIstream.cpp:359
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::token::BEGIN_BLOCK
@ BEGIN_BLOCK
End dimensions [isseparator].
Definition: token.hpp:95
pFlow::iIstream::findTokenSilent
virtual bool findTokenSilent(const word &w, int32 limitLine=100)
search for all tokesn and find the first word token that matchs
Definition: iIstream.cpp:123
pFlow::iIstream::findTokenResume
virtual bool findTokenResume(const word &w)
search for all tokesn after the current file position and find the first word token tbat matchs w
Definition: iIstream.cpp:90
pFlow::token::reset
void reset()
Reset token to UNDEFINED and clear any allocated storage.
Definition: tokenI.hpp:263
pFlow::iIstream::findTokenResumeSilent
virtual bool findTokenResumeSilent(const word &w, int32 limitLine=100)
search for all tokesn after the current file position and find the first word token tbat matchs w
Definition: iIstream.cpp:129
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::IOstream::bad
bool bad() const
Return true if stream is corrupted.
Definition: IOstream.hpp:204
pFlow::iIstream::getBack
bool getBack(token &tok)
Get the put back token if there is one and return true.
Definition: iIstream.cpp:45
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::iIstream::readBeginList
char readBeginList(const char *funcName)
Begin read of list data, starts with '(' or '{' return starting delimiter or FatalIOError.
Definition: iIstream.cpp:315
pFlow::iIstream::putBack_
bool putBack_
Has a token been put back on the stream?
Definition: iIstream.hpp:45
pFlow::iIstream::putBack
void putBack(const token &tok)
Put back token Only a single put back is permitted.
Definition: iIstream.cpp:23
pFlow::iIstream::findTokenAndNext
virtual bool findTokenAndNext(const word &w, word &nextW, bool checkEndStatement=true)
search for all tokens and find the first word token and also next word token chekck if it is eneded w...
Definition: iIstream.cpp:157
pFlow::token::END_LIST
@ END_LIST
Begin list [isseparator].
Definition: token.hpp:92
pFlow::iIstream::operator()
iIstream & operator()() const
Definition: iIstream.cpp:377
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
pFlow::iIstream::readBeginSquare
bool readBeginSquare(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: iIstream.cpp:277
pFlow::token::BEGIN_LIST
@ BEGIN_LIST
End entry [isseparator].
Definition: token.hpp:91
pFlow::token::BEGIN_SQR
@ BEGIN_SQR
End list [isseparator].
Definition: token.hpp:93
pFlow::iIstream::putBackToken_
token putBackToken_
The last token put back on the stream.
Definition: iIstream.hpp:48
pFlow::iIstream::readEndList
char readEndList(const char *funcName)
End read of list data, ends with ')' or '}' return closing delimiter or FatalIOError.
Definition: iIstream.cpp:336
CONSUME_PARAM
#define CONSUME_PARAM(x)
Definition: pFlowMacros.hpp:38
pFlow::iIstream::findBinaryBlockStart
virtual size_t findBinaryBlockStart()
It seek for a character sequence that indicates the start of a binary block char sequence is 255 255 ...
Definition: iIstream.cpp:78
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Report an error in file operation with supplied fileName and lineNumber.
Definition: error.hpp:87
pFlow::IOstream::lineNumber
int32 lineNumber() const
Const access to the current stream line number.
Definition: IOstream.hpp:223
pFlow::iIstream::findToken
virtual bool findToken(const word &w)
search for all tokesn and find the first word token tbat matchs w
Definition: iIstream.cpp:84
pFlow::token::isEndStatement
bool isEndStatement() const
Token is end statement.
Definition: tokenI.hpp:449
pFlow::token::END_SQR
@ END_SQR
Begin dimensions [isseparator].
Definition: token.hpp:94
pFlow::token::wordToken
const word & wordToken() const
Return const reference to the word contents.
Definition: tokenI.hpp:618
pFlow::token::isWord
bool isWord() const
Token is word or DIRECTIVE word.
Definition: tokenI.hpp:602
pFlow::iIstream::readEndSquare
bool readEndSquare(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: iIstream.cpp:296
pFlow::iIstream::peekBack
bool peekBack(token &tok)
Peek at the put back token without removing it.
Definition: iIstream.cpp:64