iIstream.hpp
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 #ifndef __iIstream_hpp__
22 #define __iIstream_hpp__
23 
24 #include "IOstream.hpp"
25 #include "token.hpp"
26 #include "error.hpp"
27 #include "iOstream.hpp"
28 
29 namespace pFlow
30 {
31 
32 
33 class iIstream // interface class for input streams
34 :
35  public IOstream
36 {
37 
38  // Private Data
39 
40  //- Has a token been put back on the stream?
41  bool putBack_;
42 
43  //- The last token put back on the stream
45 
46 public:
47 
49 
50  // - default
52  IOstream(),
53  putBack_(false)
54  {}
55 
56  // - Copy construct
57  iIstream(const iIstream&) = default;
58 
59  // - Destructor
60  virtual ~iIstream() = default;
61 
62 
63 
65 
66  //- Put back token
67  // Only a single put back is permitted
68  void putBack(const token& tok);
69 
70  //- Get the put back token if there is one and return true.
71  // Return false if no put back token is available.
72  bool getBack(token& tok);
73 
74  //- Peek at the put back token without removing it.
75  // Returns false if no put back token is available and set the
76  // token to undefined.
77  bool peekBack(token& tok);
78 
79  //- reset the put back token;
80  void resetPutBack()
81  {
83  putBack_ = false;
84  }
85 
86  //- Return next token from stream
87  virtual iIstream& read(token&) = 0;
88 
89  //- Read a character
90  virtual iIstream& read(char&) = 0;
91 
92  //- Read a string (including enclosing double-quotes)
93  virtual iIstream& read(word&) = 0;
94 
95  //- Read a string
96  virtual iIstream& readString(word&) = 0;
97 
98  //- Read a int64
99  virtual iIstream& read(int64&) = 0;
100 
101  //- Read a int32
102  virtual iIstream& read(int32&) = 0;
103 
104  //- Read a int16
105  virtual iIstream& read(int16&) = 0;
106 
107  //- Read a int8
108  virtual iIstream& read(int8&) = 0;
109 
110  //- Read a label
111  virtual iIstream& read(label&) = 0;
112 
113  //- Read a uin32
114  virtual iIstream& read(uint32&) = 0;
115 
116  //- Read a uin16
117  virtual iIstream& read(uint16&) = 0;
118 
119  //- Read a floatScalar
120  virtual iIstream& read(float&) = 0;
121 
122  //- Read a doubleScalar
123  virtual iIstream& read(double&) = 0;
124 
125 
126  //- Rewind the stream so that it may be read again
127  virtual void rewind() = 0;
128 
129 
131 
132  // - search for all tokesn and find the first word token tbat matchs w
133  virtual bool findToken( const word & w );
134 
135 
136  // - search for all tokesn and find the first word token that matchs
137  virtual bool findTokenSilent( const word & w, int32 limitLine = 100 );
138 
139  // - search for all tokens and find the first word token and also next word token
140  // chekck if it is eneded with end statement ;
141  virtual bool findTokenAndNext( const word& w, word& nextW, bool checkEndStatement = true);
142 
143 
144  virtual bool findTokenAndNextSilent( const word& w, word& nextW, int32 limitLine = 100);
145 
146  // - find a pair of keyword and data terminated by ;
147  // keyword data;
148  // return false if keyword does not exist or reading fails.
149  template<typename T>
150  bool findKeywordAndVal(const word& keyword, T& val, bool checkEndStatement = true);
151 
152  // - lookup for keyword and data;
153  // fatalExit if fails
154  template<typename T>
155  T lookupData(const word& keyword);
156 
157  // - lookup for keyword and data;
158  // set to setVal if lookup fails.
159  template<typename T>
160  T lookupDataOrSet(const word& keyword, const T& setVal);
161 
162  // - read the data next to keword
163  // keyword data;
164  // check the keyword is correct or not
165  template<typename T>
166  bool nextData(const word& keyword, T& data);
167 
169 
170  //- Begin read of data chunk, starts with '('.
171  // return true or FatalIOError
172  bool readBegin(const char* funcName);
173 
174  //- End read of data chunk, ends with ')'
175  // return true or FatalIOError
176  bool readEnd(const char* funcName);
177 
178  //- Begin read of data chunk, starts with '('.
179  // return true or FatalIOError
180  bool readBeginSquare(const char* funcName);
181 
182  //- Begin read of data chunk, starts with '('.
183  // return true or FatalIOError
184  bool readEndSquare(const char* funcName);
185 
186  //- Begin read of list data, starts with '(' or '{'
187  // return starting delimiter or FatalIOError
188  char readBeginList(const char* funcName);
189 
190  //- End read of list data, ends with ')' or '}'
191  // return closing delimiter or FatalIOError
192  char readEndList(const char* funcName);
193 
194  // End statement character ;
195  char readEndStatement(const char* funcName);
196 
197 
198  iIstream& operator()() const;
199 
200 };
201 
202 
203 typedef iIstream& (*iIstreamManip)(iIstream&);
204 
205 //- operator>> handling for manipulators without arguments
207 {
208  return f(is);
209 }
210 
211 //- operator>> handling for manipulators without arguments
213 {
214  f(is);
215  return is;
216 }
217 
218 
219 // read operation for basic types it gets from the
220 // token stream
221 
222 inline iIstream& operator>>( iIstream& is, word & w);
223 
224 inline iIstream& operator>>( iIstream& is, int64& val);
225 
226 inline iIstream& operator>>( iIstream& is, int32& val);
227 
228 inline iIstream& operator>>( iIstream& is, int16& val);
229 
230 inline iIstream& operator>>( iIstream& is, int8& val);
231 
232 inline iIstream& operator>>( iIstream& is, uint32& val);
233 
234 inline iIstream& operator>>( iIstream& is, uint16& val);
235 
236 inline iIstream& operator>>( iIstream& is, label& val);
237 
238 inline iIstream& operator>>( iIstream& is, float& val);
239 
240 inline iIstream& operator>>( iIstream& is, double& val);
241 
242 
243 
244 } // pFlow
245 
246 
247 #include "iIstreamI.hpp"
248 
249 
250 #endif
pFlow::iIstream::readBegin
bool readBegin(const char *funcName)
Definition: iIstream.cpp:203
pFlow::iIstream::findTokenAndNextSilent
virtual bool findTokenAndNextSilent(const word &w, word &nextW, int32 limitLine=100)
Definition: iIstream.cpp:168
pFlow::iIstream::lookupDataOrSet
T lookupDataOrSet(const word &keyword, const T &setVal)
Definition: iIstreamI.hpp:68
pFlow::iIstream::read
virtual iIstream & read(token &)=0
pFlow::token
Definition: token.hpp:42
pFlow::iIstream::readString
virtual iIstream & readString(word &)=0
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
token.hpp
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::iIstream::readEnd
bool readEnd(const char *funcName)
Definition: iIstream.cpp:223
pFlow::iIstream::readEndStatement
char readEndStatement(const char *funcName)
Definition: iIstream.cpp:324
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:55
pFlow::iIstream::findKeywordAndVal
bool findKeywordAndVal(const word &keyword, T &val, bool checkEndStatement=true)
Definition: iIstreamI.hpp:24
pFlow::iIstream::findTokenSilent
virtual bool findTokenSilent(const word &w, int32 limitLine=100)
Definition: iIstream.cpp:93
pFlow
Definition: demComponent.hpp:28
pFlow::IOstreamManip
IOstream &(* IOstreamManip)(IOstream &)
Definition: IOstream.hpp:273
pFlow::token::reset
void reset()
Definition: tokenI.hpp:245
pFlow::iIstream::rewind
virtual void rewind()=0
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::iIstreamManip
iIstream &(* iIstreamManip)(iIstream &)
Definition: iIstream.hpp:203
pFlow::iIstream::getBack
bool getBack(token &tok)
Definition: iIstream.cpp:27
pFlow::iIstream::iIstream
iIstream()
Definition: iIstream.hpp:51
pFlow::iIstream::nextData
bool nextData(const word &keyword, T &data)
Definition: iIstreamI.hpp:81
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::iIstream::readBeginList
char readBeginList(const char *funcName)
Definition: iIstream.cpp:280
pFlow::iIstream::putBack_
bool putBack_
Definition: iIstream.hpp:41
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::iIstream::findTokenAndNext
virtual bool findTokenAndNext(const word &w, word &nextW, bool checkEndStatement=true)
Definition: iIstream.cpp:122
pFlow::iIstream::operator()
iIstream & operator()() const
Definition: iIstream.cpp:342
pFlow::iIstream::resetPutBack
void resetPutBack()
Definition: iIstream.hpp:80
pFlow::iIstream::lookupData
T lookupData(const word &keyword)
Definition: iIstreamI.hpp:52
pFlow::iIstream::readBeginSquare
bool readBeginSquare(const char *funcName)
Definition: iIstream.cpp:242
IOstream.hpp
iIstreamI.hpp
pFlow::iIstream::putBackToken_
token putBackToken_
Definition: iIstream.hpp:44
pFlow::iIstream::readEndList
char readEndList(const char *funcName)
Definition: iIstream.cpp:301
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::int8
signed char int8
Definition: builtinTypes.hpp:49
iOstream.hpp
pFlow::iIstream::findToken
virtual bool findToken(const word &w)
Definition: iIstream.cpp:60
pFlow::IOstream
Definition: IOstream.hpp:45
pFlow::iIstream::~iIstream
virtual ~iIstream()=default
pFlow::iIstream::readEndSquare
bool readEndSquare(const char *funcName)
Definition: iIstream.cpp:261
error.hpp
pFlow::iIstream::peekBack
bool peekBack(token &tok)
Definition: iIstream.cpp:46