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 
26 
28 {
29  if(!evaluteWord(l, s_, yesNoSet_ ))
30  {
32  " invalid input for Logical: "<< l << endl;
33  fatalExit;
34  }
35 }
36 
37 pFlow::Logical::Logical(const char* ch)
38 :
39  Logical(word(ch))
40 {}
41 
42 bool pFlow::Logical::evaluteWord(const word& l, bool& b, int& yesNoSet )
43 {
44  auto Ul = toUpper(l);
45 
46  for(int i=0; i<4; ++i)
47  {
48  if(toUpper(YesNo__[i][0]) == Ul)
49  {
50  b = true;
51  yesNoSet = i;
52  return true;
53  }
54  else if( toUpper(YesNo__[i][1]) == Ul )
55  {
56  b = false;
57  yesNoSet = i;
58  return true;
59  }
60  }
61  yesNoSet = 0;
62  return false;
63 }
64 
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 "
89  << t;
90  is.setBad();
91  return false;
92  }
93 
94  return evaluteWord(w, s_, yesNoSet_);
95 }
96 
98 (
99  iOstream& os
100 )const
101 {
102  if(s_)
103  {
104  os<< YesNo__[yesNoSet_][0];
105  }
106  else
107  {
108  os<< YesNo__[yesNoSet_][1];
109  }
110  return os.check(FUNCTION_NAME);
111 }
112 
114 {
115  if(!L.read(is))
116  {
117  fatalExit;
118  }
119  return is;
120 }
121 
123 {
124  if(!L.write(os))
125  {
126  fatalExit;
127  }
128  return os;
129 }
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