#include <stringparser.h>
Inheritance diagram for StringParser

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 arglist& | parse (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... | |
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.
|
|
Type for the result of parsing a string into a list of strings.
Definition at line 59 of file stringparser.h. |
|
|
Iterator for an arglist.
Definition at line 61 of file stringparser.h. |
|
|
Shorter alias for arglist_iterator.
Definition at line 63 of file stringparser.h. |
|
|
Definition at line 55 of file stringparser.h. |
|
|
Definition at line 56 of file stringparser.h. |
|
|
Copy constructor.
Definition at line 65 of file stringparser.h. Referenced by clone(). |
|
|
Return a duplicate of the current object.
Reimplemented in CmdParamStringParser. Definition at line 68 of file stringparser.h. |
|
|
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(). |
|
|
Short version of parse() for simple string substitution.
Reimplemented in CmdParamStringParser. Definition at line 91 of file stringparser.h. |
|
|
Parse into a vector of strings by breaking at word boundaries.
Reimplemented in CmdParamStringParser. Definition at line 81 of file stringparser.h. |
|
|
Parse into a pointer to a double.
Reimplemented in CmdParamStringParser. Definition at line 79 of file stringparser.h. |
|
|
Parse into a string.
Reimplemented in CmdParamStringParser. Definition at line 77 of file stringparser.h. |
|
|
Parse into an int.
Reimplemented in CmdParamStringParser. Definition at line 75 of file stringparser.h. |
|
|
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(). |
1.2.1 written by Dimitri van Heesch,
© 1997-2000