#include <ParseLine.hh>
Public Member Functions | |
| ParseLine (const char *file) | |
| ParseLine (std::istream &stream) | |
| ~ParseLine (void) | |
| int | getLine (void) |
| const char * | getArg (int i) const |
| int | getCount (void) const |
| double | getDouble (int i) const |
| unsigned long | getHex (int i) const |
| long | getInt (int i) const |
| long | getLineNumber (void) const |
| void | getRange (int i, double &lo, double &hi, char sep='-') const |
| bool | isOpen (void) const |
| const char * | operator[] (int i) const |
| void | setComment (const std::string &st) |
| void | setDefault (void) |
| void | setDelim (const std::string &st) |
| void | setLog (std::ostream &log) |
| void | setParen (const std::string &st) |
| void | setQuote (const std::string &st) |
| void | setEscape (const std::string &st) |
| set the escape character. | |
A line parser is typically used in the following manner:
{verbatim} ParseLine pl("command.file"); while (pl.getLine() >= 0) { std::string arg1 = pl[0]; unsigned int hex_arg = pl.getHex(1); ... } {verbatim}
brief Parse lines from a command file.
| ParseLine::ParseLine | ( | const char * | file | ) |
Construct a line parser on a file. brief Construct a parser
| file | Input file name. |
| ParseLine::ParseLine | ( | std::istream & | stream | ) |
Construct a line parser on a stream. brief Construct a parser
| stream | Input file name. |
| ParseLine::~ParseLine | ( | void | ) |
Destroy a command line parser. brief ParseLine destructor.
| int ParseLine::getLine | ( | void | ) |
Read a line from the file into the internal buffer and parse it into words. getLine() returns the number of words found on the line. A negative number is returned if an error occurred while trying to read the line. brief Read and parse a line.
| const char* ParseLine::getArg | ( | int | i | ) | const |
Get a pointer to the ith word on a line. brief Get pointer to an argument.
| i | Argument number, 0 <= i < count. |
| int ParseLine::getCount | ( | void | ) | const [inline] |
Get the number of words on the last line read in. brief Get word count.
| double ParseLine::getDouble | ( | int | i | ) | const |
Get a double float from the ith word on a line. brief Get the ith word converted to a float number.
| unsigned long ParseLine::getHex | ( | int | i | ) | const |
Get a hex number from the ith word on a line. brief Get a hex argument.
| i | Number of argument to fetch. |
| long ParseLine::getInt | ( | int | i | ) | const |
Get a long integer from the ith word on a line. brief Get an integer argument.
| i | Number of argument to fetch. |
| long ParseLine::getLineNumber | ( | void | ) | const [inline] |
Get the current line number.
| void ParseLine::getRange | ( | int | i, | |
| double & | lo, | |||
| double & | hi, | |||
| char | sep = '-' | |||
| ) | const |
Get a range of values specified as lo-high or lo:hi. The data field is two double precision values separaterd by a single character asspecified by the sep column. By default the separator character is '-'. Some characters e.g. space, numbers will cause problems. The lo and hi variables are left unchanged if the argument number is not valid. The hi variable is left unchanged if the specified separator was not found. brief Get a value range
| i | Number of argument to fetch. | |
| lo | Low value of range | |
| hi | High value of range | |
| sep | Separation character. |
| bool ParseLine::isOpen | ( | void | ) | const [inline] |
Test that the file is open. brief Test if file is open.
| const char * ParseLine::operator[] | ( | int | i | ) | const [inline] |
Get a pointer to the ith argument string from the current line. brief Get an argument pointer.
| i | Index (in the range 0 -> N-1) of the requested argument. |
| void ParseLine::setComment | ( | const std::string & | st | ) |
Set comment characters.
| void ParseLine::setDefault | ( | void | ) |
Set the character translation table to its default values.
| void ParseLine::setDelim | ( | const std::string & | st | ) |
Set the delimiter charaters. By default, space and tab are delimeters.
| void ParseLine::setLog | ( | std::ostream & | log | ) |
Specify a log file to receive a transcription of the lines read from the command file. brief Specify a log file
| log | stream to receive a transcription of the input file. |
| void ParseLine::setParen | ( | const std::string & | st | ) |
Set parenthesis charaters. Parentheses are netstable quote characters. Parentheses are specified in open / close parentheses pairs. By default, the "()" characters are parentheses.
| void ParseLine::setQuote | ( | const std::string & | st | ) |
Set quote characters. All charaters inside a quoted string are ignored, including delimiters, parentheses and other kinds of quotes.
| void ParseLine::setEscape | ( | const std::string & | st | ) |
set the escape character.
Set the escape character. By default the escape character is '\'.
1.5.4