forked from Conedy/Conedy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.h
247 lines (184 loc) · 4.88 KB
/
command.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#ifndef command_h
#define command_h command_h
#include "baseType.h"
#include <map>
#include <boost/function.hpp>
//#include "fullNetwork.h"
#include "node.h"
#define _baseType_ 1
#define _network_ 2
#define _node_ 3
#define _int_ 4
#define _string_ 5
#define _bool_ 6
using namespace std;
using namespace conedy;
//typedef dynNode nodeBlueprint;
//typedef edgeVirtual edgeBlueprint;
void emptyFunction();
namespace conedy {
class networkTemplate;
}
// is called by conedyCondor instead of network functions
typedef dynNode nodeBlueprint;
typedef edgeVirtual edgeBlueprint;
//! Alle Befehle erben von Command. Außerdem werden hier die Variablen gehandhabt.
class command
{
protected:
//! statische Zuordnung von Strings zum Type, der in einem Conedyskript deklariert wurde
static map < string, int > varType;
static map < string, baseType* > baseTypeVar;
static map < string, bool* > boolVar;
static map < string, int* > intVar;
static map < string, networkTemplate * > networkVar;
static map < string, nodeBlueprint ** > nodeVar;
static map < string, edgeBlueprint ** > edgeVar;
static map < string, string * > stringVar;
static map < string, nodeDescriptor*> nodeDescriptorVar;
static vector <string> inputFiles;
static bool contextCheck (string s, int type)
{ if ((varType.count(s) == 0 )|| (varType[s] != type)) return 0; else return 1;} // Überprüft, ob s als Variablenname vom Type type angemeldet wurde
public:
static void clear ();
static int getType(string s) {return varType[s]; }
static void addInputFile(string s) { inputFiles.push_back(s);};
static int addInputFileInt(string s) { inputFiles.push_back(s); return 0;};
//! delete all variables in the interpreter.
static void finalize();
template <typename T>
static T * retrieve(string s) { throw "retrieve-Error"; }
static void declare(string s, vector<baseType> *d)
{
#ifdef DEBUG
cout << "vector<doubles> are not supproted at the moment in the interpreter." << endl;
#endif
//throw "vector<doubles> sind im interpreter atm not implemented!";
}
static void declare(string s, bool *d)
{
if (varType.count(s) != 0)
{
cout << "String:" << s << endl;
cout << "VarType:" << varType[s] << endl;
throw "declared twice.";
}
varType[s] = _bool_;
boolVar[s] = d;
}
static void declare(string s, int *d)
{
if (varType.count(s) != 0)
{
cout << "String:" << s << endl;
cout << "VarType:" << varType[s] << endl;
throw "declared twice.";
}
varType[s] = _int_;
intVar[s] = d;
}
static void declare(string s, baseType *d)
{
if (varType.count(s) != 0)
{
cout << "String:" << s << endl;
cout << "VarType:" << varType[s] << endl;
throw "declared twice.";
}
varType[s] = _baseType_;
baseTypeVar[s] = d;
}
static void declare(string s, string *d)
{
if (varType.count(s) != 0)
{
cout << "String:" << s << endl;
cout << "VarType:" << varType[s] << endl;
throw "declared twice.";
}
varType[s] = _string_;
stringVar[s] = d;
}
static void printAll()
{
map <string, int>::iterator it;
for (it = varType.begin(); it != varType.end(); it++)
cout << it->first << " " << it->second << endl;
}
static void declare(string s, int type); // Meldet s als Variablenname an ( so wie bei "double d;")
command() {}
virtual ~command() {};
};
class instruction : public command
{
public:
virtual void execute() {};
};
//! Basis-Klasse für Ausdrücke im Parser-Baum vom Typ T
template <>
inline baseType * command ::retrieve<baseType> (string s)
{
if (!contextCheck (s, _baseType_))
throw (s +"ContextError!").c_str();
else
return baseTypeVar[s];
}
template <> inline bool * command ::retrieve<bool> (string s)
{
if (!contextCheck (s, _bool_))
throw (s +"ContextError!").c_str();
else
return boolVar[s];
}
template <> inline int * command ::retrieve<int> (string s)
{
if (!contextCheck (s, _int_))
throw (s +"ContextError!").c_str();
else
return intVar[s];
}
template <>
inline string * command ::retrieve<string> (string s)
{
if (!contextCheck (s, _string_))
throw (s +"ContextError!").c_str();
else
return stringVar[s];
}
template <>
inline networkTemplate * command::retrieve<networkTemplate> (string s)
{
if (!contextCheck (s, _network_))
{
cout << "ContextError!" << endl;
cout << "NetworkTemplate:" << s << endl;
exit(1);
}
else
return networkVar[s];
}
template <>
inline nodeBlueprint** command::retrieve<nodeBlueprint *> (string s)
{
if (!contextCheck (s, _node_))
{
cout << "ContextError!" << endl;
cout << "NodeTemplate:" << s << endl;
exit(1);
}
else
return nodeVar[s];
}
template <>
inline edgeBlueprint** command::retrieve<edgeBlueprint *> (string s)
{
if (!contextCheck (s, _edge_))
{
cout << "ContextError!" << endl;
cout << "EdgeTemplate:" << s << endl;
exit(1);
}
else
return edgeVar[s];
}
#endif