ECF 1.5
Sub.h
1#ifndef Sub_h
2#define Sub_h
3#include "Function.h"
4
5namespace cart
6{
7 template <class T>
8 class Sub : public Function
9 {
10 public:
11 Sub();
12 Sub(uint numArgs);
13 ~Sub();
14
15 void evaluate(voidP inputs, void* result);
16 };
17
18 typedef Sub<double> SubDouble;
19 typedef Sub<int> SubInt;
20
21 template <class T>
23 {
24 name_ = "-";
25 numOfArgs_ = 2;
26 }
27
28 template <class T>
29 Sub<T>::Sub(uint numArgs)
30 {
31 name_ = "-";
32 numOfArgs_ = numArgs;
33 }
34
35 template <class T>
36 Sub<T>::~Sub()
37 {
38 }
39
40 template <class T>
41 void Sub<T>::evaluate(voidP inputs, void* result)
42 {
43 T& diff = *(T*) result;
44 stringstream ss;
45 ss << *((string*) inputs.get());
46 vector<T> readInputs;
47 T input;
48 uint i = 0;
49 while (ss >> input)
50 {
51 readInputs.push_back(input);
52 ++i;
53 if (i == numOfArgs_)
54 {
55 break;
56 }
57 }
58
59 diff = readInputs.at(0);
60 for (int i = 1; i < (int)numOfArgs_; i++)
61 {
62 diff -= readInputs.at(i);
63 }
64 }
65
66}
67
68#endif /* Sub_h */
Definition: Sub.h:9
void evaluate(voidP inputs, void *result)
Definition: Sub.h:41