inherit eoCombinedContinue from std::vector, instead of having it as a member, so that we can easily manipulate continuators themselves

This commit is contained in:
nojhan 2012-03-26 18:15:45 +02:00
commit 47447c4765

View file

@ -19,6 +19,11 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: todos@geneura.ugr.es, http://geneura.ugr.es Contact: todos@geneura.ugr.es, http://geneura.ugr.es
Authors :
todos@geneura.ugr.es
Marc Schoenauer
Ramón Casero Cañas
Johann Dréo
*/ */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -40,7 +45,7 @@
@ingroup Combination @ingroup Combination
*/ */
template< class EOT> template< class EOT>
class eoCombinedContinue: public eoContinue<EOT> { class eoCombinedContinue: public eoContinue<EOT>, public std::vector<eoContinue<EOT>* > {
public: public:
/// Define Fitness /// Define Fitness
@ -48,45 +53,45 @@ public:
/// Ctor, make sure that at least on continuator is present /// Ctor, make sure that at least on continuator is present
eoCombinedContinue( eoContinue<EOT>& _cont) eoCombinedContinue( eoContinue<EOT>& _cont)
: eoContinue<EOT> () : eoContinue<EOT>(), std::vector<eoContinue<EOT>* >(1, &_cont)
{ {
continuators.push_back(&_cont);
} }
/// Ctor - for historical reasons ... should disspear some day /// Ctor - for historical reasons ... should disspear some day
eoCombinedContinue( eoContinue<EOT>& _cont1, eoContinue<EOT>& _cont2) eoCombinedContinue( eoContinue<EOT>& _cont1, eoContinue<EOT>& _cont2)
: eoContinue<EOT> () : eoContinue<EOT>(), std::vector<eoContinue<EOT>* >()
{ {
continuators.push_back(&_cont1); #pragma message "The double continuators constructor of eocombinedContinue is deprecated and will be removed in the next release."
continuators.push_back(&_cont2);
this->push_back(&_cont1);
this->push_back(&_cont2);
} }
void add(eoContinue<EOT> & _cont) void add(eoContinue<EOT> & _cont)
{ {
continuators.push_back(&_cont); this->push_back(&_cont);
} }
///////////// RAMON'S CODE ///////////////
void removeLast(void) void removeLast(void)
{ {
continuators.pop_back(); #pragma message "The removeLast method of eocombinedContinue is deprecated and will be removed in the next release, use pop_back instead."
this->pop_back();
} }
///////////// RAMON'S CODE (end) ///////////////
/** Returns false when one of the embedded continuators say so (logical and) /** Returns false when one of the embedded continuators say so (logical and)
*/ */
virtual bool operator() ( const eoPop<EOT>& _pop ) virtual bool operator() ( const eoPop<EOT>& _pop )
{ {
for (unsigned i = 0; i < continuators.size(); ++i) for (unsigned i = 0; i < this->size(); ++i)
if ( !(*continuators[i])(_pop) ) return false; if ( ! (*this->at(i))(_pop) ) return false;
return true; return true;
} }
virtual std::string className(void) const { return "eoCombinedContinue"; } virtual std::string className(void) const { return "eoCombinedContinue"; }
private: //private:
std::vector<eoContinue<EOT>*> continuators; // std::vector<eoContinue<EOT>*> continuators;
}; };
#endif #endif