ECF 1.5
Not.h
1#ifndef Not_h
2#define Not_h
3#include "Function.h"
4
5namespace cart
6{
7 template <class T>
8 class Not : public Function
9 {
10 public:
11 Not();
12 ~Not();
13
14 void evaluate(voidP inputs, void* result);
15 };
16
17 typedef Not<uint> NotUint;
18
19 template <class T>
21 {
22 name_ = "NOT";
23 numOfArgs_ = 1;
24 }
25
26 template <class T>
28 {
29 }
30
31 template <class T>
32 void Not<T>::evaluate(voidP inputs, void* result)
33 {
34 T& neg = *(T*) result;
35 stringstream ss;
36 ss << *((string*) inputs.get());
37 vector<T> readInputs;
38 T input, maxSize = 0;
39 uint i = 0;
40 //received inputs are in format: input1 sizeOfInput1 input2 sizeOfInput2 ...
41 while (ss >> input)
42 {
43 readInputs.push_back(input);
44 ss >> input;
45 if (input > maxSize)
46 {
47 maxSize = input;
48 }
49 i += 2;
50 if (i == 2 * numOfArgs_)
51 {
52 break;
53 }
54 }
55 T mask = (T)pow(2.0, maxSize + 1.0) - 1;
56
57 neg = ~((T)readInputs.at(0));
58 //masking is important in NOT operation because instead of leading 0's there would be
59 //leading 1's as most significant bits
60 neg &= mask;
61 }
62
63}
64
65#endif /* Not_h */
Definition: Not.h:9
void evaluate(voidP inputs, void *result)
Definition: Not.h:32