ECF 1.5
Xnor.h
1#ifndef Xnor_h
2#define Xnor_h
3#include "Function.h"
4
5namespace cart
6{
7 template <class T>
8 class Xnor : public Function
9 {
10 public:
11 Xnor();
12 Xnor(uint numArgs);
13 ~Xnor();
14
15 void evaluate(voidP inputs, void* result);
16 };
17
18 typedef Xnor<uint> XnorUint;
19
20 template <class T>
22 {
23 name_ = "XNOR";
24 numOfArgs_ = 2;
25 }
26
27 template <class T>
28 Xnor<T>::Xnor(uint numArgs)
29 {
30 name_ = "XNOR";
31 numOfArgs_ = numArgs;
32 }
33
34 template <class T>
35 Xnor<T>::~Xnor()
36 {
37 }
38
39 template <class T>
40 void Xnor<T>::evaluate(voidP inputs, void* result)
41 {
42 T& xnor = *(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 while (ss >> input)
50 {
51 readInputs.push_back(input);
52 ss >> input;
53 if (input > maxSize)
54 {
55 maxSize = input;
56 }
57 i += 2;
58 if (i == 2 * numOfArgs_)
59 {
60 break;
61 }
62 }
63 T mask = (T)pow(2.0, maxSize + 1.0) - 1;
64
65 xnor = readInputs.at(0);
66 for (int i = 1; i < (int)numOfArgs_; i++)
67 {
68 xnor = ~(xnor ^ readInputs.at(i));
69 //masking is important in XNOR operation because instead of leading 0's there would be
70 //leading 1's as most significant bits
71 xnor &= mask;
72 }
73 }
74
75}
76
77#endif /* Xnor_h */
Definition: Xnor.h:9
void evaluate(voidP inputs, void *result)
Definition: Xnor.h:40