ESLA

Embeddable Scriting LAnguage

frantz@pangea.stanford.edu

Stanford University, Rock Fracture Project research group

© 2003

Parser< T > Class Template Reference


Detailed Description

template<class T>
class Parser< T >

Allow evaluation of complex string expressions
Author:
Frantz Maerten
Version:
1.0 BETA TEST for Dustin Lister
Example:

 Parser<double> p;
 string fct = "PI + ln(x+y^2.34)";
 
// all the variables are automatically pre-registered !! p.set_function(fct); p.set_var("x", 2.4538); p.set_var("y", 3.45e-12);
// Evaluate the expression // ----------------------- cout << p.get_function() << " = " << p.evaluate() << endl << "with:" << endl;
// Display every registered variables with there value // --------------------------------------------------- for( Parser<double>::iterator it = p.begin(); it != p.end(); it++ ) { cout << " " << (*it).first << " = " << (*it).second << endl; }

Definition at line 81 of file fct_parser.h.

Public Types

typedef std::map< std::string,
T >::iterator 
iterator

Public Methods

 Parser ()
bool set_function (const std::string &s, bool pre_test=true)
std::string get_function ()
void add_var (const std::string &s, T p=0)
void set_var (const std::string &s, T p)
get_var (const std::string &s) const
evaluate ()
const std::string & get_errors () const
void flush ()
iterator begin ()
iterator end ()


Member Typedef Documentation

template<class T>
typedef std::map<std::string,T>::iterator Parser< T >::iterator
 

Definition at line 83 of file fct_parser.h.

Referenced by Parser< T >::begin(), and Parser< T >::end().


Constructor & Destructor Documentation

template<class T>
Parser< T >::Parser  
 


Member Function Documentation

template<class T>
void Parser< T >::add_var const std::string &    s,
  p = 0
 

Add a variable within the parser.

Parameters:
s the variable name
p the value (default 0)

Definition at line 199 of file fct_parser.h.

template<class T>
iterator Parser< T >::begin  
 

Return the begin iterator over all registered variable. The iterator has two menbers: "first" which is the name of the variable , and "second" which is the value of the variable.

Definition at line 142 of file fct_parser.h.

References Parser< T >::iterator.

template<class T>
iterator Parser< T >::end  
 

Return the end iterator over all registered variable.

See also:
begin

Definition at line 147 of file fct_parser.h.

References Parser< T >::iterator.

template<class T>
T Parser< T >::evaluate  
 

Evaluate the expression and return the result.

Definition at line 232 of file fct_parser.h.

Referenced by Parser< T >::set_function().

template<class T>
void Parser< T >::flush  
 

Clear every registered variables and set the function to nothing

template<class T>
const std::string& Parser< T >::get_errors   const
 

Get a list of errors in string format, if any.

Definition at line 130 of file fct_parser.h.

template<class T>
std::string Parser< T >::get_function  
 

Return the function definition

Definition at line 194 of file fct_parser.h.

template<class T>
T Parser< T >::get_var const std::string &    s const
 

Get the value of a registered variable

Parameters:
s the variable name
Returns:
the value

Definition at line 212 of file fct_parser.h.

template<class T>
bool Parser< T >::set_function const std::string &    s,
bool    pre_test = true
 

Set the function string to evaluate.

Parameters:
s the string function
pre_test if you want to automatically registered variables from the expression, and test the validity of the expression.
Returns:
true if there's no errors. See also get_errors method to retrieve all reported errors.

Definition at line 222 of file fct_parser.h.

References Parser< T >::evaluate().

template<class T>
void Parser< T >::set_var const std::string &    s,
  p
 

Set a variable value.

Parameters:
s the variable name
p the value

Definition at line 204 of file fct_parser.h.


Generated on Wed May 14 11:42:34 2003 for Esla-lib by doxygen1.3-rc1