• Main Page
  • Modules
  • Classes
  • Files
  • File List

D:/Projekt/ECF_trunk/ECF/cartesian/Xnor.h

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         //received inputs are in format: input1 sizeOfInput1 input2 sizeOfInput2 ...
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             //masking is important in XNOR operation because instead of leading 0's there would be 
00070             //leading 1's as most significant bits
00071             xnor &= mask;
00072         }
00073     }
00074 
00075 }
00076 
00077 #endif /* Xnor_h */

Generated on Tue Nov 4 2014 13:04:30 for ECF by  doxygen 1.7.1