ECF 1.5
FunctionSet.cpp
1#include "FunctionSet.h"
2
3namespace cart {
4
6 {
7 type = gettype;
8 existFunc["+"] = true;
9 existFunc["-"] = true;
10 existFunc["*"] = true;
11 existFunc["/"] = true;
12 existFunc["sin"] = true;
13 existFunc["cos"] = true;
14 existFunc["AND"] = true;
15 existFunc["OR"] = true;
16 existFunc["NOT"] = true;
17 existFunc["XOR"] = true;
18 existFunc["XNOR"] = true;
19 }
20
21 bool FunctionSet::addFunction(string name)
22 {
23 if (!existFunc[name])
24 {
25 cerr << "FunctionSet error: Function " << name << " isn't implemented." << endl;
26 return false;
27 }
28
29 if (type == "double")
30 {
31 if (name == "+")
32 {
33 this->push_back((FunctionP) (new AddDouble));
34 }
35 else if (name == "-")
36 {
37 this->push_back((FunctionP) (new SubDouble));
38 }
39 else if (name == "*")
40 {
41 this->push_back((FunctionP) (new MulDouble));
42 }
43 else if (name == "/")
44 {
45 this->push_back((FunctionP) (new DivDouble));
46 }
47 else if (name == "sin")
48 {
49 this->push_back((FunctionP) (new SinDouble));
50 }
51 else if (name == "cos")
52 {
53 this->push_back((FunctionP) (new CosDouble));
54 }
55 else
56 {
57 cerr << "FunctionSet error: Unkown function name: " << name << endl;
58 return false;
59 }
60 }
61 else if (type == "int")
62 {
63 if (name == "+")
64 {
65 this->push_back((FunctionP) (new AddInt));
66 }
67 else if (name == "-")
68 {
69 this->push_back((FunctionP) (new SubInt));
70 }
71 else if (name == "*")
72 {
73 this->push_back((FunctionP) (new MulInt));
74 }
75 else if (name == "/")
76 {
77 this->push_back((FunctionP) (new DivInt));
78 }
79 else if (name == "sin")
80 {
81 this->push_back((FunctionP) (new SinInt));
82 }
83 else if (name == "cos")
84 {
85 this->push_back((FunctionP) (new CosInt));
86 }
87 else
88 {
89 cerr << "FunctionSet error: Unkown function name: " << name << endl;
90 return false;
91 }
92 }
93 else if (type == "uint")
94 {
95 if (name == "AND")
96 {
97 this->push_back((FunctionP) (new AndUint));
98 }
99 else if (name == "OR")
100 {
101 this->push_back((FunctionP) (new OrUint));
102 }
103 else if (name == "NOT")
104 {
105 this->push_back((FunctionP) (new NotUint));
106 }
107 else if (name == "XOR")
108 {
109 this->push_back((FunctionP) (new XorUint));
110 }
111 else if (name == "XNOR")
112 {
113 this->push_back((FunctionP) (new XnorUint));
114 }
115 else
116 {
117 cerr << "FunctionSet error: Unkown function name: " << name << endl;
118 return false;
119 }
120 }
121 else
122 {
123 cerr << "FunctionSet error: Unkown data type: " << type << endl;
124 return false;
125 }
126
127 return true;
128 }
129
130 bool FunctionSet::addFunction(string name, uint numArgs)
131 {
132 if (!existFunc[name])
133 {
134 cerr << "FunctionSet error: Function " << name << " isn't implemented." << endl;
135 return false;
136 }
137
138 if (type == "double")
139 {
140 if (name == "+")
141 {
142 this->push_back((FunctionP) (new AddDouble(numArgs)));
143 }
144 else if (name == "-")
145 {
146 this->push_back((FunctionP) (new SubDouble(numArgs)));
147 }
148 else if (name == "*")
149 {
150 this->push_back((FunctionP) (new MulDouble(numArgs)));
151 }
152 else if (name == "/")
153 {
154 this->push_back((FunctionP) (new DivDouble(numArgs)));
155 }
156 else
157 {
158 cerr << "FunctionSet error: Unkown function name: " << name;
159 cerr << " for " << numArgs << " arguments." << endl;
160 return false;
161 }
162 }
163 else if (type == "int")
164 {
165 if (name == "+")
166 {
167 this->push_back((FunctionP) (new AddInt(numArgs)));
168 }
169 else if (name == "-")
170 {
171 this->push_back((FunctionP) (new SubInt(numArgs)));
172 }
173 else if (name == "*")
174 {
175 this->push_back((FunctionP) (new MulInt(numArgs)));
176 }
177 else if (name == "/")
178 {
179 this->push_back((FunctionP) (new DivInt(numArgs)));
180 }
181 else
182 {
183 cerr << "FunctionSet error: Unkown function name: " << name;
184 cerr << " for " << numArgs << " arguments." << endl;
185 return false;
186 }
187 }
188 else if (type == "uint")
189 {
190 if (name == "AND")
191 {
192 this->push_back((FunctionP) (new AndUint(numArgs)));
193 }
194 else if (name == "OR")
195 {
196 this->push_back((FunctionP) (new OrUint(numArgs)));
197 }
198 else if (name == "XOR")
199 {
200 this->push_back((FunctionP) (new XorUint(numArgs)));
201 }
202 else if (name == "XNOR")
203 {
204 this->push_back((FunctionP) (new XnorUint(numArgs)));
205 }
206 else
207 {
208 cerr << "FunctionSet error: Unkown function name: " << name;
209 cerr << " for " << numArgs << " arguments." << endl;
210 return false;
211 }
212 }
213 else
214 {
215 cerr << "FunctionSet error: Unkown data type: " << type << endl;
216 return false;
217 }
218
219 return true;
220 }
221
222 void FunctionSet::evaluate(voidP inputs, void* result, uint funcNum)
223 {
224 this->at(funcNum)->evaluate(inputs, result);
225 }
226
227}
Definition: Add.h:9
Definition: And.h:9
Definition: Cos.h:10
Definition: Div.h:9
bool addFunction(string name)
Definition: FunctionSet.cpp:21
void evaluate(voidP inputs, void *result, uint funcNum)
FunctionSet(string gettype)
Definition: FunctionSet.cpp:5
Definition: Mul.h:9
Definition: Not.h:9
Definition: Or.h:9
Definition: Sin.h:10
Definition: Sub.h:9
Definition: Xnor.h:9
Definition: Xor.h:9