www.cemf.ir
Logical.cpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 #include "Logical.hpp"
22 #include "error.hpp"
23 #include "iIstream.hpp"
24 #include "iOstream.hpp"
25 
27 {
28  if (!evaluteWord(l, s_, yesNoSet_))
29  {
30  fatalErrorInFunction << " invalid input for Logical: " << l << endl;
31  fatalExit;
32  }
33 }
34 
35 pFlow::Logical::Logical(const char* ch)
36  : Logical(word(ch))
37 {
38 }
39 
40 bool
41 pFlow::Logical::evaluteWord(const word& l, bool& b, int& yesNoSet)
42 {
43  auto Ul = toUpper(l);
44 
45  for (int i = 0; i < 4; ++i)
46  {
47  if (toUpper(YesNo__[i][0]) == Ul)
48  {
49  b = true;
50  yesNoSet = i;
51  return true;
52  }
53  else if (toUpper(YesNo__[i][1]) == Ul)
54  {
55  b = false;
56  yesNoSet = i;
57  return true;
58  }
59  }
60  yesNoSet = 0;
61  return false;
62 }
63 
64 bool
66 {
67  token t(is);
68  word w;
69  if (!t.good())
70  {
71  ioErrorInFile(is.name(), is.lineNumber())
72  << "Bad token - could not get Logical value";
73  is.setBad();
74  return false;
75  }
76 
77  if (t.isString())
78  {
79  w = t.stringToken();
80  }
81  else if (t.isWord())
82  {
83  w = t.wordToken();
84  }
85  else
86  {
87  ioErrorInFile(is.name(), is.lineNumber())
88  << "Wrong token type - expected Logical value, found " << t;
89  is.setBad();
90  return false;
91  }
92 
93  return evaluteWord(w, s_, yesNoSet_);
94 }
95 
96 bool
98 {
99  if (s_)
100  {
101  os << YesNo__[yesNoSet_][0];
102  }
103  else
104  {
105  os << YesNo__[yesNoSet_][1];
106  }
107  return os.check(FUNCTION_NAME);
108 }
109 
112 {
113  if (!L.read(is))
114  {
115  fatalExit;
116  }
117  return is;
118 }
119 
122 {
123  if (!L.write(os))
124  {
125  fatalExit;
126  }
127  return os;
128 }
pFlow::Logical::evaluteWord
static bool evaluteWord(const word &l, bool &b, int &yesNoSet)
Definition: Logical.cpp:41
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
iIstream.hpp
pFlow::token::stringToken
const word & stringToken() const
Return const reference to the string contents.
Definition: tokenI.hpp:642
pFlow::token::good
bool good() const
True if token is not UNDEFINED or ERROR.
Definition: tokenI.hpp:390
pFlow::toUpper
word toUpper(const word &inStr)
convert a word to all caps
Definition: bTypesFunctions.cpp:43
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.cpp:42
pFlow::Logical::write
bool write(iOstream &os) const
Definition: Logical.cpp:97
Logical.hpp
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::Logical::read
bool read(iIstream &is)
Definition: Logical.cpp:65
pFlow::Logical::s_
bool s_
bool value
Definition: Logical.hpp:44
pFlow::IOstream::setBad
void setBad()
Set stream to be bad.
Definition: IOstream.hpp:274
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
Return the name of the stream.
Definition: IOstream.cpp:31
pFlow::Logical
Holds a bool value and converts strings to bool.
Definition: Logical.hpp:39
pFlow::Logical::Logical
Logical()=default
Default constructor.
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
iOstream.hpp
pFlow::Logical::yesNoSet_
int yesNoSet_
Set numbe of of Yes or No.
Definition: Logical.hpp:47
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::token::wordToken
const word & wordToken() const
Return const reference to the word contents.
Definition: tokenI.hpp:618
pFlow::token::isString
bool isString() const
Token is STRING, VARIABLE or VERBATIM string.
Definition: tokenI.hpp:633
pFlow::token::isWord
bool isWord() const
Token is word or DIRECTIVE word.
Definition: tokenI.hpp:602
error.hpp