EvolvingObjects
eoSelectMany.h
00001 
00025 //-----------------------------------------------------------------------------
00026 
00027 #ifndef _eoSelectMany_h
00028 #define _eoSelectMany_h
00029 
00030 
00031 //-----------------------------------------------------------------------------
00032 #include <eoSelect.h>
00033 #include <eoSelectOne.h>
00034 #include <utils/eoHowMany.h>
00035 #include <math.h>
00036 //-----------------------------------------------------------------------------
00037 
00046 template<class EOT>
00047 class eoSelectMany : public eoSelect<EOT>
00048 {
00049  public:
00051      eoSelectMany(eoSelectOne<EOT>& _select,
00052                     double  _rate, bool _interpret_as_rate = true)
00053          : select(_select), howMany(_rate, _interpret_as_rate) {}
00054 
00055      // Ctor with eoHowMany
00056      eoSelectMany(eoSelectOne<EOT>& _select, eoHowMany _howMany)
00057          : select(_select), howMany(_howMany) {}
00058 
00065   virtual void operator()(const eoPop<EOT>& _source, eoPop<EOT>& _dest)
00066   {
00067     unsigned target = howMany(_source.size());
00068 
00069     _dest.resize(target);
00070 
00071     select.setup(_source);
00072 
00073     for (size_t i = 0; i < _dest.size(); ++i)
00074       _dest[i] = select(_source);
00075   }
00076 
00077 private :
00078   eoSelectOne<EOT>& select;
00079   eoHowMany howMany;
00080 };
00081 
00082 #endif
 All Classes Namespaces Files Functions Variables Typedefs Friends