forked from Conedy/Conedy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.h
171 lines (125 loc) · 4 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
#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;
//typedef dynNode nodeBlueprint;
//typedef edgeVirtual edgeBlueprint;
void emptyFunction();
namespace conedy {
class networkTemplate;
}
// is called by conedyCondor instead of network functions
typedef conedy::dynNode nodeBlueprint;
typedef conedy::edgeVirtual edgeBlueprint;
typedef conedy::networkTemplate networkTemplate;
//! 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, conedy::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 <> baseType * command ::retrieve<baseType> (string s);
template <> bool * command ::retrieve<bool> (string s);
template <> int * command ::retrieve<int> (string s);
template <> string * command ::retrieve<string> (string s);
template <> networkTemplate * command::retrieve<networkTemplate> (string s);
template <> nodeBlueprint** command::retrieve<nodeBlueprint *> (string s);
template <> edgeBlueprint** command::retrieve<edgeBlueprint *> (string s);
#endif