LifeV
|
Parser - A string parser for algebraic expressions. More...
#include <Parser.hpp>
Private Attributes | |
stringsVector_Type | M_strings |
results_Type | M_results |
bool | M_evaluate |
calculator_Type | M_calculator |
Public Types | |
typedef std::vector< std::string > | stringsVector_Type |
Type definition for the vector containing the string segments. More... | |
typedef std::string::const_iterator | stringIterator_Type |
Type definition for the iterator over the strings. More... | |
typedef ParserSpiritGrammar< stringIterator_Type > | calculator_Type |
Type definition for the parser interpreter. More... | |
typedef calculator_Type::results_Type | results_Type |
Type definition for the results. More... | |
Constructors & Destructor | |
Parser () | |
Empty constructor (it needs a manual call to setString) More... | |
Parser (const std::string &string) | |
Constructor. More... | |
Parser (const Parser &parser) | |
Copy constructor. More... | |
virtual | ~Parser () |
Destructor. More... | |
Operators | |
Parser & | operator= (const Parser &parser) |
Operator =. More... | |
Methods | |
const Real & | evaluate (const ID &id=0) |
Evaluate the expression. More... | |
UInt | countSubstring (const std::string &substring) const |
Count how many substrings are present in the string (utility for BCInterfaceFunctionParser) More... | |
void | clearVariables () |
Clear all the variables. More... | |
Set Methods | |
void | setString (const std::string &string, const std::string &stringSeparator=";") |
Set string function. More... | |
void | setVariable (const std::string &name, const Real &value) |
Set/replace a variable. More... | |
Get Methods | |
const Real & | variable (const std::string &name) |
Get variable. More... | |
Parser - A string parser for algebraic expressions.
Parser
is a general interface class for LifeV
algebraic parsers. At the present time it works only with boost::spirit::qi
.
EXAMPLE - HOW TO USE
The syntax is very simple:
Parser parser;
parser.setString( "-sqrt(4)+1*2" );
Real result = parser.evaluate();
You can change the string at any time:
parser.setString( "c=2; [0., c, c*c, c*c*c]" );
Real result0 = parser.evaluate(0); // 0
Real result1 = parser.evaluate(1); // c
Real result2 = parser.evaluate(2); // c*c
Real result3 = parser.evaluate(3); // c*c*c
See ParserSpiritGrammar
class for more details on the expression syntax.
Definition at line 77 of file Parser.hpp.
typedef std::vector< std::string > stringsVector_Type |
Type definition for the vector containing the string segments.
Definition at line 86 of file Parser.hpp.
typedef std::string::const_iterator stringIterator_Type |
Type definition for the iterator over the strings.
Definition at line 90 of file Parser.hpp.
typedef ParserSpiritGrammar< stringIterator_Type > calculator_Type |
Type definition for the parser interpreter.
Definition at line 94 of file Parser.hpp.
typedef calculator_Type::results_Type results_Type |
Type definition for the results.
Definition at line 98 of file Parser.hpp.
|
explicit |
Empty constructor (it needs a manual call to setString)
Definition at line 46 of file Parser.cpp.
|
explicit |
|
inlinevirtual |
Destructor.
Definition at line 122 of file Parser.hpp.
Operator =.
Important note: this method is not working right now.
parser | Parser |
Definition at line 87 of file Parser.cpp.
Evaluate the expression.
id | expression index (starting from 0) |
Definition at line 107 of file Parser.cpp.
UInt countSubstring | ( | const std::string & | substring | ) | const |
Count how many substrings are present in the string (utility for BCInterfaceFunctionParser)
substring | string to find |
Definition at line 141 of file Parser.cpp.
void clearVariables | ( | ) |
Clear all the variables.
Definition at line 163 of file Parser.cpp.
void setString | ( | const std::string & | string, |
const std::string & | stringSeparator = ";" |
||
) |
Set string function.
string | Expression to evaluate |
stringSeparator | Separator identifier (default -> ";") |
Definition at line 173 of file Parser.cpp.
void setVariable | ( | const std::string & | name, |
const Real & | value | ||
) |
Set/replace a variable.
name | name of the parameter |
value | value of the parameter |
Definition at line 197 of file Parser.cpp.
const Real & variable | ( | const std::string & | name | ) |
Get variable.
name | name of the parameter |
Definition at line 213 of file Parser.cpp.
|
private |
Definition at line 199 of file Parser.hpp.
|
private |
Definition at line 201 of file Parser.hpp.
|
private |
Definition at line 203 of file Parser.hpp.
|
private |
Definition at line 205 of file Parser.hpp.