BALL
1.5.0
Loading...
Searching...
No Matches
include
BALL
MATHS
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
9
# include <
BALL/DATATYPE/stringHashMap.h
>
10
#endif
11
12
#include <numeric>
13
14
using
std::unary_function;
15
16
extern
double
ParsedFunctionResult
;
17
extern
int
ParsedFunctionparse
();
18
extern
void
ParsedFunction_initBuffer
(
const
char
*);
19
extern
void
ParsedFunction_delBuffer
();
20
21
namespace
BALL
22
{
26
extern
StringHashMap<double*> *
ParsedFunctionConstants
;
27
extern
StringHashMap<
double
(*)(
double
)> *
ParsedFunctionFunctions
;
28
36
template
<
typename
arg>
37
class
ParsedFunction
38
:
public
unary_function<arg, double>
39
{
40
public
:
44
46
ParsedFunction
();
47
49
ParsedFunction
(
const
String
& expression);
50
52
ParsedFunction
(
const
ParsedFunction
& func);
53
55
~ParsedFunction
();
56
58
62
65
double
operator ()
(arg p);
66
68
71
73
void
initTable
();
75
78
StringHashMap<double*>
constants_
;
79
82
StringHashMap
<
double
(*)(
double
)>
functions_
;
83
84
protected
:
85
String
expression_
;
86
};
87
88
template
<
typename
arg>
89
ParsedFunction<arg>::ParsedFunction
()
90
:
constants_
(),
91
functions_
(),
92
expression_
(
""
)
93
{
94
initTable
();
95
}
96
97
template
<
typename
arg>
98
ParsedFunction<arg>::ParsedFunction
(
const
String
& expression)
99
:
constants_
(),
100
functions_
(),
101
expression_
(expression)
102
{
103
initTable
();
104
}
105
106
template
<
typename
arg>
107
ParsedFunction<arg>::ParsedFunction
(
const
ParsedFunction
& func)
108
{
109
constants_
= func.
constants_
;
110
functions_
= func.
functions_
;
111
expression_
= func.
expression_
;
112
initTable
();
113
}
114
115
template
<
typename
arg>
116
ParsedFunction<arg>::~ParsedFunction
()
117
{
118
}
119
120
template
<
typename
arg>
121
double
ParsedFunction<arg>::operator ()
(arg argument)
122
{
123
constants_
[
"X"
] = (
double
*)&argument;
124
ParsedFunctionConstants
= &
constants_
;
125
ParsedFunctionFunctions
= &
functions_
;
126
ParsedFunction_initBuffer
(
expression_
.c_str());
127
ParsedFunctionparse
();
128
ParsedFunction_delBuffer
();
129
130
return
ParsedFunctionResult
;
131
}
132
133
template
<>
134
BALL_EXPORT
double
ParsedFunction<float>::operator ()
(
float
argument);
135
136
template
<>
137
BALL_EXPORT
double
ParsedFunction<double>::operator ()
(
double
argument);
138
139
template
<
typename
arg>
140
void
ParsedFunction<arg>::initTable
()
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
BALL_EXPORT
#define BALL_EXPORT
Definition
COMMON/global.h:50
BALL::ParsedFunction::expression_
String expression_
Definition
parsedFunction.h:85
BALL::ParsedFunction::functions_
StringHashMap< double(*)(double)> functions_
Definition
parsedFunction.h:82
BALL::ParsedFunction::constants_
StringHashMap< double * > constants_
Definition
parsedFunction.h:78
BALL::StringHashMap
Definition
stringHashMap.h:42
BALL::String
Definition
string.h:57
double
BALL::ParsedFunction::initTable
void initTable()
Definition
parsedFunction.h:140
BALL::ParsedFunction::ParsedFunction
ParsedFunction()
Default constructor.
Definition
parsedFunction.h:89
BALL::ParsedFunction::~ParsedFunction
~ParsedFunction()
Destructor.
Definition
parsedFunction.h:116
BALL::ParsedFunctionFunctions
StringHashMap< double(*)(double)> * ParsedFunctionFunctions
BALL::ParsedFunctionConstants
StringHashMap< double * > * ParsedFunctionConstants
BALL::ParsedFunction::operator()
double operator()(arg p)
Definition
parsedFunction.h:121
BALL
Definition
constants.h:13
ParsedFunctionResult
double ParsedFunctionResult
ParsedFunction_delBuffer
void ParsedFunction_delBuffer()
ParsedFunctionparse
int ParsedFunctionparse()
ParsedFunction_initBuffer
void ParsedFunction_initBuffer(const char *)
stringHashMap.h
Generated by
1.15.0