33 : mMode(mode), mpStream(NULL), mFileName(
"")
38 FD_DV(
"TokenReader::Tokenreader(String, ...): " << rInString);
39 mpSStream=
new std::istringstream(rInString, std::istringstream::in | std::istringstream::binary);
45 FD_DV(
"TokenReader::Tokenreader(File, \"" << rInString <<
"\")");
46 mFStream.exceptions(std::ios::badbit|std::ios::failbit);
48 mFStream.open(rInString.c_str(), std::ios::in | std::ios::binary);
50 catch (std::ios::failure&) {
51 std::stringstream errstr;
52 errstr <<
"Exception opening/reading file \""<< rInString <<
"\"";
53 throw Exception(
"TokenReader::TokenReader", errstr.str(), 1);
60 std::stringstream errstr;
61 errstr <<
"Invalid Mode / Not implemented";
62 throw Exception(
"TokenReader::TokenReader(mode,instring)", errstr.str(), 1);
69 : mMode(File), mpStream(NULL), mFileName(rFilename)
72 FD_DV(
"TokenReader::Tokenreader(File, \"" << rFilename <<
"\")");
73 mFStream.exceptions(std::ios::badbit|std::ios::failbit);
75 mFStream.open(rFilename.c_str(), std::ios::in | std::ios::binary);
77 catch (std::ios::failure&) {
78 std::stringstream errstr;
79 errstr <<
"Exception opening/reading file \""<< rFilename <<
"\"";
80 throw Exception(
"TokenReader::TokenReader", errstr.str(), 1);
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);
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);
146 FD_DV(
"TokenReader: Peek: " << token.
Str());
154 if(!
Peek(token))
return false;
166 if(token.
IsBegin(
"br") || token.
IsEnd(
"br"))
return true;
186 #ifdef FAUDES_CHECKED
192 #ifdef FAUDES_CHECKED
202 FD_DV(
"TokenReader:Get(): " << token.
Str());
216 FD_DV(
"TokenReader::SeekBegin: " << rLabel <<
" at " <<
FileLine() <<
" level " <<
mLevel);
225 std::stringstream errstr;
226 errstr <<
"Section \"" << rLabel <<
"\" expected at " <<
FileLine() <<
" no more tokens";
227 throw Exception(
"TokenReader::SeekBegin", errstr.str(), 51);
236 std::stringstream errstr;
237 errstr <<
"Section \"" << rLabel <<
"\" expected at " <<
FileLine()
238 <<
"current section ended unexpected. Found: " << rToken.
StringValue() <<
" Type " << rToken.
Type();
239 throw Exception(
"TokenReader::SeekBegin", errstr.str(), 51);
257 FD_DV(
"Looking for Section \"" << rLabel <<
"\"");
262 FD_DV(
"section level " << level <<
" current pos " << startpos <<
" begin of section " <<
mLevelState[level].mStartPosition);
270 std::stringstream errstr;
271 errstr <<
"Section \"" << rLabel <<
"\" expected at " <<
FileLine() <<
", no token at all";
272 throw Exception(
"TokenReader::ReadBegin Peek", errstr.str(), 51);
280 if((
mFilePos>=startpos) && (repcnt==1)) {
281 std::stringstream errstr;
282 errstr <<
"Section \"" << rLabel <<
"\" expected at " <<
FileLine() <<
", did not find begin label";
283 throw Exception(
"TokenReader::ReadBegin: Missing", errstr.str(), 51);
287 std::stringstream errstr;
288 errstr <<
"Section \"" << rLabel <<
"\" expected at " <<
FileLine() <<
", did not find begin label";
289 throw Exception(
"TokenReader::ReadBegin: Missing", errstr.str(), 51);
306 catch (std::ios::failure&) {
307 std::stringstream errstr;
308 errstr <<
"Section \"" << rLabel <<
"\" expected at " <<
FileLine();
309 throw Exception(
"TokenReader::ReadBegin Rewind", errstr.str(), 1);
316 FD_DV(
"TokenReader::ExistsBegin(): looking for Section \"" << rLabel <<
"\"");
321 FD_DV(
"section level " << level <<
" current pos " << startpos <<
" begin of section " <<
mLevelState[level].mStartPosition);
337 if(token.
IsEnd() && (
mLevel == level) && (rwcnt==0)) {
344 if(rwcnt>1)
return false;
356 catch (std::ios::failure&) {
357 std::stringstream errstr;
358 errstr <<
"IO Error while scanning Section \"" << rLabel <<
"\" at " <<
FileLine();
359 throw Exception(
"TokenReader::ExistsBegin IO", errstr.str(), 1);
366 FD_DV(
"TokenReader::ReadEnd: " << rLabel <<
" at " <<
FileLine() );
376 std::stringstream errstr;
377 errstr <<
"end of section \"" << rLabel <<
"\" expected at " <<
FileLine();
378 throw Exception(
"TokenReader::ReadEnd", errstr.str(), 51);
387 std::stringstream errstr;
388 errstr <<
"end of Section \"" << rLabel <<
"\" expected at " <<
FileLine();
389 throw Exception(
"TokenReader::ReadEnd", errstr.str(), 51);
400 if(level<0)
return false;
402 if(level>
mLevel)
return false;
403 if(level==
mLevel)
return true;
415 if(level>
mLevel)
return false;
427 if(
mLevel<level)
return false;
444 if(token.
IsEnd(rLabel))
return true;
454 std::stringstream errstr;
455 errstr <<
"Integer expected at " <<
FileLine();
456 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
467 std::stringstream errstr;
468 errstr <<
"Float expected at " <<
FileLine();
469 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
480 std::stringstream errstr;
481 errstr <<
"String expected at " <<
FileLine();
482 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
494 std::stringstream errstr;
495 errstr <<
"Option expected at " <<
FileLine();
496 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
507 std::stringstream errstr;
508 errstr <<
"Binary string expected at " <<
FileLine();
509 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
522 std::stringstream errstr;
523 errstr <<
"Text element \""<< rLabel <<
"\" expected at " <<
FileLine();
524 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
530 std::stringstream errstr;
531 errstr <<
"Text expected at " <<
FileLine();
532 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
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);
542 std::size_t pos2=rText.find_last_not_of(line);
543 if(pos2!=std::string::npos)
546 static const std::string white=
" \t";
548 pos1=rText.find_first_not_of(white);
549 if(pos1!=std::string::npos)
550 rText=rText.substr(pos1);
553 std::size_t pos2=rText.find_last_not_of(white);
554 if(pos2!=std::string::npos)
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);
573 std::stringstream errstr;
574 errstr <<
"Verbatim element \""<< rLabel <<
"\" expected at " <<
FileLine();
575 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
584 if(cnt>0 && !token.
IsCdata())
break;
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);
596 std::size_t pos2=rString.find_last_not_of(line);
597 if(pos2!=std::string::npos)
598 rString.erase(pos2+1);
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);
613 FD_DV(
"TokenReader::ReadCharacterData(): tag in buffer");
621 std::stringstream errstr;
622 errstr <<
"Missformed character data at " <<
FileLine() <<
": " << rData;
623 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
636 int clevel =
Level();
648 if(!
Peek(token))
break;
657 rSectionString=tw.
Str();
long int ReadInteger(void)
std::string FileLine(void) const
void ReadBinary(std::string &rData)
void ReadCharacterData(std::string &rData)
void ReadText(const std::string &rLabel, std::string &rText)
std::string ReadOption(void)
bool Eos(const std::string &rLabel)
void SeekBegin(const std::string &rLabel)
void ReadVerbatim(const std::string &rLabel, std::string &rText)
void ReadEnd(const std::string &rLabel)
std::string ReadString(void)
std::istringstream * mpSStream
void ReadSection(std::string &rSectionString)
void ReadBegin(const std::string &rLabel)
std::istream * Streamp(void)
bool ExistsBegin(const std::string &rLabel)
TokenReader(Mode mode, const std::string &rInString="")
std::string FileName(void) const
std::vector< LState > mLevelState
void WriteCharacterData(const std::string &rCharData)
void Write(Token &rToken)
bool IsBinary(void) const
const std::string & PreceedingSpace(void) const
std::string Str(void) const
const std::string & StringValue(void) const
@ End
<\label> (end of section)
bool IsString(void) const
Int IntegerValue(void) const
bool IsInteger(void) const
static int ReadCharacterData(std::istream *pStream, std::string &rString, bool fcomments)
static int ReadEscapedString(std::istream *pStream, char stop, std::string &rString)
const std::string & OptionValue(void) const
int Read(std::istream *pStream, bool fcomments=true)
bool IsOption(void) const
void SetEnd(const std::string &rName)
faudes::Float FloatValue(void) const
TokenType Type(void) const
std::string ToStringInteger(Int number)