#include <tokenreader.h>
It can get or peek the next token and it will track line numbers for informative diagnosis output.
The class also implements nested sections. That is, you may search for a (sub-)section within the current section and, hence, implement file formats that do not insist in a particular ordering of the sections (e.g. a Generator consists of states, transitions and events, no matter in which order).
Convenience functions are provided to read a token of a particular type and throws faudes::Exception on token mismatch. You may catch the exception as follows:
try { some tokenreader operations } catch (faudes::Exception& ex) { cerr << "Error reading file (details: " << ex.What() << ")" << endl; }
Definition at line 59 of file tokenreader.h.
Public Types | |
enum | Mode { File, Stdin, String } |
Mode of operation: read from file, stdin or string. More... | |
Public Member Functions | |
TokenReader (Mode mode, const std::string &rInString="") | |
TokenReader constructor. | |
TokenReader (const std::string &rFilename) | |
Creates a TokenReader for reading complete file. | |
~TokenReader (void) | |
Destruct. | |
bool | good (void) const |
Get state of TokenReader stream. | |
std::string | FileName (void) const |
Get the filename. | |
bool | Peek (Token &token) |
Peek next token. | |
bool | Get (Token &token) |
Get next token. | |
void | Rewind (void) |
Rewind stream (must be a seekable stream). | |
void | ReadBegin (const std::string &rLabel) |
Open a section by specified label. | |
void | ReadEnd (const std::string &rLabel) |
Close the current section by matching the previous ReadBegin(). | |
void | SeekBegin (const std::string &rLabel) |
Open a section by specified label. | |
void | SeekEnd (const std::string &rLabel) |
Close the current section by matching the previous SeekBegin(). | |
bool | Eos (const std::string &rLabel) |
Peek a token and check whether it ends the specified section. | |
long int | ReadInteger (void) |
Read integer token. | |
double | ReadFloat (void) |
Read float token. | |
const std::string & | ReadString (void) |
Read string token. | |
const std::string & | ReadOption (void) |
Read option token. | |
bool | operator>> (Token &token) |
Operator for get. | |
int | Line (void) const |
Return number of lines read. | |
std::string | FileLine (void) const |
Return "filename:line". | |
Private Attributes | |
Mode | mMode |
input mode | |
std::istream * | mpStream |
istream object pointer | |
std::ifstream | mFStream |
actual stream object, file input | |
std::istringstream * | mpSStream |
actual stream object on heap, string input | |
std::string | mFileName |
Filename. | |
int | mLineCount |
Line counter. | |
long int | mFilePos |
file position | |
int | mLevel |
Level (of nested sections). | |
std::vector< long int > | mLevelPos |
file positions of sections | |
std::vector< long int > | mLevelLine |
file line of sections | |
std::vector< int > | mSeekLevel |
level of recent seek | |
std::string | mLastString |
recent string buffer | |
bool | mHasPeekToken |
validity of peek buffer | |
Token | mPeekToken |
peek buffer |
|
Mode of operation: read from file, stdin or string.
Definition at line 65 of file tokenreader.h. |
|
TokenReader constructor.
Definition at line 31 of file tokenreader.cpp. |
|
Creates a TokenReader for reading complete file.
Definition at line 66 of file tokenreader.cpp. |
|
Destruct.
Definition at line 87 of file tokenreader.cpp. |
|
Peek a token and check whether it ends the specified section. This function is meant for scanning a section with a while- construct.
Definition at line 311 of file tokenreader.cpp. |
|
Return "filename:line".
Definition at line 386 of file tokenreader.cpp. |
|
Get the filename.
Definition at line 116 of file tokenreader.cpp. |
|
Get next token. False indicates eof.
Definition at line 143 of file tokenreader.cpp. |
|
Get state of TokenReader stream.
|
|
Return number of lines read.
Definition at line 381 of file tokenreader.cpp. |
|
Operator for get.
Definition at line 278 of file tokenreader.h. |
|
Peek next token. False indicates eof.
Definition at line 121 of file tokenreader.cpp. |
|
Open a section by specified label. This function searches for the section on this level, it skips any sections on levels below this level, and it will wrap to the begin of the current section. In the case of success, the matching begin token is the last token read. After processing the section, a matching ReadEnd(label) must be called.
Definition at line 236 of file tokenreader.cpp. |
|
Close the current section by matching the previous ReadBegin(). Reads all tokens up to and including end of current section.
Definition at line 285 of file tokenreader.cpp. |
|
Read float token.
Definition at line 339 of file tokenreader.cpp. |
|
Read integer token.
Definition at line 327 of file tokenreader.cpp. |
|
Read option token.
Definition at line 365 of file tokenreader.cpp. |
|
Read string token.
Definition at line 351 of file tokenreader.cpp. |
|
Rewind stream (must be a seekable stream).
Definition at line 92 of file tokenreader.cpp. |
|
Open a section by specified label. This function searches for the section on this level and any descending level. However, this funtion will not rewind to the beginning of the current section (this may change in a future revision). In the case of success, the matching begin token is the last token read. After processing the section, a matching SeekEnd(label) must be called.
Definition at line 172 of file tokenreader.cpp. |
|
Close the current section by matching the previous SeekBegin(). Reads all tokens up to the level when SeekBegin() was called.
Definition at line 208 of file tokenreader.cpp. |
|
Filename.
Definition at line 309 of file tokenreader.h. |
|
file position
Definition at line 315 of file tokenreader.h. |
|
actual stream object, file input
Definition at line 303 of file tokenreader.h. |
|
validity of peek buffer
Definition at line 333 of file tokenreader.h. |
|
recent string buffer
Definition at line 330 of file tokenreader.h. |
|
Level (of nested sections).
Definition at line 318 of file tokenreader.h. |
|
file line of sections
Definition at line 324 of file tokenreader.h. |
|
file positions of sections
Definition at line 321 of file tokenreader.h. |
|
Line counter.
Definition at line 312 of file tokenreader.h. |
|
input mode
Definition at line 297 of file tokenreader.h. |
|
peek buffer
Definition at line 336 of file tokenreader.h. |
|
actual stream object on heap, string input
Definition at line 306 of file tokenreader.h. |
|
istream object pointer
Definition at line 300 of file tokenreader.h. |
|
level of recent seek
Definition at line 327 of file tokenreader.h. |