From c95f5607d8575f463c227f3040dafeafb769ee67 Mon Sep 17 00:00:00 2001 From: nojhan Date: Tue, 28 Apr 2020 15:55:28 +0200 Subject: [PATCH] feat: add an intermediate layer of init with dimension --- eo/src/eoInit.h | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/eo/src/eoInit.h b/eo/src/eoInit.h index d9b4a0e30..88bc98999 100644 --- a/eo/src/eoInit.h +++ b/eo/src/eoInit.h @@ -28,6 +28,7 @@ #define _eoInit_H #include +#include #include "eoOp.h" #include "eoSTLFunctor.h" @@ -83,32 +84,50 @@ private: eoInit & init; }; +template +class eoInitWithDim : public eoInit +{ + public: + //! Sets the default dimension. + eoInitWithDim(unsigned dimension = 0) : + _dimension(dimension) + { } + + //! Get the current dimension. + unsigned dimension() const {return _dimension;} + + //! Set the current dimension. + void dimension(unsigned dimension) {assert(dimension > 0);_dimension = dimension;} + + protected: + unsigned _dimension; +}; + /** Initializer for fixed length representations with a single type */ template -class eoInitFixedLength: public eoInit +class eoInitFixedLength: public eoInitWithDim { public: typedef typename EOT::AtomType AtomType; - eoInitFixedLength(unsigned _dimension, eoRndGenerator& _generator) - : dim(_dimension), generator(_generator) {} + eoInitFixedLength(unsigned dimension, eoRndGenerator& generator) : + eoInitWithDim(dimension), + _generator(generator) + { } virtual void operator()(EOT& chrom) { - chrom.resize(dim); - std::generate(chrom.begin(), chrom.end(), generator); + chrom.resize(this->_dimension); + std::generate(chrom.begin(), chrom.end(), _generator); chrom.invalidate(); } - unsigned dimension() const {return dim;} - private : - unsigned dim; /// generic wrapper for eoFunctor (s), to make them have the function-pointer style copy semantics - eoSTLF generator; + eoSTLF _generator; }; /** @@ -162,7 +181,7 @@ private : Initializer for permutation (integer-based) representations. */ template -class eoInitPermutation: public eoInit +class eoInitPermutation: public eoInit // FIXME inherit from eoInitWithDim { public: