00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _eoOp_H
00026 #define _eoOp_H
00027
00028 #include <eoObject.h>
00029 #include <eoPrintable.h>
00030 #include <eoFunctor.h>
00031 #include <utils/eoRNG.h>
00058
00067 template<class EOType>
00068 class eoOp
00069 {
00070 public:
00072 enum OpType { unary = 0, binary = 1, quadratic = 2, general = 3};
00074
00076 eoOp(OpType _type)
00077 :opType( _type ) {};
00078
00080 eoOp( const eoOp& _eop )
00081 :opType( _eop.opType ) {};
00082
00084 virtual ~eoOp(){};
00085
00087 OpType getType() const {return opType;};
00088
00089 private:
00090
00092 OpType opType;
00093 };
00094
00100 template <class EOType>
00101 class eoMonOp: public eoOp<EOType>, public eoUF<EOType&, bool>
00102 {
00103 public:
00105 eoMonOp()
00106 : eoOp<EOType>( eoOp<EOType>::unary ) {};
00107 virtual std::string className() const {return "eoMonOp";};
00108 };
00109
00110
00116 template<class EOType>
00117 class eoBinOp: public eoOp<EOType>, public eoBF<EOType&, const EOType&, bool>
00118 {
00119 public:
00121 eoBinOp()
00122 :eoOp<EOType>( eoOp<EOType>::binary ) {};
00123 virtual std::string className() const {return "eoBinOp";};
00124 };
00125
00131 template<class EOType>
00132 class eoQuadOp: public eoOp<EOType>, public eoBF<EOType&, EOType&, bool> {
00133 public:
00135 eoQuadOp()
00136 :eoOp<EOType>( eoOp<EOType>::quadratic ) {};
00137 virtual std::string className() const {return "eoQuadOp";};
00138 };
00139
00142 template <class EOT>
00143 class eoQuad2BinOp: public eoBinOp<EOT>
00144 {
00145 public:
00149 eoQuad2BinOp(eoQuadOp<EOT> & _quadOp) : quadOp(_quadOp) {}
00150
00153 bool operator()(EOT & _eo1, const EOT & _eo2)
00154 {
00155 EOT eoTmp = _eo2;
00156
00157
00158 if (eo::rng.flip(0.5))
00159 return quadOp(_eo1, eoTmp);
00160 else
00161 return quadOp(eoTmp, _eo1);
00162 }
00163
00164 private:
00165 eoQuadOp<EOT> & quadOp;
00166 };
00167
00168 #endif
00169