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 
226 (
227  int16& val
228 )
229 {
231  fatalExit;
232  CONSUME_PARAM(val);
233  return *this;
234 }
235 
237 (
238  int8& val
239 )
240 {
242  fatalExit;
243  CONSUME_PARAM(val);
244  return *this;
245 }
246 
248 (
249  label& val
250 )
251 {
253  fatalExit;
254  CONSUME_PARAM(val);
255  return *this;
256 }
257 
259 (
260  uint32& val
261 )
262 {
264  fatalExit;
265  CONSUME_PARAM(val);
266  return *this;
267 }
268 
270 (
271  uint16& val
272 )
273 {
275  fatalExit;
276  CONSUME_PARAM(val);
277  return *this;
278 }
279 
280 
282 (
283  float& val
284 )
285 {
287  fatalExit;
288  CONSUME_PARAM(val);
289  return *this;
290 }
291 
292 
294 (
295  double& val
296 )
297 {
298 
300  fatalExit;
301  CONSUME_PARAM(val);
302  return *this;
303 }
304 
305 
306 
308 {
310  setFirstToken();
311  setGood();
312 }
313 
314 
316 {
318  tokenList_.clear();
319  setFirstToken();
320  setGood();
321 }
322 
324 {
325  return tokenList_;
326 }
327 
328 size_t pFlow::iTstream::size()const
329 {
330  return tokenList_.size();
331 }
332 
334 {
335  return tokenList_.size();
336 }
337 
339 (
340  const tokenList & tList
341 )
342 {
343 
344  for(auto& t:tList)
345  {
346  if(validTokenForStream(t)) tokenList_.push_back(t);
347  }
348  rewind();
349 }
350 
352 (
353  const token& t
354 )
355 {
356  if(validTokenForStream(t)) tokenList_.push_back(t);
357  rewind();
358 }
359 
360 // ************************************************************************* //
pFlow::iTstream::tokens
const tokenList & tokens() const
Definition: iTstream.cpp:323
notImplementedFunction
#define notImplementedFunction
Definition: error.hpp:47
pFlow::List< token >
pFlow::iTstream::isLastToken
bool isLastToken()
Definition: iTstream.cpp:6
iTstream.hpp
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::token
Definition: token.hpp:42
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::iTstream::reset
virtual void reset()
Definition: iTstream.cpp:315
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::iTstream::size
size_t size() const
Definition: iTstream.cpp:328
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:55
pFlow::iTstream::rewind
virtual void rewind()
Definition: iTstream.cpp:307
pFlow::iTstream::setFirstToken
void setFirstToken()
Definition: iTstream.cpp:11
pFlow::iTstream::operator=
iTstream & operator=(const iTstream &)=default
pFlow::validTokenForStream
bool validTokenForStream(const token tok)
pFlow::token::reset
void reset()
Definition: tokenI.hpp:245
pFlow::iTstream::appendTokens
void appendTokens(const tokenList &tList)
Definition: iTstream.cpp:339
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::iIstream::getBack
bool getBack(token &tok)
Definition: iIstream.cpp:27
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::iTstream::tokenList_
tokenList tokenList_
Definition: iTstream.hpp:31
pFlow::iTstream::iTstream
iTstream(const word &streamName)
Definition: iTstream.cpp:32
pFlow::iTstream::name
virtual const word & name() const
Definition: iTstream.cpp:99
pFlow::iTstream::read
virtual iIstream & read(token &t) override
Definition: iTstream.cpp:111
pFlow::iTstream::validate
void validate()
Definition: iTstream.cpp:16
pFlow::iIstream::resetPutBack
void resetPutBack()
Definition: iIstream.hpp:80
pFlow::iTstream::appendToken
void appendToken(const token &t)
Definition: iTstream.cpp:352
pFlow::iTstream::numTokens
size_t numTokens() const
Definition: iTstream.cpp:333
CONSUME_PARAM
#define CONSUME_PARAM(x)
Definition: pFlowMacros.hpp:38
pFlow::iTstream::currentToken_
tokenList::iterator currentToken_
Definition: iTstream.hpp:34
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::int8
signed char int8
Definition: builtinTypes.hpp:49
pFlow::iTstream::readString
virtual iIstream & readString(word &str) override
Definition: iTstream.cpp:192
iOstream.hpp
pFlow::token::lineNumber
int32 lineNumber() const
Definition: tokenI.hpp:360
error.hpp