eoDetSelect.h

00001 
00025 //-----------------------------------------------------------------------------
00026 
00027 #ifndef _eoDetSelect_h
00028 #define _eoDetSelect_h
00029 
00030 
00031 //-----------------------------------------------------------------------------
00032 #include <eoSelect.h>
00033 #include <utils/eoHowMany.h>
00034 #include <math.h>
00035 //-----------------------------------------------------------------------------
00036 
00039 template<class EOT>
00040 class eoDetSelect : public eoSelect<EOT>
00041 {
00042  public:
00044      eoDetSelect(double _rate = 1.0, bool _interpret_as_rate = true)
00045          : howMany(_rate, _interpret_as_rate)  {}
00046 
00053   virtual void operator()(const eoPop<EOT>& _source, eoPop<EOT>& _dest)
00054   {
00055     unsigned int pSize = _source.size();
00056     size_t target = howMany(pSize);
00057 
00058     _dest.resize(target);
00059 
00060     unsigned remain = target % pSize;
00061     unsigned entireCopy = target / pSize;
00062     typename eoPop<EOT>::iterator it = _dest.begin();
00063     
00064     if (target >= pSize)
00065       {
00066         for (unsigned i=0; i<entireCopy; i++)
00067           {
00068               std::copy(_source.begin(), _source.end(), it);
00069             it += pSize;
00070           }
00071       }
00072     // the last ones
00073     if (remain) 
00074       {
00075           std::copy(_source.begin(), _source.begin()+remain, it);
00076       }
00077   }
00078   
00079 private :
00080   eoHowMany howMany;
00081 };
00082 
00083 #endif

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