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 
57  IOstream(wf),
58  putBack_(false)
59  {}
60 
61  // - Copy construct
62  iIstream(const iIstream&) = default;
63 
64  // - Destructor
65  virtual ~iIstream() = default;
66 
67 
68 
70 
71  //- Put back token
72  // Only a single put back is permitted
73  void putBack(const token& tok);
74 
75  //- Get the put back token if there is one and return true.
76  // Return false if no put back token is available.
77  bool getBack(token& tok);
78 
79  //- Peek at the put back token without removing it.
80  // Returns false if no put back token is available and set the
81  // token to undefined.
82  bool peekBack(token& tok);
83 
84  //- reset the put back token;
85  void resetPutBack()
86  {
88  putBack_ = false;
89  }
90 
91  //- Return next token from stream
92  virtual iIstream& read(token&) = 0;
93 
94  //- Read a character
95  virtual iIstream& read(char&) = 0;
96 
97  //- Read a string (including enclosing double-quotes)
98  virtual iIstream& read(word&) = 0;
99 
100  //- Read a string
101  virtual iIstream& readString(word&) = 0;
102 
103  //- Read a int64
104  virtual iIstream& read(int64&) = 0;
105 
106  //- Read a int32
107  virtual iIstream& read(int32&) = 0;
108 
109  //- Read a int16
110  virtual iIstream& read(int16&) = 0;
111 
112  //- Read a int8
113  virtual iIstream& read(int8&) = 0;
114 
115  //- Read a label
116  virtual iIstream& read(label&) = 0;
117 
118  //- Read a uin32
119  virtual iIstream& read(uint32&) = 0;
120 
121  //- Read a uin16
122  virtual iIstream& read(uint16&) = 0;
123 
124  //- Read a floatScalar
125  virtual iIstream& read(float&) = 0;
126 
127  //- Read a doubleScalar
128  virtual iIstream& read(double&) = 0;
129 
130  virtual iIstream& read(char* buffer, std::streamsize count) =0;
131 
132 
133  //- Rewind the stream so that it may be read again
134  virtual void rewind() = 0;
135 
136 
138 
139  // - search for all tokesn and find the first word token tbat matchs w
140  virtual bool findToken( const word & w );
141 
144  virtual bool findTokenResume(const word& w);
145 
146 
147  // - search for all tokesn and find the first word token that matchs
148  virtual bool findTokenSilent( const word & w, int32 limitLine = 100 );
149 
152  virtual bool findTokenResumeSilent( const word & w, int32 limitLine = 100 );
153 
154  // - search for all tokens and find the first word token and also next word token
155  // chekck if it is eneded with end statement ;
156  virtual bool findTokenAndNext( const word& w, word& nextW, bool checkEndStatement = true);
157 
158 
159  virtual bool findTokenAndNextSilent( const word& w, word& nextW, int32 limitLine = 100);
160 
161  // - find a pair of keyword and data terminated by ;
162  // keyword data;
163  // return false if keyword does not exist or reading fails.
164  template<typename T>
165  bool findKeywordAndVal(const word& keyword, T& val, bool checkEndStatement = true);
166 
167  // - lookup for keyword and data;
168  // fatalExit if fails
169  template<typename T>
170  T lookupData(const word& keyword);
171 
172  // - lookup for keyword and data;
173  // set to setVal if lookup fails.
174  template<typename T>
175  T lookupDataOrSet(const word& keyword, const T& setVal);
176 
177  // - read the data next to keword
178  // keyword data;
179  // check the keyword is correct or not
180  template<typename T>
181  bool nextData(const word& keyword, T& data);
182 
184 
185  //- Begin read of data chunk, starts with '('.
186  // return true or FatalIOError
187  bool readBegin(const char* funcName);
188 
189  //- End read of data chunk, ends with ')'
190  // return true or FatalIOError
191  bool readEnd(const char* funcName);
192 
193  //- Begin read of data chunk, starts with '('.
194  // return true or FatalIOError
195  bool readBeginSquare(const char* funcName);
196 
197  //- Begin read of data chunk, starts with '('.
198  // return true or FatalIOError
199  bool readEndSquare(const char* funcName);
200 
201  //- Begin read of list data, starts with '(' or '{'
202  // return starting delimiter or FatalIOError
203  char readBeginList(const char* funcName);
204 
205  //- End read of list data, ends with ')' or '}'
206  // return closing delimiter or FatalIOError
207  char readEndList(const char* funcName);
208 
209  // End statement character ;
210  char readEndStatement(const char* funcName);
211 
212 
213  iIstream& operator()() const;
214 
215 };
216 
217 
218 typedef iIstream& (*iIstreamManip)(iIstream&);
219 
220 //- operator>> handling for manipulators without arguments
222 {
223  return f(is);
224 }
225 
226 //- operator>> handling for manipulators without arguments
228 {
229  f(is);
230  return is;
231 }
232 
233 
234 // read operation for basic types it gets from the
235 // token stream
236 
237 inline iIstream& operator>>( iIstream& is, word & w);
238 
239 inline iIstream& operator>>( iIstream& is, int64& val);
240 
241 inline iIstream& operator>>( iIstream& is, int32& val);
242 
243 inline iIstream& operator>>( iIstream& is, int16& val);
244 
245 inline iIstream& operator>>( iIstream& is, int8& val);
246 
247 inline iIstream& operator>>( iIstream& is, uint32& val);
248 
249 inline iIstream& operator>>( iIstream& is, uint16& val);
250 
251 inline iIstream& operator>>( iIstream& is, label& val);
252 
253 inline iIstream& operator>>( iIstream& is, float& val);
254 
255 inline iIstream& operator>>( iIstream& is, double& val);
256 
257 
258 
259 } // pFlow
260 
261 
262 #include "iIstreamI.hpp"
263 
264 
265 #endif
pFlow::iIstream::readBegin
bool readBegin(const char *funcName)
Definition: iIstream.cpp:211
pFlow::iIstream::findTokenAndNextSilent
virtual bool findTokenAndNextSilent(const word &w, word &nextW, int32 limitLine=100)
Definition: iIstream.cpp:176
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:231
pFlow::iIstream::readEndStatement
char readEndStatement(const char *funcName)
Definition: iIstream.cpp:332
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:55
pFlow::iIstream::iIstream
iIstream(writeFormat wf)
Definition: iIstream.hpp:56
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:96
pFlow
Definition: demComponent.hpp:28
pFlow::IOstreamManip
IOstream &(* IOstreamManip)(IOstream &)
An IOstream manipulator.
Definition: IOstream.hpp:307
pFlow::iIstream::findTokenResume
virtual bool findTokenResume(const word &w)
search for all tokesn after the current file position and find the first word token tbat matchs w
Definition: iIstream.cpp:66
pFlow::token::reset
void reset()
Definition: tokenI.hpp:245
pFlow::iIstream::rewind
virtual void rewind()=0
pFlow::iIstream::findTokenResumeSilent
virtual bool findTokenResumeSilent(const word &w, int32 limitLine=100)
search for all tokesn after the current file position and find the first word token tbat matchs w
Definition: iIstream.cpp:102
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:218
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:288
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:130
pFlow::count
auto count(const Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:26
pFlow::iIstream::operator()
iIstream & operator()() const
Definition: iIstream.cpp:350
pFlow::iIstream::resetPutBack
void resetPutBack()
Definition: iIstream.hpp:85
pFlow::iIstream::lookupData
T lookupData(const word &keyword)
Definition: iIstreamI.hpp:52
pFlow::iIstream::readBeginSquare
bool readBeginSquare(const char *funcName)
Definition: iIstream.cpp:250
IOstream.hpp
iIstreamI.hpp
pFlow::iIstream::putBackToken_
token putBackToken_
Definition: iIstream.hpp:44
pFlow::iIstream::readEndList
char readEndList(const char *funcName)
Definition: iIstream.cpp:309
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::int8
signed char int8
Definition: builtinTypes.hpp:49
iOstream.hpp
pFlow::IOstream::writeFormat
writeFormat
Definition: IOstream.hpp:57
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:269
error.hpp
pFlow::iIstream::peekBack
bool peekBack(token &tok)
Definition: iIstream.cpp:46