38 #include <lifev/core/util/Parser.hpp> 53 #ifdef HAVE_LIFEV_DEBUG 54 debugStream ( 5030 ) <<
"Parser::Parser" <<
"\n";
57 M_calculator.setDefaultVariables();
60 Parser::Parser (
const std::string& string ) :
67 #ifdef HAVE_LIFEV_DEBUG 68 debugStream ( 5030 ) <<
"Parser::Parser( string )" <<
"\n";
71 M_calculator.setDefaultVariables();
89 if (
this != &parser )
91 std::cerr <<
"!!! ERROR: Operator= not working !!!" << std::endl;
92 std::exit ( EXIT_FAILURE );
114 for ( UInt i (0); i < M_strings.size(); ++i )
116 start = M_strings[i].begin();
117 end = M_strings[i].end();
118 #ifdef HAVE_BOOST_SPIRIT_QI 119 #ifdef ENABLE_SPIRIT_PARSER 120 qi::phrase_parse ( start, end, M_calculator, ascii::space, M_results );
122 std::cerr <<
"!!! ERROR: The Boost Spirit parser has been disabled !!!" << std::endl;
123 std::exit ( EXIT_FAILURE );
126 std::cerr <<
"!!! ERROR: Boost version < 1.41 !!!" << std::endl;
127 std::exit ( EXIT_FAILURE );
133 #ifdef HAVE_LIFEV_DEBUG 134 debugStream ( 5030 ) <<
"Parser::evaluate results[ " << id <<
"]: " << M_results[id] <<
"\n";
137 return M_results[id];
141 Parser::countSubstring (
const std::string& substring )
const 144 std::string::size_type position ( 0 );
148 position = M_strings.back().find ( substring, position );
150 if ( position == std::string::npos )
156 position += substring.length();
165 M_calculator.clearVariables();
173 Parser::setString (
const std::string& string,
const std::string& stringSeparator )
176 #ifdef HAVE_LIFEV_DEBUG 177 debugStream ( 5030 ) <<
"Parser::setString strings: " << string <<
"\n";
181 boost::split ( M_strings, string, boost::is_any_of ( stringSeparator ) );
184 for ( UInt i = 0; i < M_strings.size(); ++i )
186 boost::replace_all ( M_strings[i],
" ",
"" );
191 M_results.reserve ( countSubstring (
"," ) + 1 );
197 Parser::setVariable (
const std::string& name,
const Real& value )
200 #ifdef HAVE_LIFEV_DEBUG 201 debugStream ( 5030 ) <<
"Parser::setVariable variables[" << name <<
"]: " << value <<
"\n";
204 M_calculator.setVariable ( name, value);
213 Parser::variable (
const std::string& name )
216 #ifdef HAVE_LIFEV_DEBUG 217 debugStream ( 5030 ) <<
"Parser::variable variables[" << name <<
"]: " << M_calculator.variable ( name ) <<
"\n";
220 return M_calculator.variable ( name );
Parser(const Parser &parser)
Copy constructor.
void clearVariables()
Clear all the variables.
Parser & operator=(const Parser &parser)
Operator =.
calculator_Type M_calculator
stringsVector_Type M_strings
Parser()
Empty constructor (it needs a manual call to setString)
void updateInverseJacobian(const UInt &iQuadPt)
std::string::const_iterator stringIterator_Type
Type definition for the iterator over the strings.
Parser - A string parser for algebraic expressions.
double Real
Generic real data.
const Real & evaluate(const ID &id=0)
Evaluate the expression.
uint32_type UInt
generic unsigned integer (used mainly for addressing)