Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

StringParser Class Reference

This class provides a basic way for values of various types to be specified in a string. More...

#include <stringparser.h>

Inheritance diagram for StringParser

Inheritance graph

[legend]
List of all members.

Public Types

typedef std::vector<string> arglist
 Type for the result of parsing a string into a list of strings. More...

typedef std::vector<stringiterator arglist_iterator
 Iterator for an arglist. More...

typedef std::vector<stringiterator argptr
 Shorter alias for arglist_iterator. More...


Public Methods

 StringParser ()
virtual ~StringParser ()
 StringParser (const StringParser&)
 Copy constructor. More...

virtual StringParser* clone () const
 Return a duplicate of the current object. More...

virtual double& parse (const string& s, double& x) const
 Parse into a double. More...

virtual int& parse (const string& s, int& x) const
 Parse into an int. More...

virtual string& parse (const string& s, string& x) const
 Parse into a string. More...

virtual double*& parse (const string& s, double*& x) const
 Parse into a pointer to a double. More...

virtual arglistparse (const string& s, arglist& x) const
 Parse into a vector of strings by breaking at word boundaries. More...

virtual string parse (const string& s) const
 Short version of parse() for simple string substitution. More...

virtual void error (const string&) const
 This implementation ignores errors (since it doesn't generate any), but derived classes may redefine this function if they wish (for instance, to write messages to the console). More...


Detailed Description

This class provides a basic way for values of various types to be specified in a string.

As implemented, it supports only the basic reading of integers and doubles as numeric constants, copies strings verbatim, ignores pointers, and breaks lines into words without taking quotes, comments, etc. into account.

The pointer version of parsing for a datatype [parse(s,T*&x)] has the same semantics as the regular version, except that it is possible that the pointer itself might be changed by the expression. (This implementation does not have any way to actually specify a pointer in a string, but derived classes can provide a mechanism for that.) The supplied pointer must already be valid, since any regular value found will be placed into the pointee. Any client that would like to support such pointer expressions should use the pointer form instead of the regular form (i.e. double* instead of double).

For convenience in expressions, the parsed value is returned in both the return type and in the supplied variable. (Of course, the variable is required to be in the argument list so that the correct return type can be deduced.)

Often this class will be overridden with a more capable class, which can e.g. accept expressions from which the actual value may be computed based on known values of variables, implement quoting, etc. Derived classes may raise exceptions or print error messages during the parsing, but they must always return a legal value of the indicated type.

Unfortunately, C++ does not implement virtual templates, or else the basicparse() routine could have just been called parse() and some of the others eliminated. Had that been done, however, no derived class could override the operations since they would not have been virtual. So, alas, the types must be limited to those enumerated here.

Definition at line 53 of file stringparser.h.


Member Typedef Documentation

typedef std::vector<string> StringParser::arglist
 

Type for the result of parsing a string into a list of strings.

Definition at line 59 of file stringparser.h.

typedef std::vector<string>::iterator StringParser::arglist_iterator
 

Iterator for an arglist.

Definition at line 61 of file stringparser.h.

typedef std::vector<string>::iterator StringParser::argptr
 

Shorter alias for arglist_iterator.

Definition at line 63 of file stringparser.h.


Constructor & Destructor Documentation

StringParser::StringParser ( ) [inline]
 

Definition at line 55 of file stringparser.h.

StringParser::~StringParser ( ) [inline, virtual]
 

Definition at line 56 of file stringparser.h.

StringParser::StringParser ( const StringParser & ) [inline]
 

Copy constructor.

Definition at line 65 of file stringparser.h.

Referenced by clone().


Member Function Documentation

StringParser * StringParser::clone ( ) const [inline, virtual]
 

Return a duplicate of the current object.

Reimplemented in CmdParamStringParser.

Definition at line 68 of file stringparser.h.

void StringParser::error ( const string & s ) const [inline, virtual]
 

This implementation ignores errors (since it doesn't generate any), but derived classes may redefine this function if they wish (for instance, to write messages to the console).

Reimplemented in CmdParamStringParser.

Definition at line 96 of file stringparser.h.

Referenced by RetinalObjectStringArgs::error().

string StringParser::parse ( const string & s ) const [inline, virtual]
 

Short version of parse() for simple string substitution.

Reimplemented in CmdParamStringParser.

Definition at line 91 of file stringparser.h.

arglist & StringParser::parse ( const string & s,
arglist & x ) const [inline, virtual]
 

Parse into a vector of strings by breaking at word boundaries.

Reimplemented in CmdParamStringParser.

Definition at line 81 of file stringparser.h.

double *& StringParser::parse ( const string & s,
double *& x ) const [inline, virtual]
 

Parse into a pointer to a double.

Reimplemented in CmdParamStringParser.

Definition at line 79 of file stringparser.h.

string & StringParser::parse ( const string & s,
string & x ) const [inline, virtual]
 

Parse into a string.

Reimplemented in CmdParamStringParser.

Definition at line 77 of file stringparser.h.

int & StringParser::parse ( const string & s,
int & x ) const [inline, virtual]
 

Parse into an int.

Reimplemented in CmdParamStringParser.

Definition at line 75 of file stringparser.h.

double & StringParser::parse ( const string & s,
double & x ) const [inline, virtual]
 

Parse into a double.

Reimplemented in CmdParamStringParser.

Definition at line 73 of file stringparser.h.

Referenced by cmddefs_exec_file(), StringArgs::lookaheadone(), ValueGenerator_Expression::next(), StringArgs::next(), StringArgs::nextis(), String::numeric_extension(), parse(), RetinalObjectStringArgs::parse(), CmdParamStringParser::parse(), RetinalObjectStringArgs::parsed_get_default(), RetinalObjectStringArgs::parsed_next(), and pgm_full_pathname().


The documentation for this class was generated from the following file:
Generated at Mon Aug 21 00:31:26 2000 for RF-LISSOM by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000