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

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

00001 #ifndef Not_h
00002 #define Not_h
00003 #include "Function.h"
00004 
00005 namespace cart
00006 {
00007     template <class T>
00008     class Not : public Function
00009     {
00010     public:
00011         Not();
00012         ~Not();
00013 
00014         void evaluate(voidP inputs, void* result);
00015     };
00016 
00017     typedef Not<uint> NotUint;
00018 
00019     template <class T>
00020     Not<T>::Not()
00021     {
00022         name_ = "NOT";
00023         numOfArgs_ = 1;
00024     }
00025 
00026     template <class T>
00027     Not<T>::~Not()
00028     {
00029     }
00030 
00031     template <class T>
00032     void Not<T>::evaluate(voidP inputs, void* result)
00033     {
00034         T& neg = *(T*) result;
00035         stringstream ss;
00036         ss << *((string*) inputs.get());
00037         vector<T> readInputs;
00038         T input, maxSize = 0;
00039         uint i = 0;
00040         //received inputs are in format: input1 sizeOfInput1 input2 sizeOfInput2 ...
00041         while (ss >> input)
00042         {
00043             readInputs.push_back(input);
00044             ss >> input;
00045             if (input > maxSize)
00046             {
00047                 maxSize = input;
00048             }
00049             i += 2;
00050             if (i == 2 * numOfArgs_)
00051             {
00052                 break;
00053             }
00054         }
00055         T mask = (T)pow(2.0, maxSize + 1.0) - 1;
00056 
00057         neg = ~((T)readInputs.at(0));
00058         //masking is important in NOT operation because instead of leading 0's there would be 
00059         //leading 1's as most significant bits
00060         neg &= mask;
00061     }
00062 
00063 }
00064 
00065 #endif /* Not_h */

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