ECF 1.5
Add.h
1#ifndef Add_h
2#define Add_h
3#include "Function.h"
4
5namespace cart
6{
7 template <class T>
8 class Add : public Function
9 {
10 public:
11 Add();
12 Add(uint numArgs);
13 ~Add();
14
15 void evaluate(voidP inputs, void* result);
16 };
17
18 typedef Add<double> AddDouble;
19 typedef Add<int> AddInt;
20
21 template <class T>
23 {
24 name_ = "+";
25 numOfArgs_ = 2;
26 }
27
28 template <class T>
29 Add<T>::Add(uint numArgs)
30 {
31 name_ = "+";
32 numOfArgs_ = numArgs;
33 }
34
35 template <class T>
36 Add<T>::~Add()
37 {
38 }
39
40 template <class T>
41 void Add<T>::evaluate(voidP inputs, void* result)
42 {
43 T& sum = *(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 sum = readInputs.at(0);
60 for (int i = 1; i < (int)numOfArgs_; i++)
61 {
62 sum += readInputs.at(i);
63 }
64 }
65
66}
67
68#endif /* Add_h */
Definition: Add.h:9
void evaluate(voidP inputs, void *result)
Definition: Add.h:41