mbxmlutils  1.3.0
Multi-Body XML Utils
octeval.h
1/*
2 mbxmlutils-eval-octave:
3 Octave implementation of the 'eval' plugin interface of MBXMLUtils
4
5 Copyright (C) Markus Friedrich
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <https://www.gnu.org/licenses/>.
19*/
20
21#ifndef _MBXMLUTILS_OCTEVAL_H_
22#define _MBXMLUTILS_OCTEVAL_H_
23
24#include "eval.h"
25#include <memory>
26
27class octave_value;
28class octave_value_list;
29class octave_function;
30
31namespace fmatvec {
32 class SymbolicExpression;
33}
34
35namespace XERCES_CPP_NAMESPACE { class DOMElement; }
36
37namespace MBXMLUtils {
38
39std::shared_ptr<octave_value> C(const Eval::Value &value);
40
41Eval::Value C(const octave_value &value);
42
43class OctEval;
44
49class OctEval : public Eval {
50 friend class Eval;
51
52 protected:
54 OctEval(std::vector<boost::filesystem::path> *dependencies_=nullptr);
55
56 public:
58 ~OctEval() override;
59
61 static std::string getNameStatic() { return "octave"; }
62 std::string getName() const override { return getNameStatic(); }
63
68 void addImport(const std::string &code, const xercesc::DOMElement *e, const std::string &action="") override;
69
70 void addImportHelper(const boost::filesystem::path &dir);
71
73 bool valueIsOfType(const Value &value, ValueType type) const override;
74
76 std::map<boost::filesystem::path, std::pair<boost::filesystem::path, bool> >& requiredFiles() const override;
77
78 void convertIndex(Value &v, bool evalTo1Based) override {}
79
80 protected:
81
82 struct Import {
83 std::string path;
84 std::map<std::string, octave_value> vn;
85 std::map<std::string, octave_value> gvn;
86 std::map<std::string, octave_value> ufn;
87 std::map<std::string, octave_value> tlvn;
88 };
89
90 Value createFunctionIndep(int dim) const override;
91
93 Value fullStringToValue(const std::string &str, const xercesc::DOMElement *e, bool skipRet=false) const override;
94
95 static octave_value_list fevalThrow(octave_function *func, const octave_value_list &arg, int n=0,
96 const std::string &msg=std::string());
97
98 static void* getSwigPtr(const octave_value &v);
99 static Value createSwigByTypeName(const std::string &name);
100 static std::string getSwigType(const octave_value &value);
101
102 Value callFunction(const std::string &name, const std::vector<Value>& args) const override;
103
104 double cast_double (const Value &value) const override;
105 std::vector<double> cast_vector_double (const Value &value) const override;
106 std::vector<std::vector<double> > cast_vector_vector_double(const Value &value) const override;
107 std::string cast_string (const Value &value) const override;
108
109 Value create_double (const double& v) const override;
110 Value create_vector_double (const std::vector<double>& v) const override;
111 Value create_vector_vector_double(const std::vector<std::vector<double> >& v) const override;
112 Value create_string (const std::string& v) const override;
113
114 std::string createSourceCode_double (const double& v) const override;
115 std::string createSourceCode_vector_double (const std::vector<double>& v) const override;
116 std::string createSourceCode_vector_vector_double(const std::vector<std::vector<double> >& v) const override;
117 std::string createSourceCode_string (const std::string& v) const override;
118
119 Value createFunctionDep(const std::vector<Value>& v) const override;
120 Value createFunctionDep(const std::vector<std::vector<Value> >& v) const override;
121 Value createFunction(const std::vector<Value> &indeps, const Value &dep) const override;
122
123 std::string serializeFunction(const Value &x) const override;
124};
125
126} // end namespace MBXMLUtils
127
128#endif
Definition: eval.h:77
ValueType
Definition: eval.h:83
std::shared_ptr< void > Value
Typedef for a shared value.
Definition: eval.h:92
Definition: octeval.h:49
Value fullStringToValue(const std::string &str, const xercesc::DOMElement *e, bool skipRet=false) const override
evaluate str fully and return result as an octave variable
Definition: octeval.cc:594
void convertIndex(Value &v, bool evalTo1Based) override
Definition: octeval.h:78
~OctEval() override
Destructor.
void addImport(const std::string &code, const xercesc::DOMElement *e, const std::string &action="") override
Definition: octeval.cc:566
OctEval(std::vector< boost::filesystem::path > *dependencies_=nullptr)
Constructor.
Definition: octeval.cc:486
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: octeval.cc:416
Value createFunctionDep(const std::vector< Value > &v) const override
create a vector function dependent
Definition: octeval.cc:382
std::string getName() const override
Get the type of this evaluator.
Definition: octeval.h:62
Value createFunctionIndep(int dim) const override
create a function independent variable. If dim == 0 a scalar is created else a vector.
Definition: octeval.cc:494
Value callFunction(const std::string &name, const std::vector< Value > &args) const override
Definition: octeval.cc:896
static std::string getNameStatic()
Get the name of this evaluator.
Definition: octeval.h:61
bool valueIsOfType(const Value &value, ValueType type) const override
get the type of value
Definition: octeval.cc:766
std::map< boost::filesystem::path, std::pair< boost::filesystem::path, bool > > & requiredFiles() const override
return a list of all required files of octave (excluding dependent files of libraries)
Definition: octeval.cc:848
Definition: octeval.h:82