00001 #ifndef Xnor_h
00002 #define Xnor_h
00003 #include "Function.h"
00004
00005 namespace cart
00006 {
00007 template <class T>
00008 class Xnor : public Function
00009 {
00010 public:
00011 Xnor();
00012 Xnor(uint numArgs);
00013 ~Xnor();
00014
00015 void evaluate(voidP inputs, void* result);
00016 };
00017
00018 typedef Xnor<uint> XnorUint;
00019
00020 template <class T>
00021 Xnor<T>::Xnor()
00022 {
00023 name_ = "XNOR";
00024 numOfArgs_ = 2;
00025 }
00026
00027 template <class T>
00028 Xnor<T>::Xnor(uint numArgs)
00029 {
00030 name_ = "XNOR";
00031 numOfArgs_ = numArgs;
00032 }
00033
00034 template <class T>
00035 Xnor<T>::~Xnor()
00036 {
00037 }
00038
00039 template <class T>
00040 void Xnor<T>::evaluate(voidP inputs, void* result)
00041 {
00042 T& xnor = *(T*) result;
00043 stringstream ss;
00044 ss << *((string*) inputs.get());
00045 vector<T> readInputs;
00046 T input, maxSize = 0;
00047 uint i = 0;
00048
00049 while (ss >> input)
00050 {
00051 readInputs.push_back(input);
00052 ss >> input;
00053 if (input > maxSize)
00054 {
00055 maxSize = input;
00056 }
00057 i += 2;
00058 if (i == 2 * numOfArgs_)
00059 {
00060 break;
00061 }
00062 }
00063 T mask = (T)pow(2.0, maxSize + 1.0) - 1;
00064
00065 xnor = readInputs.at(0);
00066 for (int i = 1; i < (int)numOfArgs_; i++)
00067 {
00068 xnor = ~(xnor ^ readInputs.at(i));
00069
00070
00071 xnor &= mask;
00072 }
00073 }
00074
00075 }
00076
00077 #endif