iIstream.cpp
Go to the documentation of this file.
1 
2 #include "iIstream.hpp"
3 
4 
6 {
7  if (bad())
8  {
10  "stream is bad.\n";
11  fatalExit;
12  }
13  else if (putBack_)
14  {
16  "putBack is already full. \n";
17  fatalExit;
18  }
19  else
20  {
21  putBackToken_ = tok;
22  putBack_ = true;
23  }
24 }
25 
26 
28 {
29 
30  if (bad())
31  {
33  return false;
34  }
35  else if (putBack_)
36  {
37  tok = putBackToken_;
38  putBack_ = false;
39  return true;
40  }
41 
42  return false;
43 }
44 
45 
47 {
48  if (putBack_)
49  {
50  tok = putBackToken_;
51  }
52  else
53  {
54  tok.reset();
55  }
56 
57  return putBack_;
58 }
59 
61 {
62  rewind();
63  token next;
64  bool isFirstToken = true;
65 
66  while( !eof() && good() )
67  {
68  read(next);
69  if(next.error())
70  {
72  "error in reading stream " << name() <<
73  " at line number "<< lineNumber()<<endl;
74  return false;
75  }
76 
77 
78 
79  if( next.isWord() && isFirstToken)
80  {
81  if(next.wordToken() == w ) return true;
82  }
83 
84  if(next.isEndStatement()|| next.isEndBlock())
85  isFirstToken = true;
86  else
87  isFirstToken = false;
88  }
89 
90  return false;
91 }
92 
93 bool pFlow::iIstream::findTokenSilent( const word & w, int32 limitLine )
94 {
95  rewind();
96  token next;
97  bool isFirstToken = true;
98 
99  while( !eof() && good() && lineNumber()<limitLine )
100  {
101  read(next);
102  if(next.error())
103  {
104  return false;
105  }
106 
107  if( next.isWord() && isFirstToken)
108  {
109  if(next.wordToken() == w) return true;
110  }
111 
112  if(next.isEndStatement()|| next.isEndBlock())
113  isFirstToken = true;
114  else
115  isFirstToken = false;
116  }
117 
118  return false;
119 }
120 
122 (
123  const word& w,
124  word& nextW,
125  bool checkEndStatement
126 )
127 {
128  if( findToken(w) )
129  {
130  // next token
131  token next(*this);
132 
133  if(next.error())
134  {
135  ioErrorInFile( name(), lineNumber());
136  return false;
137  }
138  if( next.isWord() )
139  {
140  nextW = next.wordToken();
141 
142  if( checkEndStatement )
143  {
144  read(next);
145 
146  if( !next.isEndStatement() )
147  {
148  ioErrorInFile(name(), lineNumber()) <<
149  " expected ; but found " << next;
150  return false;
151  }
152 
153  }
154 
155  return true;
156 
157  }else
158  {
159  ioErrorInFile( name(), lineNumber() ) <<
160  " token is not a word" << next <<endl;
161  return false;
162  }
163  }
164 
165  return false;
166 }
167 
168 bool pFlow::iIstream::findTokenAndNextSilent(const word& w, word& nextW, int32 limitLine)
169 {
170  if( findTokenSilent(w, limitLine) )
171  {
172  // next token
173  token next(*this);
174 
175  if(next.error())
176  {
177  return false;
178  }
179 
180  if( next.isWord() )
181  {
182  nextW = next.wordToken();
183 
184  read(next);
185 
186  if( !next.isEndStatement() )
187  {
188  return false;
189  }
190 
191  return true;
192 
193  }else
194  {
195  return false;
196  }
197  }
198 
199  return false;
200 }
201 
202 
203 bool pFlow::iIstream::readBegin(const char* funcName)
204 {
205 
206  const token delimiter(*this);
207 
208  if (delimiter != token::BEGIN_LIST)
209  {
210  setBad();
211 
212  ioErrorInFile( name(), lineNumber() )
213  << "Expected a '" << token::BEGIN_LIST
214  << "' while reading " << funcName
215  << ", found " << delimiter << endl;
216  fatalExit;
217  }
218 
219  return true;
220 }
221 
222 
223 bool pFlow::iIstream::readEnd(const char* funcName)
224 {
225  const token delimiter(*this);
226 
227  if (delimiter != token::END_LIST)
228  {
229  setBad();
230 
231  ioErrorInFile( name(), lineNumber())
232  << "Expected a '" << token::END_LIST
233  << "' while reading " << funcName
234  << ", found "
235  << delimiter <<endl;
236  fatalExit;
237  }
238 
239  return true;
240 }
241 
242 bool pFlow::iIstream::readBeginSquare(const char* funcName)
243 {
244  const token delimiter(*this);
245 
246  if (delimiter != token::BEGIN_SQR)
247  {
248  setBad();
249 
250  ioErrorInFile( name(), lineNumber())
251  << "Expected a '" << token::BEGIN_SQR
252  << "' while reading " << funcName
253  << ", found "
254  << delimiter <<endl;
255  fatalExit;
256  }
257 
258  return true;
259 }
260 
261 bool pFlow::iIstream::readEndSquare(const char* funcName)
262 {
263  const token delimiter(*this);
264 
265  if (delimiter != token::END_SQR)
266  {
267  setBad();
268 
269  ioErrorInFile( name(), lineNumber())
270  << "Expected a '" << token::END_SQR
271  << "' while reading " << funcName
272  << ", found "
273  << delimiter <<endl;
274  fatalExit;
275  }
276 
277  return true;
278 }
279 
280 char pFlow::iIstream::readBeginList(const char* funcName)
281 {
282  const token delimiter(*this);
283 
284  if (delimiter != token::BEGIN_LIST && delimiter != token::BEGIN_BLOCK)
285  {
286  setBad();
287  ioErrorInFile( name(), lineNumber() )
288  << "Expected a '" << token::BEGIN_LIST
289  << "' or a '" << token::BEGIN_BLOCK
290  << "' while reading " << funcName
291  << ", found " << delimiter<<endl;
292  fatalExit;
293 
294  return '\0';
295  }
296 
297  return delimiter.pToken();
298 }
299 
300 
301 char pFlow::iIstream::readEndList(const char* funcName)
302 {
303  const token delimiter(*this);
304 
305  if (delimiter != token::END_LIST && delimiter != token::END_BLOCK)
306  {
307  setBad();
308 
309  ioErrorInFile( name(), lineNumber() )
310  << "Expected a '" << token::END_LIST
311  << "' or a '" << token::END_BLOCK
312  << "' while reading " << funcName
313  << ", found " << delimiter
314  << " at stream position " << endl;
315  fatalExit;
316 
317  return '\0';
318  }
319 
320  return delimiter.pToken();
321 }
322 
323 
324 char pFlow::iIstream::readEndStatement(const char* funcName)
325 {
326  CONSUME_PARAM(funcName);
327  const token delimiter(*this);
328 
329  if (!delimiter.isEndStatement())
330  {
331  setBad();
332  ioErrorInFile( name(), lineNumber() ) <<
333  " expected ; but found " << delimiter << endl;
334  fatalExit;
335 
336  return '\0';
337  }
338 
339  return delimiter.pToken();
340 }
341 
343 {
344  if (!good())
345  {
346  check("iIstream::operator()");
347  fatalExit;
348  }
349 
350  return const_cast<iIstream&>(*this);
351 }
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
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::token
Definition: token.hpp:42
pFlow::token::pToken
punctuationToken pToken() const
Definition: tokenI.hpp:452
iIstream.hpp
pFlow::token::isEndBlock
bool isEndBlock() const
Definition: tokenI.hpp:442
pFlow::token::END_BLOCK
@ END_BLOCK
End block [isseparator].
Definition: token.hpp:94
pFlow::token::error
bool error() const
Definition: tokenI.hpp:384
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::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::token::BEGIN_BLOCK
@ BEGIN_BLOCK
Begin block [isseparator].
Definition: token.hpp:93
pFlow::iIstream::findTokenSilent
virtual bool findTokenSilent(const word &w, int32 limitLine=100)
Definition: iIstream.cpp:93
pFlow::token::reset
void reset()
Definition: tokenI.hpp:245
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::IOstream::bad
bool bad() const
Definition: IOstream.hpp:168
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::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::iIstream::findTokenAndNext
virtual bool findTokenAndNext(const word &w, word &nextW, bool checkEndStatement=true)
Definition: iIstream.cpp:122
pFlow::token::END_LIST
@ END_LIST
End list [isseparator].
Definition: token.hpp:90
pFlow::iIstream::operator()
iIstream & operator()() const
Definition: iIstream.cpp:342
pFlow::IOstream::name
virtual const word & name() const
Definition: IOstream.cpp:31
pFlow::iIstream::readBeginSquare
bool readBeginSquare(const char *funcName)
Definition: iIstream.cpp:242
pFlow::token::BEGIN_LIST
@ BEGIN_LIST
Begin list [isseparator].
Definition: token.hpp:89
pFlow::token::BEGIN_SQR
@ BEGIN_SQR
Begin dimensions [isseparator].
Definition: token.hpp:91
pFlow::iIstream::putBackToken_
token putBackToken_
Definition: iIstream.hpp:44
pFlow::iIstream::readEndList
char readEndList(const char *funcName)
Definition: iIstream.cpp:301
CONSUME_PARAM
#define CONSUME_PARAM(x)
Definition: pFlowMacros.hpp:38
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
pFlow::iIstream::findToken
virtual bool findToken(const word &w)
Definition: iIstream.cpp:60
pFlow::token::isEndStatement
bool isEndStatement() const
Definition: tokenI.hpp:431
pFlow::token::END_SQR
@ END_SQR
End dimensions [isseparator].
Definition: token.hpp:92
pFlow::token::wordToken
const word & wordToken() const
Definition: tokenI.hpp:600
pFlow::token::isWord
bool isWord() const
Definition: tokenI.hpp:584
pFlow::iIstream::readEndSquare
bool readEndSquare(const char *funcName)
Definition: iIstream.cpp:261
pFlow::iIstream::peekBack
bool peekBack(token &tok)
Definition: iIstream.cpp:46