ParseLine Class Reference
[Parse an input line]

#include <ParseLine.hh>

List of all members.

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.


Detailed Description

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:

{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.

Author:
J. Zweizig
Version:
1.3; modified June 30, 2004

Constructor & Destructor Documentation

ParseLine::ParseLine ( const char *  file  ) 

Construct a line parser on a file. brief Construct a parser

Parameters:
file Input file name.

ParseLine::ParseLine ( std::istream &  stream  ) 

Construct a line parser on a stream. brief Construct a parser

Parameters:
stream Input file name.

ParseLine::~ParseLine ( void   ) 

Destroy a command line parser. brief ParseLine destructor.


Member Function Documentation

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.

Returns:
Number of words on line.

const char* ParseLine::getArg ( int  i  )  const

Get a pointer to the ith word on a line. brief Get pointer to an argument.

Parameters:
i Argument number, 0 <= i < count.
Returns:
Constant pointer to the specified argument string.

int ParseLine::getCount ( void   )  const [inline]

Get the number of words on the last line read in. brief Get word count.

Returns:
The number of words read in.

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.

Returns:
The value of the ith word.

unsigned long ParseLine::getHex ( int  i  )  const

Get a hex number from the ith word on a line. brief Get a hex argument.

Parameters:
i Number of argument to fetch.
Returns:
Integer argument value

long ParseLine::getInt ( int  i  )  const

Get a long integer from the ith word on a line. brief Get an integer argument.

Parameters:
i Number of argument to fetch.
Returns:
Integer argument value

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

Parameters:
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.

Returns:
true if file is open and ready to be read.

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.

Returns:
A pointer to the specified argument string.
Parameters:
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

Parameters:
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 '\'.


The documentation for this class was generated from the following file:
Generated on Sun Mar 8 19:21:13 2009 for dmt by  doxygen 1.5.4