www.cemf.ir
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 #ifndef __iIstream_hpp__
21 #define __iIstream_hpp__
22 
23 #include "IOstream.hpp"
24 #include "token.hpp"
25 #include "error.hpp"
26 #include "iOstream.hpp"
27 
28 namespace pFlow
29 {
30 
37 class iIstream
38 :
39  public IOstream
40 {
41 
42  //- Private Data
43 
45  bool putBack_;
46 
49 
50 public:
51 
53 
56  IOstream(),
57  putBack_(false)
58  {}
59 
61  IOstream(wf),
62  putBack_(false)
63  {}
64 
66  iIstream(const iIstream&) = default;
67 
69  virtual ~iIstream() = default;
70 
71 
72 
74 
77  void putBack(const token& tok);
78 
81  bool getBack(token& tok);
82 
86  bool peekBack(token& tok);
87 
89  void resetPutBack()
90  {
92  putBack_ = false;
93  }
94 
96  virtual iIstream& read(token&) = 0;
97 
99  virtual iIstream& read(char&) = 0;
100 
102  virtual iIstream& read(word&) = 0;
103 
105  virtual iIstream& readString(word&) = 0;
106 
108  virtual iIstream& read(int64&) = 0;
109 
111  virtual iIstream& read(int32&) = 0;
112 
114  virtual iIstream& read(int8&) = 0;
115 
117  virtual iIstream& read(uint64&) = 0;
118 
120  virtual iIstream& read(uint32&) = 0;
121 
123  virtual iIstream& read(uint8&) = 0;
124 
126  virtual iIstream& read(float&) = 0;
127 
129  virtual iIstream& read(double&) = 0;
130 
132  virtual iIstream& read(char* buffer, std::streamsize count) =0;
133 
135  virtual void rewind() = 0;
136 
137  virtual void seek(size_t pos) = 0;
138 
140  virtual size_t tell() = 0;
141 
143 
147  virtual size_t findBinaryBlockStart();
148 
150  virtual bool findToken( const word & w );
151 
154  virtual bool findTokenResume(const word& w);
155 
156 
158  virtual bool findTokenSilent( const word & w, int32 limitLine = 100 );
159 
162  virtual bool findTokenResumeSilent( const word & w, int32 limitLine = 100 );
163 
166  virtual bool findTokenAndNext( const word& w, word& nextW, bool checkEndStatement = true);
167 
168 
169  virtual bool findTokenAndNextSilent( const word& w, word& nextW, int32 limitLine = 100);
170 
174  template<typename T>
175  bool findKeywordAndVal(const word& keyword, T& val, bool checkEndStatement = true);
176 
179  template<typename T>
180  T lookupData(const word& keyword);
181 
184  template<typename T>
185  T lookupDataOrSet(const word& keyword, const T& setVal);
186 
190  template<typename T>
191  bool nextData(const word& keyword, T& data);
192 
194 
197  bool readBegin(const char* funcName);
198 
201  bool readEnd(const char* funcName);
202 
205  bool readBeginSquare(const char* funcName);
206 
209  bool readEndSquare(const char* funcName);
210 
213  char readBeginList(const char* funcName);
214 
217  char readEndList(const char* funcName);
218 
220  char readEndStatement(const char* funcName);
221 
222 
223  iIstream& operator()() const;
224 
225 };
226 
227 
228 typedef iIstream& (*iIstreamManip)(iIstream&);
229 
232 {
233  return f(is);
234 }
235 
238 {
239  f(is);
240  return is;
241 }
242 
243 
244 // read operation for basic types it gets from the token stream
245 inline iIstream& operator>>( iIstream& is, word & w);
246 
247 inline iIstream& operator>>( iIstream& is, int64& val);
248 
249 inline iIstream& operator>>( iIstream& is, int32& val);
250 
251 inline iIstream& operator>>( iIstream& is, int8& val);
252 
253 inline iIstream& operator>>( iIstream& is, uint64& val);
254 
255 inline iIstream& operator>>( iIstream& is, uint32& val);
256 
257 inline iIstream& operator>>( iIstream& is, uint8& val);
258 
259 inline iIstream& operator>>( iIstream& is, float& val);
260 
261 inline iIstream& operator>>( iIstream& is, double& val);
262 
263 inline iIstream& operator>>( iIstream& is, size_t& val);
264 
265 
266 
267 } // pFlow
268 
269 
270 #include "iIstreamI.hpp"
271 
272 
273 #endif //__iIstream_hpp__
pFlow::iIstream::readBegin
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: iIstream.cpp:238
pFlow::iIstream::seek
virtual void seek(size_t pos)=0
pFlow::iIstream::findTokenAndNextSilent
virtual bool findTokenAndNextSilent(const word &w, word &nextW, int32 limitLine=100)
Definition: iIstream.cpp:203
pFlow::iIstream::lookupDataOrSet
T lookupDataOrSet(const word &keyword, const T &setVal)
lookup for keyword and data; set to setVal if lookup fails.
Definition: iIstreamI.hpp:68
pFlow::iIstream::read
virtual iIstream & read(token &)=0
Return next token from stream.
pFlow::token
Token class based on OpenFOAM stream, with some modifications/simplifications to be tailored to our n...
Definition: token.hpp:44
pFlow::iIstream::readString
virtual iIstream & readString(word &)=0
Read a string.
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
token.hpp
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::iIstream::readEnd
bool readEnd(const char *funcName)
End read of data chunk, ends with ')' return true or FatalIOError.
Definition: iIstream.cpp:258
pFlow::iIstream::readEndStatement
char readEndStatement(const char *funcName)
End statement character ;.
Definition: iIstream.cpp:359
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:52
pFlow::iIstream::iIstream
iIstream(writeFormat wf)
Definition: iIstream.hpp:60
pFlow::iIstream::findKeywordAndVal
bool findKeywordAndVal(const word &keyword, T &val, bool checkEndStatement=true)
find a pair of keyword and data terminated by ; keyword data; return false if keyword does not exist ...
Definition: iIstreamI.hpp:24
pFlow::iIstream::findTokenSilent
virtual bool findTokenSilent(const word &w, int32 limitLine=100)
search for all tokesn and find the first word token that matchs
Definition: iIstream.cpp:123
pFlow
Definition: demGeometry.hpp:27
pFlow::IOstreamManip
IOstream &(* IOstreamManip)(IOstream &)
An IOstream manipulator.
Definition: IOstream.hpp:308
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:90
pFlow::token::reset
void reset()
Reset token to UNDEFINED and clear any allocated storage.
Definition: tokenI.hpp:263
pFlow::iIstream::rewind
virtual void rewind()=0
Rewind the stream so that it may be read again.
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:129
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::iIstreamManip
iIstream &(* iIstreamManip)(iIstream &)
Definition: iIstream.hpp:228
pFlow::iIstream::getBack
bool getBack(token &tok)
Get the put back token if there is one and return true.
Definition: iIstream.cpp:45
pFlow::iIstream::iIstream
iIstream()
default
Definition: iIstream.hpp:55
pFlow::iIstream::nextData
bool nextData(const word &keyword, T &data)
read the data next to keword keyword data; check the keyword is correct or not
Definition: iIstreamI.hpp:81
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::iIstream::readBeginList
char readBeginList(const char *funcName)
Begin read of list data, starts with '(' or '{' return starting delimiter or FatalIOError.
Definition: iIstream.cpp:315
pFlow::iIstream::putBack_
bool putBack_
Has a token been put back on the stream?
Definition: iIstream.hpp:45
pFlow::iIstream::putBack
void putBack(const token &tok)
Put back token Only a single put back is permitted.
Definition: iIstream.cpp:23
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)
search for all tokens and find the first word token and also next word token chekck if it is eneded w...
Definition: iIstream.cpp:157
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:377
pFlow::iIstream::resetPutBack
void resetPutBack()
reset the put back token;
Definition: iIstream.hpp:89
pFlow::iIstream::tell
virtual size_t tell()=0
Return current position indicator.
pFlow::iIstream::lookupData
T lookupData(const word &keyword)
lookup for keyword and data; fatalExit if fails
Definition: iIstreamI.hpp:52
pFlow::iIstream::readBeginSquare
bool readBeginSquare(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: iIstream.cpp:277
IOstream.hpp
iIstreamI.hpp
pFlow::iIstream::putBackToken_
token putBackToken_
The last token put back on the stream.
Definition: iIstream.hpp:48
pFlow::iIstream::readEndList
char readEndList(const char *funcName)
End read of list data, ends with ')' or '}' return closing delimiter or FatalIOError.
Definition: iIstream.cpp:336
pFlow::iIstream::findBinaryBlockStart
virtual size_t findBinaryBlockStart()
It seek for a character sequence that indicates the start of a binary block char sequence is 255 255 ...
Definition: iIstream.cpp:78
pFlow::uint64
unsigned long long int uint64
Definition: builtinTypes.hpp:58
pFlow::int8
signed char int8
Definition: builtinTypes.hpp:48
iOstream.hpp
pFlow::IOstream::writeFormat
writeFormat
Definition: IOstream.hpp:59
pFlow::iIstream::findToken
virtual bool findToken(const word &w)
search for all tokesn and find the first word token tbat matchs w
Definition: iIstream.cpp:84
pFlow::uint8
unsigned char uint8
Definition: builtinTypes.hpp:54
pFlow::IOstream
A base calss for input/output streams.
Definition: IOstream.hpp:47
pFlow::iIstream::~iIstream
virtual ~iIstream()=default
Destructor.
pFlow::iIstream::readEndSquare
bool readEndSquare(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: iIstream.cpp:296
error.hpp
pFlow::iIstream::peekBack
bool peekBack(token &tok)
Peek at the put back token without removing it.
Definition: iIstream.cpp:64