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