ECF 1.5
Or.h
1#ifndef Or_h
2#define Or_h
3#include "Function.h"
4
5namespace cart
6{
7 template <class T>
8 class Or : public Function
9 {
10 public:
11 Or();
12 Or(uint numArgs);
13 ~Or();
14
15 void evaluate(voidP inputs, void* result);
16 };
17
18 typedef Or<uint> OrUint;
19
20 template <class T>
21 Or<T>::Or()
22 {
23 name_ = "OR";
24 numOfArgs_ = 2;
25 }
26
27 template <class T>
28 Or<T>::Or(uint numArgs)
29 {
30 name_ = "OR";
31 numOfArgs_ = numArgs;
32 }
33
34 template <class T>
36 {
37 }
38
39 template <class T>
40 void Or<T>::evaluate(voidP inputs, void* result)
41 {
42 T& or_ = *(T*) result;
43 stringstream ss;
44 ss << *((string*) inputs.get());
45 vector<T> readInputs;
46 T input, maxSize = 0;
47 uint i = 0;
48 //received inputs are in format: input1 sizeOfInput1 input2 sizeOfInput2 ...
49 //size of inputs are not important in OR-ing because OR will not produce leading 1's instead of
50 //leading 0's like NOT or XNOR function
51 while (ss >> input)
52 {
53 readInputs.push_back(input);
54 ss >> input;
55 if (input > maxSize)
56 {
57 maxSize = input;
58 }
59 i += 2;
60 if (i == 2 * numOfArgs_)
61 {
62 break;
63 }
64 }
65
66 or_ = readInputs.at(0);
67 for (int i = 1; i < (int)numOfArgs_; i++)
68 {
69 or_ |= readInputs.at(i);
70 }
71 }
72
73}
74
75#endif /* Or_h */
Definition: Or.h:9
void evaluate(voidP inputs, void *result)
Definition: Or.h:40