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

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

00001 #ifndef Or_h
00002 #define Or_h
00003 #include "Function.h"
00004 
00005 namespace cart
00006 {
00007     template <class T>
00008     class Or : public Function
00009     {
00010     public:
00011         Or();
00012         Or(uint numArgs);
00013         ~Or();
00014 
00015         void evaluate(voidP inputs, void* result);
00016     };
00017 
00018     typedef Or<uint> OrUint;
00019 
00020     template <class T>
00021     Or<T>::Or()
00022     {
00023         name_ = "OR";
00024         numOfArgs_ = 2;
00025     }
00026 
00027     template <class T>
00028     Or<T>::Or(uint numArgs)
00029     {
00030         name_ = "OR";
00031         numOfArgs_ = numArgs;
00032     }
00033 
00034     template <class T>
00035     Or<T>::~Or()
00036     {
00037     }
00038 
00039     template <class T>
00040     void Or<T>::evaluate(voidP inputs, void* result)
00041     {
00042         T& or_ = *(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         //size of inputs are not important in OR-ing because OR will not produce leading 1's instead of
00050         //leading 0's like NOT or XNOR function
00051         while (ss >> input)
00052         {
00053             readInputs.push_back(input);
00054             ss >> input;
00055             if (input > maxSize)
00056             {
00057                 maxSize = input;
00058             }
00059             i += 2;
00060             if (i == 2 * numOfArgs_)
00061             {
00062                 break;
00063             }
00064         }
00065 
00066         or_ = readInputs.at(0);
00067         for (int i = 1; i < (int)numOfArgs_; i++)
00068         {
00069             or_ |= readInputs.at(i);
00070         }
00071     }
00072 
00073 }
00074 
00075 #endif /* Or_h */

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