eoOp.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 //-----------------------------------------------------------------------------
00003 // eoOp.h
00004 // (c) GeNeura Team, 1998
00005 /* 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Lesser General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Lesser General Public License for more details.
00015 
00016     You should have received a copy of the GNU Lesser General Public
00017     License along with this library; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020     Contact: todos@geneura.ugr.es, http://geneura.ugr.es
00021     CVS Info: $Date: 2004/08/10 17:19:46 $ $Header: /cvsroot/eodev/eo/src/eoOp.h,v 1.29 2004/08/10 17:19:46 jmerelo Exp $ $Author: jmerelo $ 
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;              // a copy that can be modified
00156     // if the embedded eoQuadOp is not symmetrical,
00157     // the result might be biased - hence the flip ...
00158     if (eo::rng.flip(0.5))
00159       return quadOp(_eo1, eoTmp);          // both are modified - that's all
00160     else
00161       return quadOp(eoTmp, _eo1);          // both are modified - that's all
00162   }
00163 
00164 private:
00165   eoQuadOp<EOT> & quadOp;
00166 };
00167 
00168 #endif
00169 

Generated on Thu Oct 19 05:06:36 2006 for EO by  doxygen 1.3.9.1