BALL
1.4.2
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
65
double
operator ()
(arg p);
66
68
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
Generated by
1.8.3.1