mbxmlutils  1.3.0
Multi-Body XML Utils
pyeval.h
1#ifndef _MBXMLUTILS_PYEVAL_H_
2#define _MBXMLUTILS_PYEVAL_H_
3
4#include "eval.h"
5#include "pycppwrapper.h"
6#include <boost/uuid/name_generator.hpp>
7
8namespace MBXMLUtils {
9
14class PyEval : public Eval {
15 friend class Eval;
16
17 protected:
19 PyEval(std::vector<boost::filesystem::path> *dependencies_=nullptr);
20 public:
22 ~PyEval() override;
23 void garbageCollect() override;
24 static std::string getNameStatic() { return "python"; }
25 std::string getName() const override { return getNameStatic(); }
26 void addImport(const std::string &code, const xercesc::DOMElement *e, const std::string &action="") override;
27 bool valueIsOfType(const Value &value, ValueType type) const override;
28 std::map<boost::filesystem::path, std::pair<boost::filesystem::path, bool> >& requiredFiles() const override;
29 void convertIndex(Value &v, bool evalTo1Base) override;
30 std::string getStringRepresentation(const Value &x) const override;
31 protected:
32 Value createFunctionIndep(int dim) const override;
33 Value callFunction(const std::string &name, const std::vector<Value>& args) const override;
34 Value fullStringToValue(const std::string &str, const xercesc::DOMElement *e, bool skipRet=false) const override;
35 private:
36 // Eval::currentImport / importStack is not used since
37 // - "addNewVarsToInstance" uses globaImportDict and
38 // - "addAllVarsAsParams" uses currentParam / paramStack.
39 PythonCpp::PyO globalImportDict; // deprecated
40
41 double cast_double (const Value &value) const override;
42 std::vector<double> cast_vector_double (const Value &value) const override;
43 std::vector<std::vector<double> >cast_vector_vector_double (const Value &value) const override;
44 std::string cast_string (const Value &value) const override;
45 Value create_double (const double& v) const override;
46 Value create_vector_double (const std::vector<double>& v) const override;
47 Value create_vector_vector_double (const std::vector<std::vector<double> >& v) const override;
48 Value create_string (const std::string& v) const override;
49 std::string createSourceCode_double (const double& v) const override;
50 std::string createSourceCode_vector_double (const std::vector<double>& v) const override;
51 std::string createSourceCode_vector_vector_double(const std::vector<std::vector<double> >& v) const override;
52 std::string createSourceCode_string (const std::string& v) const override;
53
54 Value createFunctionDep(const std::vector<Value>& v) const override;
55 Value createFunctionDep(const std::vector<std::vector<Value> >& v) const override;
56 Value createFunction(const std::vector<Value> &indeps, const Value &dep) const override;
57
58 std::string serializeFunction(const Value &x) const override;
59 static boost::uuids::name_generator uuidGen;
60 mutable std::unordered_map<boost::uuids::uuid, std::pair<int, PythonCpp::PyO>, boost::hash<boost::uuids::uuid>> byteCodeMap;
61};
62
63}
64
65#endif
Definition: eval.h:87
ValueType
Definition: eval.h:93
std::shared_ptr< void > Value
Typedef for a shared value.
Definition: eval.h:102
Definition: pyeval.h:14
void garbageCollect() override
Definition: pyeval.cc:236
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.
Definition: pyeval.cc:897
Value createFunctionDep(const std::vector< std::vector< Value > > &v) const override
create a matrix function dependent
void convertIndex(Value &v, bool evalTo1Base) override
Definition: pyeval.cc:865
Value createFunctionDep(const std::vector< Value > &v) const override
create a vector function dependent
PyEval(std::vector< boost::filesystem::path > *dependencies_=nullptr)
Constructor.
Definition: pyeval.cc:225
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)
Definition: pyeval.cc:835
void addImport(const std::string &code, const xercesc::DOMElement *e, const std::string &action="") override
Definition: pyeval.cc:288
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)
Definition: pyeval.cc:417
Value createFunctionIndep(int dim) const override
create a function independent variable. If dim == 0 a scalar is created else a vector.
Definition: pyeval.cc:241
bool valueIsOfType(const Value &value, ValueType type) const override
Definition: pyeval.cc:404
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.
Definition: pyeval.cc:497
Value callFunction(const std::string &name, const std::vector< Value > &args) const override
Definition: pyeval.cc:483
std::string getName() const override
Get the type of this evaluator.
Definition: pyeval.h:25
~PyEval() override
Destructor.
Definition: pyeval.cc:230
Definition: pycppwrapper.h:98