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

StringParser Class Reference

#include <stringparser.h>

Inheritance diagram for StringParser:

Inheritance graph
[legend]
List of all members.

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 55 of file stringparser.h.

Public Types

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

typedef std::vector< string
>::iterator 
arglist_iterator
 Iterator for an arglist.

typedef std::vector< string
>::iterator 
argptr
 Shorter alias for arglist_iterator.

typedef std::vector< string
>::const_iterator 
const_argptr

Public Methods

 StringParser (const StringParser &)
 Copy constructor.

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

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

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

Family of parse functions differing only by their return datatypes
virtual double & parse (const string &s, double &x) const
 Parse into a double.

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

virtual Tristateparse (const string &s, Tristate &x) const
 Parse into a Tristate.

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

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

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

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

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

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


The documentation for this class was generated from the following file:
Generated on Mon Jan 20 02:37:25 2003 for RF-LISSOM by doxygen1.3-rc2