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

ExprParser< T > Class Template Reference

#include <exprparser.h>

Inheritance diagram for ExprParser< T >:

Inheritance graph
[legend]
Collaboration diagram for ExprParser< T >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<class T = int>
class ExprParser< T >

Basic C-like expression parsing.

This parser works reasonably well, but it is not at all robust or well-written. In particular, the string handling is almost all based on old C code, which is much more complicated than the equivalent code using a C++ string class would be. Rather than being improved incrementally, it should probably be reimplemented using lex/yacc or just replaced altogether with a real interpreter, e.g. for Scheme.

In any case, this interface is for interfacing to legacy code; new code should use the ParamStringParser interface if possible.

At present, the template argument is just a dummy to allow the full definition to be included in the header file, but in future, the numeric expression type might be a good one to actually use as the templated type.

Definition at line 39 of file exprparser.h.

Public Types

typedef long double exprtype
 Unified return type for numeric expressions.


Public Methods

 ExprParser (const char *expr, Msg::LevelHandler<> **mhp_i=&(Msg::LevelHandler<>::default_instance()))
 Constructor.

bool consumeifpresent (string s)
 If the given string is the next thing on the remaining chars, consume it and return true; otherwise do nothing.

string whatsleft ()
bool empty () const
 Returns true if no further characters remain.

exprtype getnumericval ()
 Same as getval but works only with numeric types, and always converts them to "exprtype" (long double, if avail, or double, if not) so they can be returned cleanly.

Parsing for specific datatypes
double cmdf ()
 Public routine to read an expression of type double.

long cmdi ()
 Integer equivalent of cmdf.

const char * cmds ()
 Public routine to read an expression of string type.


Static Public Methods

void message (Msg::MessageLevel m, const string &s)

Protected Methods

virtual const Typelessgetval ()
 Parses the given string to find the value of the first scalar item found (i.e., not an expression).


Protected Attributes

const char * remaining


Constructor & Destructor Documentation

template<class T = int>
ExprParser< T >::ExprParser const char *    expr,
Msg::LevelHandler<> **    mhp_i = &(Msg::LevelHandler<>::default_instance())
[inline]
 

Constructor.

Takes an expression and an optional handler for various sorts of messages.

Definition at line 43 of file exprparser.h.


Member Function Documentation

template<class T = int>
long ExprParser< T >::cmdi   [inline]
 

Integer equivalent of cmdf.

Returns type long but warns if can't fit in int.

Definition at line 55 of file exprparser.h.

template<class T = int>
bool ExprParser< T >::consumeifpresent string    s [inline]
 

If the given string is the next thing on the remaining chars, consume it and return true; otherwise do nothing.

Useful for testing for e.g. a keyword or special character.

Definition at line 73 of file exprparser.h.

template<class T>
const Typeless & ExprParser< T >::getval   [protected, virtual]
 

Parses the given string to find the value of the first scalar item found (i.e., not an expression).

This implementation assumes that the scalar is a literal numeric value representable in type double. Derived classes may implement return of other types via the Typeless wrapper.

Definition at line 127 of file exprparser.h.

Referenced by ExprParser< T >::getnumericval().


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