-
Notifications
You must be signed in to change notification settings - Fork 4
/
expression.h
190 lines (137 loc) · 3.98 KB
/
expression.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#ifndef __expression
#define __expression
#include "command.h"
#include <boost/function.hpp>
#include "dynNode.h"
using namespace boost;
template <typename T>
class expression : public instruction
{
public:
//! Werte den Ausdruck aus.
virtual T evaluate() { return (T)0; }
virtual void execute() { this->evaluate(); }
};
//! Ausdruck, der den Wert einer Varieblen zurückgibt
template <typename T>
class varCommand : public expression<T>
{
private:
T *target;
public:
varCommand (string s) { target = command::retrieve<T> (s); }
T evaluate() { return *target; };
void assign(T newData) { *target = newData; }
};
//! Ausdruck, der einen Konstanten Wert zurückgibt. Wird verwendet für alle Zahlen, die in den Conedy-Skripten stehen
template <typename T>
class constantCommand : public expression<T>
{
private:
const T value;
public:
constantCommand(T v) : value(v){};
T evaluate() { return value; };
};
//! Instruction mit einem Funktionszeiger.
template <typename T>
class bindExpression : public expression<T>
{
public:
boost::function<T ()> _f;
bindExpression(boost::function<T ()> f) : _f(f) {};
virtual T evaluate(){ return (_f)(); };
T operator()() { return (_f)(); };
};
template <typename T>
class randomVector : public command
{
private:
vector <bindExpression <T>*> vec;
public:
void push_back(bindExpression<T> *el) { vec.push_back(el); }
vector < function<T() > > evaluate()
{
vector<function <T()> > resVec;
for (unsigned int i = 0; i < vec.size(); i++)
resVec.push_back((baseType)vec[i]->_f);
return resVec;
}
};
class convertToNodeDescriptor : public expression <nodeDescriptor>
{
private:
expression<int> *nExp;
public:
convertToNodeDescriptor(expression<int> *n) : nExp(n) {};
nodeDescriptor evaluate() {
if (nExp->evaluate() < 0)
throw "Negative Node Number !";
return (nodeDescriptor)nExp->evaluate();
};
};
class fileNameExpression : public expression <string>
{
private:
expression<string> *sExp;
public:
fileNameExpression(expression<string> *n) : sExp(n) {};
virtual string evaluate()
{
command::addInputFile (sExp->evaluate());
return sExp->evaluate();
}
};
//! TODO hier ist irgendwas faul. Der bison macht da eventuell unendlich lange Bäume, wenn int und double ineinander umwandelbar sind.
class convertToInt : public expression <int>
{
private:
expression<baseType> *dExp;
public:
convertToInt(expression<baseType> *d) : dExp(d) {};
int evaluate() { return (nodeDescriptor)dExp->evaluate(); };
};
//! TODO hier ist irgendwas faul. Der bison macht da eventuell unendlich lange Bäume, wenn int und double ineinander umwandelbar sind.
class convertIntegerToBaseType : public expression <baseType>
{
private:
expression<int> *dExp;
public:
convertIntegerToBaseType(expression<int> *d) : dExp(d) {};
baseType evaluate() { return (baseType)dExp->evaluate(); };
};
//! Ausdruck für einen Vector
template <typename T>
class expressionVector : public command
{
private:
vector <expression <T>*> vec;
public:
void push_back(expression<T> *el) { vec.push_back(el); }
vector <T> evaluate()
{
vector<T> resVec;
for (unsigned int i = 0; i < vec.size(); i++)
resVec.push_back((T)vec[i]->evaluate());
return resVec;
}
};
class setNodeParameter : public expression<nodeBlueprint*>
{
private:
expressionVector<baseType> *parameter;
expression<nodeBlueprint *> *node;
public:
setNodeParameter (expressionVector<baseType> * p, expression<nodeBlueprint*> *n) : parameter(p), node(n) {}
virtual nodeBlueprint * evaluate() { ( (node->evaluate() ))-> params<baseType>::rerouteParams((parameter->evaluate())); return node->evaluate(); }
};
class setEdgeParameter : public expression<edgeBlueprint*>
{
private:
expressionVector<baseType> * parameter;
expression<edgeBlueprint *>* edge;
public:
setEdgeParameter (expressionVector<baseType>* p, expression<edgeBlueprint *> *e) : parameter(p), edge(e) {}
virtual edgeBlueprint* evaluate();
};
#endif