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