NetlistTokenizer is a simple string tokenizer, which usings C strtok () function from. More...
#include <NetlistParser.h>
Public Member Functions | |
NetlistTokenizer (const char *fileName, const char *delim, const char *comments) | |
Constructor. | |
const std::string | nextToken () |
returns the next token from the file | |
bool | hasMoreTokens () const |
Private Member Functions | |
bool | isCommentBegin () const |
char * | getNextLine () |
read next line from the file and return it as a C string | |
char * | readNextToken () |
read next token as a C string | |
Private Attributes | |
std::ifstream | ifs |
correct way to use is to first check if hasMoreTokens and then call nextToken | |
const char * | delim |
what characters mark end of a token | |
const char * | comments |
string representing beginning of a line comment | |
char * | linePtr |
current line read from the file | |
char * | nextTokPtr |
ptr to next token | |
char * | currTokPtr |
ptr to current token, returned on a call to nextToken () |
NetlistTokenizer is a simple string tokenizer, which usings C strtok () function from.
cstring
NetlistTokenizer::NetlistTokenizer | ( | const char * | fileName, | |
const char * | delim, | |||
const char * | comments | |||
) | [inline] |
Constructor.
fileName,: | the file to read from | |
delim,: | a string containing characters that mark end of a token | |
comments,: | a string that contains beginning of a comment |
char* NetlistTokenizer::getNextLine | ( | ) | [inline, private] |
read next line from the file and return it as a C string
bool NetlistTokenizer::hasMoreTokens | ( | ) | const [inline] |
bool NetlistTokenizer::isCommentBegin | ( | ) | const [inline, private] |
const std::string NetlistTokenizer::nextToken | ( | ) | [inline] |
returns the next token from the file
char* NetlistTokenizer::readNextToken | ( | ) | [inline, private] |
read next token as a C string
const char* NetlistTokenizer::comments [private] |
string representing beginning of a line comment
char* NetlistTokenizer::currTokPtr [private] |
ptr to current token, returned on a call to nextToken ()
const char* NetlistTokenizer::delim [private] |
what characters mark end of a token
std::ifstream NetlistTokenizer::ifs [private] |
correct way to use is to first check if hasMoreTokens and then call nextToken
need to read one token ahead so because hasMoreTokens is called before nextToken
basic algorithm
initially currTokPtr = NULL, nextTokPtr = nextTokenInt
In nextToken return string at currTokPtr currTokPtr = nextTokPtr nextTokPtr = read next token
algorithm for reading next token read next token (with NULL) while next token is null or beginning of comment { read next line (break out the loop if file has ended) read first token } create a string and return
things to check for
initialization:
char* NetlistTokenizer::linePtr [private] |
current line read from the file
char* NetlistTokenizer::nextTokPtr [private] |
ptr to next token