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());
163 if(!res)
return false;
165 if(token.
IsBegin(
"br") || token.
IsEnd(
"br"))
return true;
185 #ifdef FAUDES_CHECKED
191 #ifdef FAUDES_CHECKED
201 FD_DV(
"TokenReader:Get(): " << token.
Str());
215 FD_DV(
"TokenReader::SeekBegin: " << rLabel <<
" at " <<
FileLine() <<
" level " <<
mLevel);
224 std::stringstream errstr;
225 errstr <<
"Section \"" << rLabel <<
"\" expected at " <<
FileLine() <<
" no more tokens";
226 throw Exception(
"TokenReader::SeekBegin", errstr.str(), 51);
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);
256 FD_DV(
"Looking for Section \"" << rLabel <<
"\"");
261 FD_DV(
"section level " << level <<
" current pos " << startpos <<
" begin of section " <<
mLevelState[level].mStartPosition);
269 std::stringstream errstr;
270 errstr <<
"Section \"" << rLabel <<
"\" expected at " <<
FileLine() <<
", no token at all";
271 throw Exception(
"TokenReader::ReadBegin Peek", errstr.str(), 51);
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);
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);
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);
315 FD_DV(
"TokenReader::ExistsBegin(): looking for Section \"" << rLabel <<
"\"");
320 FD_DV(
"section level " << level <<
" current pos " << startpos <<
" begin of section " <<
mLevelState[level].mStartPosition);
336 if(token.
IsEnd() && (
mLevel == level) && (rwcnt==0)) {
343 if(rwcnt>1)
return false;
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);
365 FD_DV(
"TokenReader::ReadEnd: " << rLabel <<
" at " <<
FileLine() );
375 std::stringstream errstr;
376 errstr <<
"end of section \"" << rLabel <<
"\" expected at " <<
FileLine();
377 throw Exception(
"TokenReader::ReadEnd", errstr.str(), 51);
386 std::stringstream errstr;
387 errstr <<
"end of Section \"" << rLabel <<
"\" expected at " <<
FileLine();
388 throw Exception(
"TokenReader::ReadEnd", errstr.str(), 51);
399 if(level<0)
return false;
401 if(level>
mLevel)
return false;
402 if(level==
mLevel)
return true;
414 if(level>
mLevel)
return false;
426 if(
mLevel<level)
return false;
447 std::stringstream errstr;
448 errstr <<
"section end \"" << rLabel <<
"\" expected at " <<
FileLine();
449 throw Exception(
"TokenReader::Eos", errstr.str(), 51);
459 std::stringstream errstr;
460 errstr <<
"Integer expected at " <<
FileLine();
461 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
472 std::stringstream errstr;
473 errstr <<
"Float expected at " <<
FileLine();
474 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
485 std::stringstream errstr;
486 errstr <<
"String expected at " <<
FileLine();
487 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
499 std::stringstream errstr;
500 errstr <<
"Option expected at " <<
FileLine();
501 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
512 std::stringstream errstr;
513 errstr <<
"Binary string expected at " <<
FileLine();
514 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
527 std::stringstream errstr;
528 errstr <<
"Text element \""<< rLabel <<
"\" expected at " <<
FileLine();
529 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
535 std::stringstream errstr;
536 errstr <<
"Text expected at " <<
FileLine();
537 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
541 static const std::string line=
"\n\r\v";
542 std::size_t pos1=rText.find_first_not_of(line);
543 if(pos1!=std::string::npos)
544 rText=rText.substr(pos1);
547 std::size_t pos2=rText.find_last_not_of(line);
548 if(pos2!=std::string::npos)
551 static const std::string white=
" \t";
553 pos1=rText.find_first_not_of(white);
554 if(pos1!=std::string::npos)
555 rText=rText.substr(pos1);
558 std::size_t pos2=rText.find_last_not_of(white);
559 if(pos2!=std::string::npos)
564 if(!token.
IsEnd(rLabel)) {
565 std::stringstream errstr;
566 errstr <<
"End of text element \""<< rLabel <<
"\" expected at " <<
FileLine();
567 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
578 std::stringstream errstr;
579 errstr <<
"Verbatim element \""<< rLabel <<
"\" expected at " <<
FileLine();
580 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
589 if(cnt>0 && !token.
IsCdata())
break;
595 static const std::string line=
"\n\r\v";
596 std::size_t pos1=rString.find_first_not_of(line);
597 if(pos1!=std::string::npos)
598 rString=rString.substr(pos1);
601 std::size_t pos2=rString.find_last_not_of(line);
602 if(pos2!=std::string::npos)
603 rString.erase(pos2+1);
606 if(!token.
IsEnd(rLabel)) {
607 std::stringstream errstr;
608 errstr <<
"End of verbatim element \""<< rLabel <<
"\" expected at " <<
FileLine();
609 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
618 FD_DV(
"TokenReader::ReadCharacterData(): tag in buffer");
626 std::stringstream errstr;
627 errstr <<
"Missformed character data at " <<
FileLine() <<
": " << rData;
628 throw Exception(
"TokenReader::TokenReader", errstr.str(), 50);
641 int clevel =
Level();
653 if(!
Peek(token))
break;
662 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)