www.cemf.ir
iTstream.cpp
Go to the documentation of this file.
1 
2 #include "iTstream.hpp"
3 #include "error.hpp"
4 #include "iOstream.hpp"
5 
7 {
8  return currentToken_ == tokenList_.end();
9 }
10 
12 {
13  currentToken_ = tokenList_.begin();
14 }
15 
17 {
18  for (auto it = tokenList_.begin(); it != tokenList_.end(); )
19  {
20  if (!validTokenForStream(*it))
21  {
22  it = tokenList_.erase(it);
23  }
24  else
25  {
26  ++it;
27  }
28  }
29 }
30 
32 (
33  const word& streamName
34 )
35 :
36  iIstream(),
37  name_(streamName),
38  tokenList_(),
39  currentToken_(tokenList_.begin())
40 {
41  setOpened();
42  setGood();
43  rewind();
44 }
45 
47 (
48  const word& streamName,
49  const tokenList& tList
50 )
51 :
52  iIstream(),
53  name_(streamName),
54  tokenList_(tList),
55  currentToken_(tokenList_.begin())
56 {
57  setOpened();
58  setGood();
59  // check for invalid tokens in the tList
60  validate();
61  rewind();
62 }
63 
65 (
66  const word& streamName,
67  tokenList&& tList
68 )
69 :
70  iIstream(),
71  name_(streamName),
72  tokenList_(std::move(tList)),
73  currentToken_(tokenList_.begin())
74 {
75  setOpened();
76  setGood();
77 
78  // check for invalid tokens in the tList
79  validate();
80  rewind();
81 }
82 
83 // copy assignment from tokenList
85 {
86  tokenList_ = tList;
87  validate();
88  rewind();
89 }
90 
91 // move assignment from tokenList
93 {
94  tokenList_ = std::move(tList);
95  validate();
96  rewind();
97 }
98 
100 {
101  return name_;
102 }
103 
105 {
106  return name_;
107 }
108 
109 
111 (
112  token& t
113 )
114 {
115  // Return the put back token if it exists
116  if (iIstream::getBack(t))
117  {
118  lineNumber_ = t.lineNumber();
119  setGood();
120  return *this;
121  }
122 
123  if ( !isLastToken() )
124  {
125  //t = operator[](tokenIndex_++);
126  lineNumber_ = t.lineNumber();
127  t = *currentToken_;
128  setGood();
129  currentToken_++;
130 
131  if( isLastToken() )
132  {
133  setEof();
134  }
135  }
136  else
137  {
138  if (eof())
139  {
141  "attempt to read beyond EOF \n";
142  fatalExit;
143  setBad();
144  }
145  else
146  {
147  setEof();
148  }
149 
150  t.reset();
151 
152  if (tokenList_.size())
153  {
154  t.lineNumber() = tokenList_.back().lineNumber();
155  }
156  else
157  {
158  t.lineNumber() = lineNumber();
159  }
160  }
161 
162  return *this;
163 }
164 
165 
166 
168 (
169  char& c
170 )
171 {
173  fatalExit;
174  CONSUME_PARAM(c);
175  return *this;
176 }
177 
178 
180 (
181  word& str
182 )
183 {
185  fatalExit;
186  CONSUME_PARAM(str);
187  return *this;
188 }
189 
190 
192 (
193  word& str
194 )
195 {
197  fatalExit;
198  CONSUME_PARAM(str);
199  return *this;
200 }
201 
202 
204 (
205  int64& val
206 )
207 {
209  fatalExit;
210  CONSUME_PARAM(val);
211  return *this;
212 }
213 
215 (
216  int32& val
217 )
218 {
220  fatalExit;
221  CONSUME_PARAM(val);
222  return *this;
223 }
224 
225 
227 (
228  int8& val
229 )
230 {
232  fatalExit;
233  CONSUME_PARAM(val);
234  return *this;
235 }
236 
238 (
239  uint64& val
240 )
241 {
243  fatalExit;
244  CONSUME_PARAM(val);
245  return *this;
246 }
247 
249 (
250  uint32& val
251 )
252 {
254  fatalExit;
255  CONSUME_PARAM(val);
256  return *this;
257 }
258 
260 (
261  uint8& val
262 )
263 {
265  fatalExit;
266  CONSUME_PARAM(val);
267  return *this;
268 }
269 
270 
272 (
273  float& val
274 )
275 {
277  fatalExit;
278  CONSUME_PARAM(val);
279  return *this;
280 }
281 
282 
284 (
285  double& val
286 )
287 {
288 
290  fatalExit;
291  CONSUME_PARAM(val);
292  return *this;
293 }
294 
296 (
297  char* buffer,
298  std::streamsize count
299 )
300 {
302  return *this;
303 }
304 
306 {
308  setFirstToken();
309  setGood();
310 }
311 
312 void pFlow::iTstream::seek(size_t pos)
313 {
315 }
316 
318 {
320  tokenList_.clear();
321  setFirstToken();
322  setGood();
323 }
324 
326 {
328  return static_cast<size_t>(-1);
329 }
330 
332 {
333  return tokenList_;
334 }
335 
336 size_t pFlow::iTstream::size()const
337 {
338  return tokenList_.size();
339 }
340 
342 {
343  return tokenList_.size();
344 }
345 
347 (
348  const tokenList & tList
349 )
350 {
351 
352  for(auto& t:tList)
353  {
354  if(validTokenForStream(t)) tokenList_.push_back(t);
355  }
356  rewind();
357 }
358 
360 (
361  const token& t
362 )
363 {
364  if(validTokenForStream(t)) tokenList_.push_back(t);
365  rewind();
366 }
367 
368 // ************************************************************************* //
pFlow::iTstream::tokens
const tokenList & tokens() const
const access to token list
Definition: iTstream.cpp:331
notImplementedFunction
#define notImplementedFunction
Report that a function is yet not implemented.
Definition: error.hpp:84
pFlow::List< token >
pFlow::iTstream::isLastToken
bool isLastToken()
check if end of list is reached
Definition: iTstream.cpp:6
iTstream.hpp
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
pFlow::iTstream::tell
size_t tell() override
Return current position indicator.
Definition: iTstream.cpp:325
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::iTstream::reset
virtual void reset()
reset the iTstream and make the stream empty
Definition: iTstream.cpp:317
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::iTstream::size
size_t size() const
size
Definition: iTstream.cpp:336
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:52
pFlow::iTstream::setFirstToken
void setFirstToken()
rewind the stream
Definition: iTstream.cpp:11
pFlow::iTstream::operator=
iTstream & operator=(const iTstream &)=default
copy assignment
pFlow::validTokenForStream
bool validTokenForStream(const token tok)
Is tok a valid token for this stream?
pFlow::iTstream::seek
void seek(size_t pos) override
Definition: iTstream.cpp:312
pFlow::token::reset
void reset()
Reset token to UNDEFINED and clear any allocated storage.
Definition: tokenI.hpp:263
pFlow::iTstream::appendTokens
void appendTokens(const tokenList &tList)
append a list of tokens to the end of tokens
Definition: iTstream.cpp:347
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::iIstream::getBack
bool getBack(token &tok)
Get the put back token if there is one and return true.
Definition: iIstream.cpp:45
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::iTstream::tokenList_
tokenList tokenList_
list of tokens in this stream
Definition: iTstream.hpp:37
pFlow::iTstream::iTstream
iTstream(const word &streamName)
construct with a name
Definition: iTstream.cpp:32
pFlow::iTstream::name
virtual const word & name() const
Return the name of the stream.
Definition: iTstream.cpp:99
pFlow::iTstream::rewind
virtual void rewind() override
Rewind the stream so that it may be read again.
Definition: iTstream.cpp:305
pFlow::iTstream::read
virtual iIstream & read(token &t) override
Return next token from stream.
Definition: iTstream.cpp:111
pFlow::count
auto count(const Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:26
pFlow::iTstream::validate
void validate()
check for valid tokens in the tokenList
Definition: iTstream.cpp:16
pFlow::iIstream::resetPutBack
void resetPutBack()
reset the put back token;
Definition: iIstream.hpp:89
pFlow::iTstream::appendToken
void appendToken(const token &t)
append token to the end of token and rewind the stream
Definition: iTstream.cpp:360
pFlow::iTstream::numTokens
size_t numTokens() const
size
Definition: iTstream.cpp:341
CONSUME_PARAM
#define CONSUME_PARAM(x)
Definition: pFlowMacros.hpp:38
pFlow::uint64
unsigned long long int uint64
Definition: builtinTypes.hpp:58
pFlow::iTstream::currentToken_
tokenList::iterator currentToken_
current token
Definition: iTstream.hpp:40
pFlow::int8
signed char int8
Definition: builtinTypes.hpp:48
pFlow::iTstream::readString
virtual iIstream & readString(word &str) override
Read a string.
Definition: iTstream.cpp:192
iOstream.hpp
pFlow::uint8
unsigned char uint8
Definition: builtinTypes.hpp:54
pFlow::token::lineNumber
int32 lineNumber() const
The line number for the token.
Definition: tokenI.hpp:378
error.hpp