# PhasicFlow: src/phasicFlow/streams/iStream/iIstreamI.hpp Source File

iIstreamI.hpp
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.
-----------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * templates * * * * * * * * * * * * * * * * *//
template<typename T>
bool pFlow::iIstream::findKeywordAndVal(const word& keyword, T& val, bool checkEndStatement)
{
if( findToken(keyword) )
{
iIstream& is = *this;
is >> val;
if( checkEndStatement )
{
token next(is);
if( !next.good() || !next.isEndStatement() )
{
return false;
}
}
}
else
{
return false;
}
return true;
}
template<typename T>
T pFlow::iIstream::lookupData
(
const word& keyword
)
{
T val;
if( !findKeywordAndVal(keyword, val) )
{
ioErrorInFile( name(), lineNumber() )<<
" error in finding keyword "<< keyword <<" and value next to it.";
fatalExit;
}
return val;
}
template<typename T>
T pFlow::iIstream::lookupDataOrSet(const word& keyword, const T& setVal)
{
T val;
if(!findKeywordAndVal(keyword, val))
{
val = setVal;
}
return val;
}
template<typename T>
bool pFlow::iIstream::nextData(const word& keyword, T& data)
{
token next;
if( !eof() && good() )
{
read(next);
if(next.error())
{
ioErrorInFile(name(), lineNumber());
return false;
}
if( !next.isWord() )
{
ioErrorInFile(name(), lineNumber())<<
" expected word token.";
return false;
}
if(next.wordToken() != keyword)
{
ioErrorInFile(name(), lineNumber())<<
" expected keyword "<< keyword << " but found "<<next.wordToken()<<endl;
return false;
}
iIstream& is = *this;
is >> data;
read(next);
if( !next.good() || !next.isEndStatement() )
{
ioErrorInFile(name(),lineNumber())<<
" expected ; but found "<< next<<endl;
return false;
}
return true;
}
return false;
}
// * * * * * * * * * * * * * * IO operations * * * * * * * * * * * * * * * * *//
inline pFlow::iIstream& pFlow::operator>>(iIstream& is, word & w)
{
token t(is);
if (!t.good())
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Bad token - could not get word/string value";
fatalExit;
is.setBad();
return is;
}
if (t.isString())
{
w = t.stringToken();
}
else if(t.isWord() )
{
w = t.wordToken();
}
else
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Wrong token type - expected word/string value, found "
<< t;
fatalExit;
is.setBad();
return is;
}
is.check(FUNCTION_NAME);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, int64& val)
{
token t(is);
if (!t.good())
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Bad token - could not get int64 value";
fatalExit;
is.setBad();
return is;
}
if (t.isNumber())
{
val = t.number();
}
else
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Wrong token type - expected int64 value, found "
<< t;
fatalExit;
is.setBad();
return is;
}
is.check(FUNCTION_NAME);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, int32& val)
{
int64 lval(0);
is>>lval;
val = static_cast< int32 >(lval);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, int16& val)
{
int64 lval(0);
is>>lval;
val = static_cast< int16 >(lval);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, int8& val)
{
int64 lval(0);
is>>lval;
val = static_cast< int8 >(lval);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, label& val)
{
int64 lval(0);
is>>lval;
val = static_cast< label >(lval);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, uint32& val)
{
int64 lval(0);
is>>lval;
val = static_cast< uint32 >(lval);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, uint16& val)
{
int64 lval(0);
is>>lval;
val = static_cast< uint16 >(lval);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, float& val)
{
token t(is);
if (!t.good())
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Bad token - could not get float value";
fatalExit;
is.setBad();
return is;
}
if (t.isNumber())
{
val = t.number();
}
else
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Wrong token type - expected float value, found "
<< t;
fatalExit;
is.setBad();
return is;
}
is.check(FUNCTION_NAME);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, double& val)
{
token t(is);
if (!t.good())
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Bad token - could not get double value";
fatalExit;
is.setBad();
return is;
}
if (t.isNumber())
{
val = t.number();
}
else
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Wrong token type - expected double value, found "
<< t;
fatalExit;
is.setBad();
return is;
}
is.check(FUNCTION_NAME);
return is;
}
pFlow::iIstream::lookupDataOrSet
T lookupDataOrSet(const word &keyword, const T &setVal)
Definition: iIstreamI.hpp:68
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::token
Definition: token.hpp:42
pFlow::token::stringToken
const word & stringToken() const
Definition: tokenI.hpp:624
pFlow::token::error
bool error() const
Definition: tokenI.hpp:384
pFlow::token::good
bool good() const
Definition: tokenI.hpp:372
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::token::number
real number() const
Definition: tokenI.hpp:568
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:55
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::iIstream::findKeywordAndVal
bool findKeywordAndVal(const word &keyword, T &val, bool checkEndStatement=true)
Definition: iIstreamI.hpp:24
pFlow::IOstream::check
virtual bool check(const char *operation) const
Definition: IOstream.cpp:42
pFlow::int16
short int int16
Definition: builtinTypes.hpp:51
pFlow::uint16
unsigned short int uint16
Definition: builtinTypes.hpp:57
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::iIstream::nextData
bool nextData(const word &keyword, T &data)
Definition: iIstreamI.hpp:81
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::IOstream::setBad
void setBad()
Definition: IOstream.hpp:238
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::IOstream::name
virtual const word & name() const
Definition: IOstream.cpp:31
pFlow::iIstream::lookupData
T lookupData(const word &keyword)
Definition: iIstreamI.hpp:52
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::int8
signed char int8
Definition: builtinTypes.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::isNumber
bool isNumber() const
Definition: tokenI.hpp:562
pFlow::token::isEndStatement
bool isEndStatement() const
Definition: tokenI.hpp:431
pFlow::token::wordToken
const word & wordToken() const
Definition: tokenI.hpp:600
pFlow::token::isString
bool isString() const
Definition: tokenI.hpp:615
pFlow::token::isWord
bool isWord() const
Definition: tokenI.hpp:584