mbxmlutils
1.3.0
Multi-Body XML Utils
|
#include <eval.h>
Public Types | |
enum | ValueType { ScalarType , VectorType , MatrixType , StringType , FunctionType } |
using | Value = std::shared_ptr< void > |
Typedef for a shared value. | |
Public Member Functions | |
~Eval () override | |
Destructor. | |
Eval (const Eval &other)=delete | |
Eval (Eval &&other)=delete | |
Eval & | operator= (const Eval &other)=delete |
Eval & | operator= (Eval &&other)=delete |
virtual std::string | getName () const =0 |
Get the type of this evaluator. More... | |
void | addParam (const std::string ¶mName, const Value &value) |
Add a value to the current parameters. | |
void | addParamSet (const xercesc::DOMElement *e) |
virtual void | addImport (const std::string &code, const xercesc::DOMElement *e, const std::string &action="")=0 |
Value | eval (const xercesc::DOMElement *e) |
Value | eval (const xercesc::DOMAttr *a) |
Value | eval (const std::string &str, const xercesc::DOMElement *e=nullptr, bool skipRet=false) |
template<typename T > | |
T | cast (const Value &value) const |
virtual std::string | getStringRepresentation (const Value &x) const |
Returns a evaluator specific string representation of x. This is only useful for display to the user. More... | |
virtual bool | valueIsOfType (const Value &value, ValueType type) const =0 |
Value | stringToValue (const std::string &str, const xercesc::DOMElement *e=nullptr, bool fullEval=true, bool skipRet=false) const |
template<class T > | |
Value | create (const T &v) const |
virtual std::map< boost::filesystem::path, std::pair< boost::filesystem::path, bool > > & | requiredFiles () const =0 |
return a list of all required files of the evaluator (excluding dependent files of libraries) More... | |
virtual void | convertIndex (Value &v, bool evalTo1Based)=0 |
virtual Value | callFunction (const std::string &name, const std::vector< Value > &args) const =0 |
size_t | getStackSize () |
template<> | |
string | cast (const Value &value) const |
template<> | |
CodeString | cast (const Value &value) const |
template<> | |
double | cast (const Value &value) const |
template<> | |
int | cast (const Value &value) const |
template<> | |
vector< double > | cast (const Value &value) const |
template<> | |
vector< vector< double > > | cast (const Value &value) const |
template<> | |
Eval::Value | create (const double &v) const |
template<> | |
Eval::Value | create (const vector< double > &v) const |
template<> | |
Eval::Value | create (const vector< vector< double > > &v) const |
template<> | |
Eval::Value | create (const string &v) const |
template<> | |
CodeString | cast (const Value &value) const |
template<> | |
double | cast (const Value &value) const |
template<> | |
int | cast (const Value &value) const |
template<> | |
Eval::Value | create (const double &v) const |
Static Public Member Functions | |
static std::shared_ptr< Eval > | createEvaluator (const std::string &evalName, std::vector< boost::filesystem::path > *dependencies_=nullptr) |
Create a evaluator. | |
template<class E > | |
static void | registerEvaluator () |
static void | setValue (xercesc::DOMElement *e, const Value &v) |
Set value on DOMElement (is used by Eval::cast) | |
Static Public Attributes | |
static boost::filesystem::path | installPath |
Protected Member Functions | |
Eval (std::vector< boost::filesystem::path > *dependencies_) | |
Constructor. | |
virtual Value | createFunctionIndep (int dim) const =0 |
create a function independent variable. If dim == 0 a scalar is created else a vector. More... | |
virtual Value | createFunctionDep (const std::vector< Value > &v) const =0 |
create a vector function dependent More... | |
virtual Value | createFunctionDep (const std::vector< std::vector< Value > > &v) const =0 |
create a matrix function dependent More... | |
virtual Value | createFunction (const std::vector< Value > &indeps, const Value &dep) const =0 |
create a Function with n independents and a dependent function (scalar, vector or matrix) More... | |
void | pushContext () |
Push the current context to a internal stack. | |
void | popContext () |
Overwrite the current context with the top level context from the internal stack. | |
virtual Value | fullStringToValue (const std::string &str, const xercesc::DOMElement *e, bool skipRet=false) const =0 |
evaluate the string str using the current parameters and return the result. More... | |
std::string | partialStringToString (const std::string &str, const xercesc::DOMElement *e) const |
evaluate str partially and return result as an std::string | |
void | addStaticDependencies (const xercesc::DOMElement *e) const |
Static Protected Member Functions | |
template<class E > | |
static std::shared_ptr< Eval > | newEvaluator (std::vector< boost::filesystem::path > *dependencies_) |
static void | printEvaluatorMsg (const std::ostringstream &str, MsgType msgType) |
Protected Attributes | |
std::vector< boost::filesystem::path > * | dependencies |
std::unordered_map< std::string, Value > | currentParam |
std::stack< std::unordered_map< std::string, Value > > | paramStack |
std::unordered_map< std::string, Value > | currentImport |
std::stack< std::unordered_map< std::string, Value > > | importStack |
Private Member Functions | |
virtual double | cast_double (const Value &value) const =0 |
virtual std::vector< double > | cast_vector_double (const Value &value) const =0 |
virtual std::vector< std::vector< double > > | cast_vector_vector_double (const Value &value) const =0 |
virtual std::string | cast_string (const Value &value) const =0 |
CodeString | cast_CodeString (const Value &value) const |
int | cast_int (const Value &value) const |
virtual Value | create_double (const double &v) const =0 |
virtual Value | create_vector_double (const std::vector< double > &v) const =0 |
virtual Value | create_vector_vector_double (const std::vector< std::vector< double > > &v) const =0 |
virtual Value | create_string (const std::string &v) const =0 |
virtual std::string | serializeFunction (const Value &x) const =0 |
Value | handleUnit (const xercesc::DOMElement *e, const Value &ret) |
Static Private Member Functions | |
static std::map< std::string, std::function< std::shared_ptr< Eval >(std::vector< boost::filesystem::path > *)> > & | getEvaluators () |
Static Private Attributes | |
static std::map< std::string, std::string > | units |
Friends | |
class | NewParamLevel |
Expression evaluator and converter.
Known types for a variable See also valueIsOfType.
|
pure virtual |
Import evaluator statements. This routine highly depends on the evaluator. See the spezialized evaluators documentation for details.
Implemented in MBXMLUtils::OctEval, MBXMLUtils::PyEval, and MBXMLUtils::XMLFlatEval.
void MBXMLUtils::Eval::addParamSet | ( | const xercesc::DOMElement * | e | ) |
Add all parameters from XML element e. The parameters are added from top to bottom as they appear in the XML element e. Parameters may depend on parameters already added.
|
pure virtual |
Return the value of a call to name using the arguments args. The following functions must be implemented by the evaluator:
Implemented in MBXMLUtils::OctEval, MBXMLUtils::PyEval, and MBXMLUtils::XMLFlatEval.
T MBXMLUtils::Eval::cast | ( | const Value & | value | ) | const |
Cast the value value to type T
. Possible combinations of allowed value types and template types T
are listed in the following table. If a combination is not allowed a exception is thrown.
value is of Type ... | |||||
---|---|---|---|---|---|
Template Type T equals ... | real scalar | real vector | real matrix | string |
|
int | only if its integral number | ||||
double | X | ||||
vector<double> | X | X | |||
vector<vector<double> > | X | X | X | ||
string | X | ||||
CodeString | returns e.g. 5 | returns e.g. [3;7] | returns e.g. [1,3;5,4] | returns e.g. 'foo' | returns e.g. ( 2 [...] {...} [...]) |
|
pure virtual |
convert a index (scalar or vector). if evalTo1Based == true: convert from the script language 0/1 base to 1 base. if evalTo1Based == false: convert from 1 base to the script language 0/1 base.
Implemented in MBXMLUtils::PyEval, MBXMLUtils::OctEval, and MBXMLUtils::XMLFlatEval.
Value MBXMLUtils::Eval::create | ( | const T & | v | ) | const |
create a value of the given type. T can be one of: double: create a floating point value vector<double>: create a vector of floating point values vector<vector<double>>: create a matrix of floating point values string: create a string value
|
protectedpure virtual |
create a Function with n independents and a dependent function (scalar, vector or matrix)
Implemented in MBXMLUtils::OctEval, MBXMLUtils::PyEval, and MBXMLUtils::XMLFlatEval.
|
protectedpure virtual |
create a matrix function dependent
Implemented in MBXMLUtils::OctEval, MBXMLUtils::PyEval, and MBXMLUtils::XMLFlatEval.
|
protectedpure virtual |
create a vector function dependent
Implemented in MBXMLUtils::OctEval, MBXMLUtils::PyEval, and MBXMLUtils::XMLFlatEval.
|
protectedpure virtual |
create a function independent variable. If dim == 0 a scalar is created else a vector.
Implemented in MBXMLUtils::OctEval, MBXMLUtils::PyEval, and MBXMLUtils::XMLFlatEval.
Value MBXMLUtils::Eval::eval | ( | const std::string & | str, |
const xercesc::DOMElement * | e = nullptr , |
||
bool | skipRet = false |
||
) |
Evaluate str using the current parameters. if skipRet=true then str is not required to return anything, a empty Value will be returned in this case.
Eval::Value MBXMLUtils::Eval::eval | ( | const xercesc::DOMAttr * | a | ) |
Evaluate the XML attribute a using the current parameters returning the resulting value. The type of evaluation depends on the type of a. The result of a "partially" evaluation is returned as a string even so it is not really a string.
Value MBXMLUtils::Eval::eval | ( | const xercesc::DOMElement * | e | ) |
Evaluate the XML element e using the current parameters returning the resulting value. The type of evaluation depends on the type of e.
|
protectedpure virtual |
evaluate the string str using the current parameters and return the result.
Implemented in MBXMLUtils::OctEval, MBXMLUtils::PyEval, and MBXMLUtils::XMLFlatEval.
|
pure virtual |
Get the type of this evaluator.
Implemented in MBXMLUtils::OctEval, MBXMLUtils::PyEval, and MBXMLUtils::XMLFlatEval.
|
virtual |
Returns a evaluator specific string representation of x. This is only useful for display to the user.
Reimplemented in MBXMLUtils::PyEval.
|
pure virtual |
return a list of all required files of the evaluator (excluding dependent files of libraries)
Implemented in MBXMLUtils::OctEval, MBXMLUtils::PyEval, and MBXMLUtils::XMLFlatEval.
Eval::Value MBXMLUtils::Eval::stringToValue | ( | const std::string & | str, |
const xercesc::DOMElement * | e = nullptr , |
||
bool | fullEval = true , |
||
bool | skipRet = false |
||
) | const |
evaluate str and return result as an variable, this can be used to evaluate outside of XML. If e is given it is used as location information in case of errors. If fullEval is false the "partially" evaluation is returned as a string even so it is not really a string.
|
pure virtual |
check whether value is of type type. Note that true is only returned if the value is really of type type. If value can be casted to type type but is not of this type then false is returned. Note that their are evaluators (e.g. octave) which cannot distinguish between e.g. a scalar, a vector of size 1 or a matrix of size 1x1. Hence, these evaluators will return true for ScalarType in all these three cases and analog for VectorType.
Implemented in MBXMLUtils::OctEval, MBXMLUtils::PyEval, and MBXMLUtils::XMLFlatEval.