# PhasicFlow: src/phasicFlow/types/basicTypes/Logical.cpp Source File

Logical.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 "Logical.hpp"
#include "error.hpp"
#include "iIstream.hpp"
#include "iOstream.hpp"
pFlow::Logical::Logical(const word& l)
{
if(!evaluteWord(l, s_, yesNoSet_ ))
{
fatalErrorInFunction<<
" invalid input for Logical: "<< l << endl;
fatalExit;
}
}
pFlow::Logical::Logical(const char* ch)
:
Logical(word(ch))
{}
bool pFlow::Logical::evaluteWord(const word& l, bool& b, int& yesNoSet )
{
auto Ul = toUpper(l);
for(int i=0; i<4; ++i)
{
if(toUpper(YesNo__[i][0]) == Ul)
{
b = true;
yesNoSet = i;
return true;
}
else if( toUpper(YesNo__[i][1]) == Ul )
{
b = false;
yesNoSet = i;
return true;
}
}
yesNoSet = 0;
return false;
}
bool pFlow::Logical::read(iIstream& is)
{
token t(is);
word w;
if (!t.good())
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Bad token - could not get Logical value";
is.setBad();
return false;
}
if (t.isString())
{
w = t.stringToken();
}
else if(t.isWord() )
{
w = t.wordToken();
}
else
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Wrong token type - expected Logical value, found "
<< t;
is.setBad();
return false;
}
return evaluteWord(w, s_, yesNoSet_);
}
bool pFlow::Logical::write
(
iOstream& os
)const
{
if(s_)
{
os<< YesNo__[yesNoSet_][0];
}
else
{
os<< YesNo__[yesNoSet_][1];
}
return os.check(FUNCTION_NAME);
}
pFlow::iIstream& pFlow::operator>>( iIstream& is, Logical& L)
{
if(!L.read(is))
{
fatalExit;
}
return is;
}
pFlow::iOstream& pFlow::operator<< ( iOstream& os, const Logical& L)
{
if(!L.write(os))
{
fatalExit;
}
return os;
}
pFlow::Logical::evaluteWord
static bool evaluteWord(const word &l, bool &b, int &yesNoSet)
Definition: Logical.cpp:42
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::token
Definition: token.hpp:42
iIstream.hpp
pFlow::token::stringToken
const word & stringToken() const
Definition: tokenI.hpp:624
pFlow::token::good
bool good() const
Definition: tokenI.hpp:372
pFlow::Logical::Logical
Logical()
Definition: Logical.hpp:55
pFlow::toUpper
word toUpper(const word &inStr)
Definition: bTypesFunctions.cpp:107
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::IOstream::check
virtual bool check(const char *operation) const
Definition: IOstream.cpp:42
pFlow::Logical::write
bool write(iOstream &os) const
Definition: Logical.cpp:98
Logical.hpp
pFlow::iIstream
Definition: iIstream.hpp:33
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::Logical::read
bool read(iIstream &is)
Definition: Logical.cpp:65
pFlow::Logical::s_
bool s_
Definition: Logical.hpp:38
pFlow::IOstream::setBad
void setBad()
Definition: IOstream.hpp:238
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
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
pFlow::Logical
Definition: Logical.hpp:35
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
iOstream.hpp
pFlow::Logical::yesNoSet_
int yesNoSet_
Definition: Logical.hpp:40
pFlow::iOstream
Definition: iOstream.hpp:53
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
error.hpp