mbxmlutils  1.3.0
Multi-Body XML Utils
MBXMLUtils::PyEval Class Reference

#include <pyeval.h>

Inheritance diagram for MBXMLUtils::PyEval:
[legend]

Public Member Functions

 ~PyEval () override
 Destructor.
 
std::string getName () const override
 Get the type of this evaluator. More...
 
void addImport (const std::string &code, const xercesc::DOMElement *e, const std::string &action="") override
 
bool valueIsOfType (const Value &value, ValueType type) const override
 
std::map< boost::filesystem::path, std::pair< boost::filesystem::path, bool > > & requiredFiles () const override
 return a list of all required files of the evaluator (excluding dependent files of libraries) More...
 
void convertIndex (Value &v, bool evalTo1Base) override
 
std::string getStringRepresentation (const Value &x) const override
 Returns a evaluator specific string representation of x. This is only useful for display to the user. More...
 
- Public Member Functions inherited from MBXMLUtils::Eval
 ~Eval () override
 Destructor.
 
 Eval (const Eval &other)=delete
 
 Eval (Eval &&other)=delete
 
Evaloperator= (const Eval &other)=delete
 
Evaloperator= (Eval &&other)=delete
 
virtual std::string getName () const =0
 Get the type of this evaluator. More...
 
void addParam (const std::string &paramName, 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 >
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::string getNameStatic ()
 
- Static Public Member Functions inherited from MBXMLUtils::Eval
static std::shared_ptr< EvalcreateEvaluator (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)
 

Protected Member Functions

 PyEval (std::vector< boost::filesystem::path > *dependencies_=nullptr)
 Constructor.
 
Value createFunctionIndep (int dim) const override
 create a function independent variable. If dim == 0 a scalar is created else a vector. More...
 
Value callFunction (const std::string &name, const std::vector< Value > &args) const override
 
Value fullStringToValue (const std::string &str, const xercesc::DOMElement *e, bool skipRet=false) const override
 evaluate the string str using the current parameters and return the result. More...
 
- Protected Member Functions inherited from MBXMLUtils::Eval
 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
 

Private Member Functions

double cast_double (const Value &value) const override
 
std::vector< double > cast_vector_double (const Value &value) const override
 
std::vector< std::vector< double > > cast_vector_vector_double (const Value &value) const override
 
std::string cast_string (const Value &value) const override
 
Value create_double (const double &v) const override
 
Value create_vector_double (const std::vector< double > &v) const override
 
Value create_vector_vector_double (const std::vector< std::vector< double > > &v) const override
 
Value create_string (const std::string &v) const override
 
Value createFunctionDep (const std::vector< Value > &v) const override
 create a vector function dependent More...
 
Value createFunctionDep (const std::vector< std::vector< Value > > &v) const override
 create a matrix function dependent More...
 
Value createFunction (const std::vector< Value > &indeps, const Value &dep) const override
 create a Function with n independents and a dependent function (scalar, vector or matrix) More...
 
std::string serializeFunction (const Value &x) const override
 

Private Attributes

PythonCpp::PyO globalImportDict
 
std::map< boost::uuids::uuid, std::pair< int, PythonCpp::PyO > > byteCodeMap
 

Static Private Attributes

static boost::uuids::name_generator uuidGen
 

Friends

class Eval
 

Additional Inherited Members

- Public Types inherited from MBXMLUtils::Eval
enum  ValueType {
  ScalarType , VectorType , MatrixType , StringType ,
  FunctionType
}
 
using Value = std::shared_ptr< void >
 Typedef for a shared value.
 
- Static Public Attributes inherited from MBXMLUtils::Eval
static boost::filesystem::path installPath
 
- Static Protected Member Functions inherited from MBXMLUtils::Eval
template<class E >
static std::shared_ptr< EvalnewEvaluator (std::vector< boost::filesystem::path > *dependencies_)
 
static void printEvaluatorMsg (const std::ostringstream &str, MsgType msgType)
 
- Protected Attributes inherited from MBXMLUtils::Eval
std::vector< boost::filesystem::path > * dependencies
 
std::unordered_map< std::string, ValuecurrentParam
 
std::stack< std::unordered_map< std::string, Value > > paramStack
 
std::unordered_map< std::string, ValuecurrentImport
 
std::stack< std::unordered_map< std::string, Value > > importStack
 

Detailed Description

A evaluator based on python.

See measurementToHtml.xsl for details.

Member Function Documentation

◆ addImport()

void MBXMLUtils::PyEval::addImport ( const std::string &  code,
const xercesc::DOMElement *  e,
const std::string &  action = "" 
)
overridevirtual

Import evaluator statements. This routine highly depends on the evaluator. See the spezialized evaluators documentation for details.

Implements MBXMLUtils::Eval.

◆ callFunction()

Eval::Value MBXMLUtils::PyEval::callFunction ( const std::string &  name,
const std::vector< Value > &  args 
) const
overrideprotectedvirtual

Return the value of a call to name using the arguments args. The following functions must be implemented by the evaluator:

  • rotateAboutX(alpha): returns a 3x3 rotation matrix about the x-axis by angle alpha which is given in rad.
  • rotateAboutY(beta): returns a 3x3 rotation matrix about the y-axis by angle beta which is given in rad.
  • rotateAboutZ(gamma): returns a 3x3 rotation matrix about the z-axis by angle gamma which is given in rad.
  • cardan(alpha, beta, gamma): returns a 3x3 rotation matrix of a cardan rotation about the angles alpha, beta and gamma which are given in rad.
  • euler(PHI, theta, phi): returns a 3x3 rotation matrix of a euler rotation about the angles PHI, theta and phi which are given in rad.
  • load(filename): returns a NxM matrix of the data stored in the file filename. filename may be a absolute or relative path. A relative path is interprete relative to the location of the XML file with the load statement. (The abstract Eval class guarantees that the current path is at the XML file if load is called)

Implements MBXMLUtils::Eval.

◆ cast_double()

double MBXMLUtils::PyEval::cast_double ( const Value value) const
overrideprivatevirtual

Implements MBXMLUtils::Eval.

◆ cast_string()

string MBXMLUtils::PyEval::cast_string ( const Value value) const
overrideprivatevirtual

Implements MBXMLUtils::Eval.

◆ cast_vector_double()

vector< double > MBXMLUtils::PyEval::cast_vector_double ( const Value value) const
overrideprivatevirtual

Implements MBXMLUtils::Eval.

◆ cast_vector_vector_double()

vector< vector< double > > MBXMLUtils::PyEval::cast_vector_vector_double ( const Value value) const
overrideprivatevirtual

Implements MBXMLUtils::Eval.

◆ convertIndex()

void MBXMLUtils::PyEval::convertIndex ( Value v,
bool  evalTo1Based 
)
overridevirtual

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.

Implements MBXMLUtils::Eval.

◆ create_double()

Eval::Value MBXMLUtils::PyEval::create_double ( const double &  v) const
overrideprivatevirtual

Implements MBXMLUtils::Eval.

◆ create_string()

Eval::Value MBXMLUtils::PyEval::create_string ( const std::string &  v) const
overrideprivatevirtual

Implements MBXMLUtils::Eval.

◆ create_vector_double()

Eval::Value MBXMLUtils::PyEval::create_vector_double ( const std::vector< double > &  v) const
overrideprivatevirtual

Implements MBXMLUtils::Eval.

◆ create_vector_vector_double()

Eval::Value MBXMLUtils::PyEval::create_vector_vector_double ( const std::vector< std::vector< double > > &  v) const
overrideprivatevirtual

Implements MBXMLUtils::Eval.

◆ createFunction()

Eval::Value MBXMLUtils::PyEval::createFunction ( const std::vector< Value > &  indeps,
const Value dep 
) const
overrideprivatevirtual

create a Function with n independents and a dependent function (scalar, vector or matrix)

Implements MBXMLUtils::Eval.

◆ createFunctionDep() [1/2]

Value MBXMLUtils::PyEval::createFunctionDep ( const std::vector< std::vector< Value > > &  v) const
overrideprivatevirtual

create a matrix function dependent

Implements MBXMLUtils::Eval.

◆ createFunctionDep() [2/2]

Value MBXMLUtils::PyEval::createFunctionDep ( const std::vector< Value > &  v) const
overrideprivatevirtual

create a vector function dependent

Implements MBXMLUtils::Eval.

◆ createFunctionIndep()

Eval::Value MBXMLUtils::PyEval::createFunctionIndep ( int  dim) const
overrideprotectedvirtual

create a function independent variable. If dim == 0 a scalar is created else a vector.

Implements MBXMLUtils::Eval.

◆ fullStringToValue()

Eval::Value MBXMLUtils::PyEval::fullStringToValue ( const std::string &  str,
const xercesc::DOMElement *  e,
bool  skipRet = false 
) const
overrideprotectedvirtual

evaluate the string str using the current parameters and return the result.

Implements MBXMLUtils::Eval.

◆ getName()

std::string MBXMLUtils::PyEval::getName ( ) const
inlineoverridevirtual

Get the type of this evaluator.

Implements MBXMLUtils::Eval.

◆ getStringRepresentation()

string MBXMLUtils::PyEval::getStringRepresentation ( const Value x) const
overridevirtual

Returns a evaluator specific string representation of x. This is only useful for display to the user.

Reimplemented from MBXMLUtils::Eval.

◆ requiredFiles()

map< path, pair< path, bool > > & MBXMLUtils::PyEval::requiredFiles ( ) const
overridevirtual

return a list of all required files of the evaluator (excluding dependent files of libraries)

Implements MBXMLUtils::Eval.

◆ serializeFunction()

string MBXMLUtils::PyEval::serializeFunction ( const Value x) const
overrideprivatevirtual

Implements MBXMLUtils::Eval.

◆ valueIsOfType()

bool MBXMLUtils::PyEval::valueIsOfType ( const Value value,
ValueType  type 
) const
overridevirtual

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.

Implements MBXMLUtils::Eval.


The documentation for this class was generated from the following files: