BALL 1.5.0
Loading...
Searching...
No Matches
parsedFunction.h
Go to the documentation of this file.
1// -*- Mode: C++; tab-width: 2; -*-
2// vi: set ts=2:
3//
4
5#ifndef BALL_MATHS_PARSEDFUNCTION_H
6#define BALL_MATHS_PARSEDFUNCTION_H
7
8#ifndef BALL_DATATYPE_STRINGHASHMAP_H
10#endif
11
12#include <numeric>
13
14using std::unary_function;
15
16extern double ParsedFunctionResult;
18extern void ParsedFunction_initBuffer(const char*);
20
21namespace BALL
22{
26 extern StringHashMap<double*> *ParsedFunctionConstants;
27 extern StringHashMap<double (*)(double)> *ParsedFunctionFunctions;
28
36 template <typename arg>
38 : public unary_function<arg, double>
39 {
40 public:
44
47
49 ParsedFunction(const String& expression);
50
52 ParsedFunction(const ParsedFunction& func);
53
56
58
65 double operator () (arg p);
66
68
73 void initTable();
75
79
83
84 protected:
86 };
87
88 template <typename arg>
90 : constants_(),
91 functions_(),
92 expression_("")
93 {
94 initTable();
95 }
96
97 template <typename arg>
99 : constants_(),
100 functions_(),
101 expression_(expression)
102 {
103 initTable();
104 }
105
106 template <typename arg>
108 {
109 constants_ = func.constants_;
110 functions_ = func.functions_;
111 expression_ = func.expression_;
112 initTable();
113 }
114
115 template <typename arg>
119
120 template <typename arg>
122 {
123 constants_["X"] = (double*)&argument;
124 ParsedFunctionConstants = &constants_;
125 ParsedFunctionFunctions = &functions_;
126 ParsedFunction_initBuffer(expression_.c_str());
129
131 }
132
133 template <>
135
136 template <>
138
139 template <typename arg>
141 {
142 // initialize the functions table
143 functions_["sin"] = (double(*)(double))&sin;
144 functions_["cos"] = (double(*)(double))&cos;
145 functions_["asin"] = (double(*)(double))&asin;
146 functions_["acos"] = (double(*)(double))&acos;
147 functions_["tan"] = (double(*)(double))&tan;
148 functions_["atan"] = (double(*)(double))&atan;
149 functions_["ln"] = (double(*)(double))&log;
150 functions_["exp"] = (double(*)(double))&exp;
151 functions_[""] = 0;
152 }
153
155}
156
157#endif // BALL_MATHS_PARSEDFUNCTION_H
double ParsedFunctionResult
void ParsedFunction_delBuffer()
int ParsedFunctionparse()
void ParsedFunction_initBuffer(const char *)
ParsedFunction()
Default constructor.
~ParsedFunction()
Destructor.
StringHashMap< double(*)(double)> * ParsedFunctionFunctions
StringHashMap< double * > * ParsedFunctionConstants
double operator()(arg p)
StringHashMap< double(*)(double)> functions_
StringHashMap< double * > constants_
#define BALL_EXPORT