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);
90 : mMode(Stream), mpStream(NULL), mFileName(
"anonymous")
92 FD_DV(
"TokenReader::Tokenreader(Stream)");
96 std::stringstream errstr;
97 errstr <<
"Exception opening/reading anonymous stream";
98 throw Exception(
"TokenReader::TokenReader", errstr.str(), 1);
130 catch (std::ios::failure&) {
131 std::stringstream errstr;
132 errstr <<
"Exception opening/reading file in "<<
FileLine();
133 throw Exception(
"TokenReader::Rewind", errstr.str(), 1);
149 }
catch (std::ios::failure&) {
150 std::stringstream errstr;
151 errstr <<
"Exception opening/reading file in "<<
FileLine();
152 throw Exception(
"TokenReader::Peek", errstr.str(), 1);
160 FD_DV(
"TokenReader: Peek: " << token.
Str());
167 if(!
Peek(token))
return false;
179 if(token.
IsBegin(
"br") || token.
IsEnd(
"br"))
return true;
199 #ifdef FAUDES_CHECKED
205 #ifdef FAUDES_CHECKED
215 FD_DV(
"TokenReader:Get(): " << token.
Str());
229 FD_DV(
"TokenReader::SeekBegin: " << rLabel <<
" at " <<
FileLine() <<
" level " <<
mLevel);
238 std::stringstream errstr;
239 errstr <<
"Section \"" << rLabel <<
"\" expected at " <<
FileLine() <<
" no more tokens";
240 throw Exception(
"TokenReader::SeekBegin", errstr.str(), 51);
249 std::stringstream errstr;
250 errstr <<
"Section \"" << rLabel <<
"\" expected at " <<
FileLine()
251 <<
"current section ended unexpected. Found: " << rToken.
StringValue() <<
" Type " << rToken.
Type();
252 throw Exception(
"TokenReader::SeekBegin", errstr.str(), 51);
270 FD_DV(
"Looking for Section \"" << rLabel <<
"\"");
275 FD_DV(
"section level " << level <<
" current pos " << startpos <<
" begin of section " <<
mLevelState[level].mStartPosition);
283 std::stringstream errstr;
284 errstr <<
"Section \"" << rLabel <<
"\" expected at " <<
FileLine() <<
", no token at all";
285 throw Exception(
"TokenReader::ReadBegin Peek", errstr.str(), 51);
293 if((
mFilePos>=startpos) && (repcnt==1)) {
294 std::stringstream errstr;
295 errstr <<
"Section \"" << rLabel <<
"\" expected at " <<
FileLine() <<
", did not find begin label";
296 throw Exception(
"TokenReader::ReadBegin: Missing", errstr.str(), 51);
300 std::stringstream errstr;
301 errstr <<
"Section \"" << rLabel <<
"\" expected at " <<
FileLine() <<
", did not find begin label";
302 throw Exception(
"TokenReader::ReadBegin: Missing", errstr.str(), 51);
319 catch (std::ios::failure&) {
320 std::stringstream errstr;
321 errstr <<
"Section \"" << rLabel <<
"\" expected at " <<
FileLine();
322 throw Exception(
"TokenReader::ReadBegin Rewind", errstr.str(), 1);
329 FD_DV(
"TokenReader::ExistsBegin(): looking for Section \"" << rLabel <<
"\"");
334 FD_DV(
"section level " << level <<
" current pos " << startpos <<
" begin of section " <<
mLevelState[level].mStartPosition);
350 if(token.
IsEnd() && (
mLevel == level) && (rwcnt==0)) {
357 if(rwcnt>1)
return false;
369 catch (std::ios::failure&) {
370 std::stringstream errstr;
371 errstr <<
"IO Error while scanning Section \"" << rLabel <<
"\" at " <<
FileLine();
372 throw Exception(
"TokenReader::ExistsBegin IO", errstr.str(), 1);
379 FD_DV(
"TokenReader::ReadEnd: " << rLabel <<
" at " <<
FileLine() );
389 std::stringstream errstr;
390 errstr <<
"end of section \"" << rLabel <<
"\" expected at " <<
FileLine();
391 throw Exception(
"TokenReader::ReadEnd", errstr.str(), 51);
400 std::stringstream errstr;
401 errstr <<
"end of Section \"" << rLabel <<
"\" expected at " <<
FileLine();
402 throw Exception(
"TokenReader::ReadEnd", errstr.str(), 51);
413 if(level<0)
return false;
415 if(level>
mLevel)
return false;
416 if(level==
mLevel)
return true;
428 if(level>
mLevel)
return false;
440 if(
mLevel<level)
return false;
457 if(token.
IsEnd(rLabel))
return true;
467 std::stringstream errstr;
468 errstr <<
"Integer expected at " <<
FileLine();
469 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
480 std::stringstream errstr;
481 errstr <<
"Float expected at " <<
FileLine();
482 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
493 std::stringstream errstr;
494 errstr <<
"String expected at " <<
FileLine();
495 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
507 std::stringstream errstr;
508 errstr <<
"Option expected at " <<
FileLine();
509 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
520 std::stringstream errstr;
521 errstr <<
"Binary string expected at " <<
FileLine();
522 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
535 std::stringstream errstr;
536 errstr <<
"Text element \""<< rLabel <<
"\" expected at " <<
FileLine();
537 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
543 std::stringstream errstr;
544 errstr <<
"Text expected at " <<
FileLine();
545 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
549 static const std::string line=
"\n\r\v";
550 std::size_t pos1=rText.find_first_not_of(line);
551 if(pos1!=std::string::npos)
552 rText=rText.substr(pos1);
555 std::size_t pos2=rText.find_last_not_of(line);
556 if(pos2!=std::string::npos)
559 static const std::string white=
" \t";
561 pos1=rText.find_first_not_of(white);
562 if(pos1!=std::string::npos)
563 rText=rText.substr(pos1);
566 std::size_t pos2=rText.find_last_not_of(white);
567 if(pos2!=std::string::npos)
572 if(!token.
IsEnd(rLabel)) {
573 std::stringstream errstr;
574 errstr <<
"End of text element \""<< rLabel <<
"\" expected at " <<
FileLine();
575 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
586 std::stringstream errstr;
587 errstr <<
"Verbatim element \""<< rLabel <<
"\" expected at " <<
FileLine();
588 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
597 if(cnt>0 && !token.
IsCdata())
break;
603 static const std::string line=
"\n\r\v";
604 std::size_t pos1=rString.find_first_not_of(line);
605 if(pos1!=std::string::npos)
606 rString=rString.substr(pos1);
609 std::size_t pos2=rString.find_last_not_of(line);
610 if(pos2!=std::string::npos)
611 rString.erase(pos2+1);
614 if(!token.
IsEnd(rLabel)) {
615 std::stringstream errstr;
616 errstr <<
"End of verbatim element \""<< rLabel <<
"\" expected at " <<
FileLine();
617 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
626 FD_DV(
"TokenReader::ReadCharacterData(): tag in buffer");
634 std::stringstream errstr;
635 errstr <<
"Missformed character data at " <<
FileLine() <<
": " << rData;
636 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
649 int clevel =
Level();
661 if(!
Peek(token))
break;
670 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)