class ParseLine

Parse lines from a command file.

Public Methods

ParseLine(const char* file)
Construct a parser
~ParseLine(void)
ParseLine destructor.
int getLine(void)
Read and parse a line.
const char* getArg(int i) const
Get pointer to an argument.
int getCount(void) const
Get word count.
double getDouble(int i) const
Get the ith word converted to a float number.
unsigned long getHex(int i) const
Get a hex argument.
long getInt(int i) const
Get an integer argument.
bool isOpen(void) const
Test if file is open.
const char* operator[](int i) const
Get an argument pointer.
void setLog(std::ostream& log)
Specify a log file

Documentation

Class ParseLine reads a file and splits up each line into words delimited by one or more blank space characters or by quotes. Lines may be continued in the file using a backslash resulting in up to 1024 character command lines. Words from the command line can be accessed using the getArg() or operator[] methods. The words may also be converted to numeric values with getDouble(), getHex() or getInt().

A line parser is typically used in the following manner:

     ParseLine pl("command.file");
     while (pl.getLine() >= 0) {
        std::string arg1 = pl[0];
	unsigned int hex_arg = pl.getHex(1);
        ...
     }

ParseLine(const char* file)
Construct a line parser on a file.
Parameters:
file - Input file name.

~ParseLine(void)
Destroy a command line parser.

int 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.
Returns:
Number of words on line.

const char* getArg(int i) const
Get a pointer to the ith word on a line.
Returns:
Constant pointer to the specified argument string.
Parameters:
i - Argument number, 0 <= i < count.

int getCount(void) const
Get the number of words on the last line read in.
Returns:
The number of words read in.

double getDouble(int i) const
Get a double float from the ith word on a line.
Returns:
The value of the ith word.

unsigned long getHex(int i) const
Get a hex number from the ith word on a line.
Returns:
Integer argument value
Parameters:
i - Number of argument to fetch.

long getInt(int i) const
Get a long integer from the ith word on a line.
Returns:
Integer argument value
Parameters:
i - Number of argument to fetch.

bool isOpen(void) const
Test that the file is open.
Returns:
true if file is open and ready to be read.

const char* operator[](int i) const
Get a pointer to the ith argument string from the current line.
Returns:
A pointer to the specified argument string.
Parameters:
i - Index (in the range 0 -> N-1) of the requested argument.

void setLog(std::ostream& log)
Specify a log file to receive a transcription of the lines read from the command file.
Parameters:
log - stream to receive a transcription of the input file.


This class has no child classes.
Author:
J. Zweizig
Version:
1.2; modified January 26, 2001

alphabetic index hierarchy of classes


generated by doc++