# PhasicFlow: src/phasicFlow/dictionary/entry/iEntry.cpp Source File

iEntry.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.
-----------------------------------------------------------------------------*/
// based on OpenFOAM dictionary, with some modifications/simplifications
// to be tailored to our needs
#include "iEntry.hpp"
#include "dictionary.hpp"
#include "dataEntry.hpp"
#include "error.hpp"
#include "iOstream.hpp"
#include "iIstream.hpp"
bool pFlow::iEntry::readKeyword
(
iIstream &is,
word& keyword,
token& tok
)
{
while
(
!is.read(tok).bad() &&
!is.eof() &&
tok.good()
)
{
if(tok == token::END_STATEMENT) continue;
if( tok.isWord())
{
keyword = tok.wordToken();
return true;
}
else
{
return false;
}
}
return false;
}
bool pFlow::iEntry::createEntry
(
dictionary& parDict,
iIstream& is,
bool hasBlockToken
)
{
is.fatalCheck(FUNCTION_NAME);
// reads tokens one-by-one
word key;
token nextTok;
if( auto isKey = iEntry::readKeyword(is, key, nextTok ); isKey )
{
//output<< key << " "<<nextTok <<endl;
is.read(nextTok);
if( is.eof() || is.bad() || !nextTok.good() )
{
ioErrorInFile(is.name(), is.lineNumber())<<
"expecting a valid token after keyword " << key << endl;
fatalExit;
}
// output<< nextTok<<endl;
is.putBack(nextTok);
if( nextTok == token::BEGIN_BLOCK )
{
uniquePtr<iEntry> ptr = makeUnique<dictionary>(key, parDict, is);
if( !parDict.addPtr(key, ptr ))
{
fatalErrorInFunction <<
"unable to add dicrionary " << key <<
" to dictionary " << parDict.globalName() <<endl;
fatalExit;
}
}
else
{
uniquePtr<iEntry> ptr = makeUnique<dataEntry>(key, parDict, is);
if( !parDict.addPtr(key, ptr ) )
{
fatalErrorInFunction <<
"unable to add dataEntry " << key <<
" to dictionary " << parDict.globalName() <<endl;
fatalExit;
}
}
}
else
{
if( nextTok.good() )
{
if(hasBlockToken)
{
if(nextTok != token::END_BLOCK )
{
ioErrorInFile(is.name(), is.lineNumber())<<
"expecting a } but found "<< nextTok <<endl;
fatalExit;
}else
{
return false;
}
}else
{
ioErrorInFile(is.name(), is.lineNumber())<<
"not expecting " << nextTok <<endl;
return false;
}
}
else if( !is.eof())
{
ioErrorInFile(is.name(), is.lineNumber())<<
"error in reading next token. \n";
fatalExit;
}
}
return true;
}
bool pFlow::iEntry::writeKeyword
(
iOstream& os
)const
{
os.writeWordKeyword(keyword_);
os.fatalCheck("pFlow::iEntry::writeKeyword");
return true;
}
pFlow::iOstream& pFlow::operator << (iOstream& os, const iEntry& e)
{
if(!e.write(os))
{
ioErrorInFile(os.name(), os.lineNumber())<<
"Error in wrting to file \n";
fatalExit;
}
return os;
}
pFlow::iIstream& pFlow::operator >> (iIstream& is, iEntry& e)
{
if( !e.read(is))
{
ioErrorInFile(is.name(), is.lineNumber())<<
"Error in reading from file \n";
fatalExit;
}
return is;
}
pFlow::IOstream::eof
bool eof() const
Definition: IOstream.hpp:156
pFlow::iIstream::read
virtual iIstream & read(token &)=0
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::token
Definition: token.hpp:42
iIstream.hpp
pFlow::token::good
bool good() const
Definition: tokenI.hpp:372
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::dictionary::globalName
virtual word globalName() const
Definition: dictionary.cpp:349
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::iEntry::write
virtual bool write(iOstream &os) const =0
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::iEntry::read
virtual bool read(iIstream &is)=0
pFlow::IOstream::bad
bool bad() const
Definition: IOstream.hpp:168
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::iEntry::createEntry
static bool createEntry(dictionary &parDict, iIstream &is, bool hasBlockToken=false)
Definition: iEntry.cpp:64
dictionary.hpp
pFlow::iIstream::putBack
void putBack(const token &tok)
Definition: iIstream.cpp:5
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::IOstream::fatalCheck
bool fatalCheck(const char *operation) const
Definition: IOstream.cpp:48
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::IOstream::name
virtual const word & name() const
Definition: IOstream.cpp:31
iEntry.hpp
pFlow::iEntry::writeKeyword
bool writeKeyword(iOstream &os) const
Definition: iEntry.cpp:154
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
dataEntry.hpp
pFlow::dictionary::addPtr
bool addPtr(const word &keyword, uniquePtr< iEntry > &etry)
Definition: dictionary.cpp:379
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::iEntry::readKeyword
static bool readKeyword(iIstream &is, word &keyword, token &tok)
Definition: iEntry.cpp:32
pFlow::iEntry
Definition: iEntry.hpp:38
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
iOstream.hpp
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::token::wordToken
const word & wordToken() const
Definition: tokenI.hpp:600
pFlow::iOstream::writeWordKeyword
virtual iOstream & writeWordKeyword(const word &kw)
Definition: iOstream.cpp:41
pFlow::dictionary
Definition: dictionary.hpp:38
pFlow::token::isWord
bool isWord() const
Definition: tokenI.hpp:584
error.hpp