cfl_tokenreader.cpp
Go to the documentation of this file.
1 /** @file cfl_tokenreader.cpp @brief Class TokenReader */
2 
3 /* FAU Discrete Event Systems Library (libfaudes)
4 
5 Copyright (C) 2006 Bernd Opitz
6 Copyright (C) 2006 Thomas Moor
7 Exclusive copyright is granted to Klaus Schmidt
8 
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13 
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 
24 
25 
26 #include "cfl_tokenwriter.h"
27 #include "cfl_tokenreader.h"
28 
29 namespace faudes {
30 
31 // TokenReader(mode,instring)
32 TokenReader::TokenReader(Mode mode, const std::string& rInString)
33  : mMode(mode), mpStream(NULL), mFileName("")
34 {
35  switch(mode) {
36  case String:
37  // use mSStream
38  FD_DV("TokenReader::Tokenreader(String, ...): " << rInString);
39  mpSStream= new std::istringstream(rInString, std::istringstream::in | std::istringstream::binary);
41  Rewind();
42  break;
43  case File:
44  // set up mFStream
45  FD_DV("TokenReader::Tokenreader(File, \"" << rInString <<"\")");
46  mFStream.exceptions(std::ios::badbit|std::ios::failbit);
47  try{
48  mFStream.open(rInString.c_str(), std::ios::in | std::ios::binary);
49  }
50  catch (std::ios::failure&) {
51  std::stringstream errstr;
52  errstr << "Exception opening/reading file \""<< rInString << "\"";
53  throw Exception("TokenReader::TokenReader", errstr.str(), 1);
54  }
55  mFileName=rInString;
57  Rewind();
58  break;
59  default:
60  std::stringstream errstr;
61  errstr << "Invalid Mode / Not implemented";
62  throw Exception("TokenReader::TokenReader(mode,instring)", errstr.str(), 1);
63  }
64 }
65 
66 
67 // TokenReader(rFilename)
68 TokenReader::TokenReader(const std::string& rFilename)
69  : mMode(File), mpStream(NULL), mFileName(rFilename)
70 {
71  // set up mFStream
72  FD_DV("TokenReader::Tokenreader(File, \"" << rFilename <<"\")");
73  mFStream.exceptions(std::ios::badbit|std::ios::failbit);
74  try{
75  mFStream.open(rFilename.c_str(), std::ios::in | std::ios::binary);
76  }
77  catch (std::ios::failure&) {
78  std::stringstream errstr;
79  errstr << "Exception opening/reading file \""<< rFilename << "\"";
80  throw Exception("TokenReader::TokenReader", errstr.str(), 1);
81  }
82  mFileName=rFilename;
84  Rewind();
85 }
86 
87 
88 // destruct
90  if(mMode==String) delete mpSStream;
91 }
92 
93 // Stream()
94 std::istream* TokenReader::Streamp(void) {
95  return mpStream;
96 }
97 
98 // Rewind()
99 void TokenReader::Rewind(void) {
100  FD_DV("TokenReader::Rewind: \"" << mFileName <<"\"");
101  try {
102  mpStream->clear();
103  mpStream->seekg(0);
105  mLevel=0;
106  mLineCount=1;
107  mFilePos=0;
108  mFaudesComments=true;
109  mLevelState.resize(mLevel+1);
110  mLevelState.back().mLabel="OUTER";
111  mLevelState.back().mStartPosition=mFilePos;
112  mLevelState.back().mStartLine=mLineCount;
113  mLevelState.back().mStartPeek=mPeekToken;
114  mLevelState.back().mFaudesComments=mFaudesComments;
115  }
116  catch (std::ios::failure&) {
117  std::stringstream errstr;
118  errstr << "Exception opening/reading file in "<< FileLine();
119  throw Exception("TokenReader::Rewind", errstr.str(), 1);
120  }
121 }
122 
123 
124 // FileName()
125 std::string TokenReader::FileName(void) const {
126  return mFileName;
127 }
128 
129 // Peek(token)
130 bool TokenReader::Peek(Token& token) {
131  // read to peek buffer
132  if(mPeekToken.IsNone()) {
133  try{
135  } catch (std::ios::failure&) {
136  std::stringstream errstr;
137  errstr << "Exception opening/reading file in "<< FileLine();
138  throw Exception("TokenReader::Peek", errstr.str(), 1);
139  }
140  }
141  // get from peek buffer
142  token=mPeekToken;
143  // substitute empty sections
144  if(token.IsEmpty()) token.ClrEnd();
145  // done
146  FD_DV("TokenReader: Peek: " << token.Str());
147  return !token.IsNone();
148 }
149 
150 // Get(token)
151 bool TokenReader::Get(Token& token) {
152  bool res;
153  // get token from peek buffer
154  res=Peek(token);
155  // invalidate buffer: case a
157  // invalidate buffer: case b
158  if(mPeekToken.IsEmpty()) {
159  FD_DV("TokenReader: fake end : " << mPeekToken.Str());
160  mPeekToken.SetEnd(std::string(mPeekToken.StringValue()));
161  }
162  // bail out on error
163  if(!res) return false;
164  // ignore misbehavong <br> tag in by level management
165  if(token.IsBegin("br") || token.IsEnd("br")) return true;
166  // track state (level of nested sections, filepos etc)
167  mFilePos=mpStream->tellg();
168  if(token.IsBegin()) {
169  // track level
170  mLevel++;
171  // update state
172  if(token.StringValue()=="ReferencePage") mFaudesComments=false;
173  if(token.StringValue()=="html") mFaudesComments=false;
174  if(token.StringValue()=="Html") mFaudesComments=false;
175  if(token.StringValue()=="HTML") mFaudesComments=false;
176  // record state
177  mLevelState.resize(mLevel+1);
178  mLevelState.back().mLabel=token.StringValue();
179  mLevelState.back().mStartPosition=mFilePos;
180  mLevelState.back().mStartLine=mLineCount;
181  mLevelState.back().mStartPeek=mPeekToken;
182  mLevelState.back().mFaudesComments=mFaudesComments;
183  }
184  if(token.IsEnd()) {
185 #ifdef FAUDES_CHECKED
186  if(token.StringValue()!=mLevelState.back().mLabel)
187  FD_WARN("TokenReader::Get(): end of section \"" << token.StringValue() << "\" at " << FileLine()
188  << " should match \"" << mLevelState.back().mLabel << "\" at line " << mLevelState.back().mStartLine );
189 #endif
190  if(mLevel<1) {
191 #ifdef FAUDES_CHECKED
192  FD_WARN("TokenReader::Get(): Unbalanced end of section \"" << token.StringValue() << "\" at " << FileLine());
193 #endif
194  token.SetNone();
195  return false;
196  }
197  mLevel--;
198  mLevelState.pop_back();
199  mFaudesComments=mLevelState.back().mFaudesComments;
200  }
201  FD_DV("TokenReader:Get(): " << token.Str());
202 
203  return res;
204 }
205 
206 // SeekBegin(label)
207 void TokenReader::SeekBegin(const std::string& rLabel) {
208  Token token;
209  SeekBegin(rLabel,token);
210 }
211 
212 // SeekBegin(label)
213 void TokenReader::SeekBegin(const std::string& rLabel, Token& rToken) {
214  // search for begin at any descending level, no rewind
215  FD_DV("TokenReader::SeekBegin: " << rLabel << " at " << FileLine() << " level " << mLevel);
216  int level=mLevel;
217  for (;;) {
218  // swollow some plain text (e.g. html may contain plain text that cannot be tokenized properly)
219  std::string swallow;
220  ReadCharacterData(swallow);
221  // exception: did not get a token at all (incl. eof)
222  if(!Peek(rToken)) {
223  Rewind();
224  std::stringstream errstr;
225  errstr << "Section \"" << rLabel << "\" expected at " << FileLine() << " no more tokens";
226  throw Exception("TokenReader::SeekBegin", errstr.str(), 51);
227  }
228  // exception: current section ends
229  if((rToken.Type() == Token::End) && (mLevel == level)) {
230  mpStream->seekg(mLevelState[level].mStartPosition);
231  mFilePos=mLevelState[level].mStartPosition;
232  mLineCount=mLevelState[level].mStartLine;
233  mPeekToken=mLevelState[level].mStartPeek;
234  mFaudesComments=mLevelState[level].mFaudesComments;
235  std::stringstream errstr;
236  errstr << "Section \"" << rLabel << "\" expected at " << FileLine()
237  << "current section ended unexpected. Found: " << rToken.StringValue() << " Type " << rToken.Type();
238  throw Exception("TokenReader::SeekBegin", errstr.str(), 51);
239  }
240  // success: found begin section
241  if ((rToken.IsBegin()) && (rToken.StringValue() == rLabel))
242  break;
243  // go on seeking
244  Get(rToken);
245  }
246 }
247 
248 // ReadBegin(label)
249 void TokenReader::ReadBegin(const std::string& rLabel) {
250  Token token;
251  ReadBegin(rLabel,token);
252 }
253 
254 // ReadBegin(label,token)
255 void TokenReader::ReadBegin(const std::string& rLabel, Token& rToken) {
256  FD_DV("Looking for Section \"" << rLabel << "\"");
257  try {
258  int level=mLevel;
259  int repcnt=0;
260  long int startpos=mFilePos;
261  FD_DV("section level " << level << " current pos " << startpos << " begin of section " << mLevelState[level].mStartPosition);
262  // search for begin at current level
263  for (;;) {
264  // swallow some plain text (e.g. html may contain plain text that cannot be tokenized properly)
265  std::string swallow;
266  ReadCharacterData(swallow);
267  // exception: did not get a token at all (incl eof)
268  if(!Peek(rToken)) {
269  std::stringstream errstr;
270  errstr << "Section \"" << rLabel << "\" expected at " << FileLine() << ", no token at all";
271  throw Exception("TokenReader::ReadBegin Peek", errstr.str(), 51);
272  }
273  // success: found begin section
274  if((rToken.IsBegin()) && (rToken.StringValue() == rLabel) && (mLevel==level)) {
275  Get(rToken);
276  break;
277  }
278  // exception: did not find begin label
279  if((mFilePos>=startpos) && (repcnt==1)) {
280  std::stringstream errstr;
281  errstr << "Section \"" << rLabel << "\" expected at " << FileLine() << ", did not find begin label";
282  throw Exception("TokenReader::ReadBegin: Missing", errstr.str(), 51);
283  }
284  // exception: did not find begin label
285  if(repcnt>1) {
286  std::stringstream errstr;
287  errstr << "Section \"" << rLabel << "\" expected at " << FileLine() << ", did not find begin label";
288  throw Exception("TokenReader::ReadBegin: Missing", errstr.str(), 51);
289  }
290  // rewind once when current section ends
291  if(rToken.IsEnd() && !rToken.IsBegin() && (mLevel == level)) {
292  mpStream->seekg(mLevelState[level].mStartPosition);
293  mFilePos=mLevelState[level].mStartPosition;
294  mLineCount=mLevelState[level].mStartLine;
295  mPeekToken=mLevelState[level].mStartPeek;
296  mFaudesComments=mLevelState[level].mFaudesComments;
297  repcnt++;
298  continue;
299  }
300  // skip this token
301  Get(rToken);
302  }
303  }
304  // catch my seek/tell errors
305  catch (std::ios::failure&) {
306  std::stringstream errstr;
307  errstr << "Section \"" << rLabel << "\" expected at " << FileLine();
308  throw Exception("TokenReader::ReadBegin Rewind", errstr.str(), 1);
309  }
310 }
311 
312 
313 // ExistsBegin(label)
314 bool TokenReader::ExistsBegin(const std::string& rLabel) {
315  FD_DV("TokenReader::ExistsBegin(): looking for Section \"" << rLabel << "\"");
316  try {
317  int level=mLevel;
318  int rwcnt=0;
319  long int startpos=mFilePos;
320  FD_DV("section level " << level << " current pos " << startpos << " begin of section " << mLevelState[level].mStartPosition);
321  Token token;
322  // search for begin at current level
323  for(;;) {
324  // swallow some plain text (e.g. html may contain plain text that cannot be tokenized properly)
325  std::string swallow;
326  ReadCharacterData(swallow);
327  // fail: did not get a token at all (e.g. eof)
328  if(!Peek(token)) {
329  return false;
330  }
331  // success: found begin section
332  if((token.IsBegin()) && (token.StringValue() == rLabel) && (mLevel==level)) {
333  return true;
334  }
335  // rewind once when current section ends
336  if(token.IsEnd() && (mLevel == level) && (rwcnt==0)) {
337  mpStream->seekg(mLevelState[level].mStartPosition);
338  mFilePos=mLevelState[level].mStartPosition;
339  mLineCount=mLevelState[level].mStartLine;
340  mPeekToken=mLevelState[level].mStartPeek;
341  mFaudesComments=mLevelState[level].mFaudesComments;
342  rwcnt++;;
343  if(rwcnt>1) return false; // survive funny mFilePos in e.g. empty sections
344  continue;
345  }
346  // fail: did not find begin label are one turn around
347  if((mFilePos>=startpos) && (rwcnt>0) && (mLevel == level)) {
348  return false;
349  }
350  // skip this token
351  Get(token);
352  }
353  }
354  // catch my seek/tell errors
355  catch (std::ios::failure&) {
356  std::stringstream errstr;
357  errstr << "IO Error while scanning Section \"" << rLabel << "\" at " << FileLine();
358  throw Exception("TokenReader::ExistsBegin IO", errstr.str(), 1);
359  }
360  return false;
361 }
362 
363 // ReadEnd(label)
364 void TokenReader::ReadEnd(const std::string& rLabel) {
365  FD_DV("TokenReader::ReadEnd: " << rLabel << " at " << FileLine() );
366  // search for end at current level
367  int level=mLevel;
368  Token token;
369  for (;;) {
370  // swallow some plain text (e.g. html may contain plain text that cannot be tokenized properly)
371  std::string swallow;
372  ReadCharacterData(swallow);
373  // exception: did not get a token at all
374  if(!Peek(token)) {
375  std::stringstream errstr;
376  errstr << "end of section \"" << rLabel << "\" expected at " << FileLine();
377  throw Exception("TokenReader::ReadEnd", errstr.str(), 51);
378  }
379  // success: found end of current section
380  if(token.IsEnd() && !token.IsBegin() && (token.StringValue() == rLabel) && (mLevel==level)) {
381  Get(token);
382  break;
383  }
384  // exception: current section ends with unexpected label
385  if(mLevel<level) {
386  std::stringstream errstr;
387  errstr << "end of Section \"" << rLabel << "\" expected at " << FileLine();
388  throw Exception("TokenReader::ReadEnd", errstr.str(), 51);
389  }
390  // get the token and continue
391  Get(token);
392  //std::cout << token.Str() << "\n";
393  }
394 }
395 
396 // Recover()
397 bool TokenReader::Recover(int level) {
398  // paranoia
399  if(level<0) return false;
400  // trivial cases
401  if(level>mLevel) return false;
402  if(level==mLevel) return true;
403  // loop until match
404  Token token;
405  while(Get(token))
406  if(mLevel<=level) break;
407  // done
408  return level==mLevel;
409 }
410 
411 // Recover()
412 bool TokenReader::Reset(int level) {
413  // paranoia
414  if(level>mLevel) return false;
415  // coonvenience arg: negative becomed reset this level
416  if(level<0) level=mLevel;
417  // trivial case
418  if(level==0) {
419  Rewind();
420  return true;
421  }
422  // loop until end
423  Token token;
424  while(Peek(token)) {
425  if((mLevel==level) && token.IsEnd()) break;
426  if(mLevel<level) return false;
427  Get(token);
428  }
429  // do the rewind
430  mpStream->seekg(mLevelState[level].mStartPosition);
431  mFilePos=mLevelState[level].mStartPosition;
432  mLineCount=mLevelState[level].mStartLine;
433  mPeekToken=mLevelState[level].mStartPeek;
434  mFaudesComments=mLevelState[level].mFaudesComments;
435  return true;
436 }
437 
438 // Eos(label)
439 bool TokenReader::Eos(const std::string& rLabel) {
440  // peek token and check for end of section
441  Token token;
442  Peek(token);
443  if(! (token.IsEnd() && !token.IsBegin()))
444  return false;
445  if((token.IsEnd() && !token.IsBegin()) && (token.StringValue() == rLabel))
446  return true;
447  std::stringstream errstr;
448  errstr << "section end \"" << rLabel << "\" expected at " << FileLine();
449  throw Exception("TokenReader::Eos", errstr.str(), 51);
450  return false;
451 }
452 
453 
454 // ReadInteger()
455 long int TokenReader::ReadInteger(void) {
456  Token token;
457  Get(token);
458  if(!token.IsInteger()) {
459  std::stringstream errstr;
460  errstr << "Integer expected at " << FileLine();
461  throw Exception("TokenReader::TokenReader", errstr.str(), 50);
462  }
463  return token.IntegerValue();
464 }
465 
466 // ReadFloat()
468  Token token;
469  Get(token);
470  if((!token.IsFloat()) && (!token.IsInteger())) {
471  std::stringstream errstr;
472  errstr << "Float expected at " << FileLine();
473  throw Exception("TokenReader::TokenReader", errstr.str(), 50);
474  }
475  return token.FloatValue();
476 }
477 
478 // ReadString()
479 std::string TokenReader::ReadString(void) {
480  Token token;
481  Get(token);
482  if(!token.IsString()) {
483  std::stringstream errstr;
484  errstr << "String expected at " << FileLine();
485  throw Exception("TokenReader::TokenReader", errstr.str(), 50);
486  }
487  return token.StringValue();
488 }
489 
490 
491 // ReadOption()
492 std::string TokenReader::ReadOption(void) {
493  Token token;
494  Get(token);
495  if(!token.IsOption()) {
496  std::stringstream errstr;
497  errstr << "Option expected at " << FileLine();
498  throw Exception("TokenReader::TokenReader", errstr.str(), 50);
499  }
500  return token.OptionValue();
501 }
502 
503 // ReadBinary()
504 void TokenReader::ReadBinary(std::string& rData) {
505  Token token;
506  Get(token);
507  if(!token.IsBinary()) {
508  std::stringstream errstr;
509  errstr << "Binary string expected at " << FileLine();
510  throw Exception("TokenReader::TokenReader", errstr.str(), 50);
511  }
512  rData = token.StringValue();
513 }
514 
515 
516 // ReadText()
517 void TokenReader::ReadText(const std::string& rLabel, std::string& rText) {
518  // insist in my begin tag
519  Token token;
520  Peek(token);
521  if(!token.IsBegin(rLabel)) {
522  std::stringstream errstr;
523  errstr << "Text element \""<< rLabel << "\" expected at " << FileLine();
524  throw Exception("TokenReader::TokenReader", errstr.str(), 50);
525  }
526  Get(token);
527  // do my text reading
528  int ll=Token::ReadEscapedString(mpStream,'<',rText);
529  if(ll<0) {
530  std::stringstream errstr;
531  errstr << "Text expected at " << FileLine();
532  throw Exception("TokenReader::TokenReader", errstr.str(), 50);
533  }
534  mLineCount+=ll;
535  // strip leading/trailing linefeeds
536  static const std::string line="\n\r\v";
537  std::size_t pos1=rText.find_first_not_of(line);
538  if(pos1!=std::string::npos)
539  rText=rText.substr(pos1);
540  else
541  rText.clear();
542  std::size_t pos2=rText.find_last_not_of(line);
543  if(pos2!=std::string::npos)
544  rText.erase(pos2+1);
545  // strip leading/trailing white if all in one line
546  static const std::string white=" \t";
547  if(pos1==0) {
548  pos1=rText.find_first_not_of(white);
549  if(pos1!=std::string::npos)
550  rText=rText.substr(pos1);
551  else
552  rText.clear();
553  std::size_t pos2=rText.find_last_not_of(white);
554  if(pos2!=std::string::npos)
555  rText.erase(pos2+1);
556  }
557  // insist in my end tag
558  Peek(token);
559  if(!token.IsEnd(rLabel)) {
560  std::stringstream errstr;
561  errstr << "End of text element \""<< rLabel << "\" expected at " << FileLine();
562  throw Exception("TokenReader::TokenReader", errstr.str(), 50);
563  }
564  Get(token);
565 }
566 
567 // ReadVerbatim()
568 void TokenReader::ReadVerbatim(const std::string& rLabel, std::string& rString) {
569  // insist in my tag
570  Token token;
571  Peek(token);
572  if(!token.IsBegin(rLabel)) {
573  std::stringstream errstr;
574  errstr << "Verbatim element \""<< rLabel << "\" expected at " << FileLine();
575  throw Exception("TokenReader::TokenReader", errstr.str(), 50);
576  }
577  Get(token);
578  rString.clear();
579  // loop cdata
580  int cnt=0;
581  rString.clear();
582  while(Peek(token)) {
583  if(!token.IsString()) break;
584  if(cnt>0 && !token.IsCdata()) break;
585  Get(token);
586  rString.append(token.StringValue());
587  cnt++;
588  }
589  // strip leading/trailing linefeeds
590  static const std::string line="\n\r\v";
591  std::size_t pos1=rString.find_first_not_of(line);
592  if(pos1!=std::string::npos)
593  rString=rString.substr(pos1);
594  else
595  rString.clear();
596  std::size_t pos2=rString.find_last_not_of(line);
597  if(pos2!=std::string::npos)
598  rString.erase(pos2+1);
599  // insist in my end tag
600  Peek(token);
601  if(!token.IsEnd(rLabel)) {
602  std::stringstream errstr;
603  errstr << "End of verbatim element \""<< rLabel << "\" expected at " << FileLine();
604  throw Exception("TokenReader::TokenReader", errstr.str(), 50);
605  }
606  Get(token);
607 }
608 
609 // ReadCharacterData()
610 void TokenReader::ReadCharacterData(std::string& rData) {
611  // if we have a markup token in the buffer there is no character data except white space
612  if(mPeekToken.IsBegin() || mPeekToken.IsEnd()) {
613  FD_DV("TokenReader::ReadCharacterData(): tag in buffer");
614  rData=mPeekToken.PreceedingSpace();
616  return;
617  }
618  // do my own reading
620  if(ll<0) {
621  std::stringstream errstr;
622  errstr << "Missformed character data at " << FileLine() << ": " << rData;
623  throw Exception("TokenReader::TokenReader", errstr.str(), 50);
624  }
625  mLineCount+=ll;
626  // prepend peek buffers string value (better: need rewind!)
627  if(mPeekToken.IsString())
628  rData=mPeekToken.StringValue() + " " + rData;
629  // invalidate buffer
631 }
632 
633 // ReadSection()
634 void TokenReader::ReadSection(std::string& rSectionString) {
635  // record current level
636  int clevel = Level();
637  // setup token writer for destination // need a better interface here: provide string buffer
639  tw.Endl(true);
640  // token copy loop
641  while(true) {
642  // see whether we can grab and copy some character data
643  std::string cdata;
644  ReadCharacterData(cdata);
645  tw.WriteCharacterData(cdata);
646  // break end of my level
647  Token token;
648  if(!Peek(token)) break;
649  if(token.IsEnd() && !token.IsBegin() && Level()==clevel)
650  break;
651  // get and copy markup token
652  Get(token);
653  token.PreceedingSpace("n"); // explicit no formating
654  tw.Write(token);
655  }
656  // done
657  rSectionString=tw.Str();
658 }
659 
660 
661 // Line()
662 int TokenReader::Line(void) const {
663  return mLineCount;
664 }
665 
666 // FileLine()
667 std::string TokenReader::FileLine(void) const {
668  if(mFileName!="")
669  return "("+ mFileName + ":" + ToStringInteger(mLineCount) +")";
670  else
671  return "(#" + ToStringInteger(mLineCount) +")";
672 }
673 
674 } // namespace faudes
#define FD_DV(message)
Debug: optional low-level report on iterations and token IO.
#define FD_WARN(message)
Debug: always report warnings.
Class TokenReader.
Class TokenWriter.
Faudes exception class.
Elementary type.
long int ReadInteger(void)
Read integer token.
std::string FileLine(void) const
Return "filename:line".
void ReadBinary(std::string &rData)
Read binary token.
void ReadCharacterData(std::string &rData)
Read plain text.
Mode
Mode of operation: read from file, stdin or string.
void ReadText(const std::string &rLabel, std::string &rText)
Read plain text.
Token mPeekToken
peek buffer
std::string ReadOption(void)
Read option token.
bool mFaudesComments
flag to ignore faudes comments marked by ''
bool Eos(const std::string &rLabel)
Peek a token and check whether it ends the specified section.
void SeekBegin(const std::string &rLabel)
Find specified begin label.
void ReadVerbatim(const std::string &rLabel, std::string &rText)
Read verbatim text.
bool Reset(int level=-1)
Reset to the begining of the specified level of section nesting.
Mode mMode
input mode
int Level(void) const
Return current level of section nesting.
void ReadEnd(const std::string &rLabel)
Close the current section by matching the previous ReadBegin().
double ReadFloat(void)
Read float token.
bool Recover(int level)
Recover by skipping tokens until returning to the specified level of section nesting.
std::string ReadString(void)
Read string token.
void Rewind(void)
Rewind stream.
std::istringstream * mpSStream
actual stream object on heap, string input
void ReadSection(std::string &rSectionString)
Read XML section.
void ReadBegin(const std::string &rLabel)
Open a section by specified label.
std::istream * mpStream
istream object pointer
int mLineCount
Line counter.
std::ifstream mFStream
actual stream object, file input
bool Get(Token &token)
Get next token.
bool Peek(Token &token)
Peek next token.
std::istream * Streamp(void)
Access C++ stream.
int Line(void) const
Return number of lines read.
int mLevel
Level (of nested sections)
bool ExistsBegin(const std::string &rLabel)
Search for specified element.
std::string mFileName
Filename.
TokenReader(Mode mode, const std::string &rInString="")
TokenReader constructor.
std::string FileName(void) const
Access the filename.
~TokenReader(void)
Destruct.
std::vector< LState > mLevelState
long int mFilePos
file position
A TokenWriter writes sequential tokens to a file, a string or stdout.
std::string Str(void)
Retrieve output as string (if in String mode)
void WriteCharacterData(const std::string &rCharData)
Write character data.
void Write(Token &rToken)
Write next token.
void Endl(void)
Write endl separator.
Tokens model atomic data for stream IO.
Definition: cfl_token.h:53
bool IsCdata(void) const
Test token Type.
Definition: cfl_token.cpp:253
bool IsBinary(void) const
Test token Type.
Definition: cfl_token.cpp:248
void SetNone(void)
Initialize None token.
Definition: cfl_token.cpp:72
const std::string & PreceedingSpace(void) const
Preceeding space when writing to stream.
Definition: cfl_token.cpp:188
std::string Str(void) const
Pretty print string representation.
Definition: cfl_token.cpp:1296
const std::string & StringValue(void) const
Get string value of a name token.
Definition: cfl_token.cpp:177
void ClrEnd(void)
Clear End type (resolve empty section)
Definition: cfl_token.cpp:160
@ End
<\label> (end of section)
Definition: cfl_token.h:84
bool IsString(void) const
Test token Type.
Definition: cfl_token.cpp:243
Int IntegerValue(void) const
Get integer value of a numeric token.
Definition: cfl_token.cpp:166
bool IsNone(void) const
Test token Type.
Definition: cfl_token.cpp:213
bool IsInteger(void) const
Test token Type.
Definition: cfl_token.cpp:218
static int ReadCharacterData(std::istream *pStream, std::string &rString, bool fcomments)
Read chracter data from an input file stream.
Definition: cfl_token.cpp:918
static int ReadEscapedString(std::istream *pStream, char stop, std::string &rString)
Read a std::string value from an input file stream.
Definition: cfl_token.cpp:857
bool IsEmpty(void) const
Test token Type.
Definition: cfl_token.cpp:280
bool IsBegin(void) const
Test token Type.
Definition: cfl_token.cpp:258
const std::string & OptionValue(void) const
Get option value of a name token.
Definition: cfl_token.cpp:183
int Read(std::istream *pStream, bool fcomments=true)
Read Token from input stream.
Definition: cfl_token.cpp:1205
bool IsEnd(void) const
Test token Type.
Definition: cfl_token.cpp:269
bool IsFloat(void) const
Test token Type.
Definition: cfl_token.cpp:233
bool IsOption(void) const
Test token Type.
Definition: cfl_token.cpp:238
void SetEnd(const std::string &rName)
Initialize as End token.
Definition: cfl_token.cpp:98
faudes::Float FloatValue(void) const
Get float value of a numeric token.
Definition: cfl_token.cpp:172
TokenType Type(void) const
Get token Type.
Definition: cfl_token.cpp:198
libFAUDES resides within the namespace faudes.
std::string ToStringInteger(Int number)
integer to string
Definition: cfl_helper.cpp:43

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen