From 9d1fdcd126ff7a70178d50c438260958b9e45d25 Mon Sep 17 00:00:00 2001 From: gustavo Date: Wed, 10 Feb 1999 13:39:48 +0000 Subject: [PATCH] small bug fixes --- eo/src/eoBin.h | 52 +++++++++++++++++++++++++++-------------------- eo/src/eoVector.h | 6 ++++-- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/eo/src/eoBin.h b/eo/src/eoBin.h index 85574a08..91ce6b09 100644 --- a/eo/src/eoBin.h +++ b/eo/src/eoBin.h @@ -7,36 +7,40 @@ //----------------------------------------------------------------------------- -#include // ostream, istream -#include // bind2nd +#include // ostream, istream +#include // bind2nd +#include // string +#include // EO -#include // string -#include // EO +/***************************************************************************** + * eoBin: implementation of binary chromosome. * + * based on STL's bit_vector (vector). * + *****************************************************************************/ -//----------------------------------------------------------------------------- -/** eoBin: implementation of binary chromosome. - based on STL's bit_vector (vector)*/ -//----------------------------------------------------------------------------- - -template class eoBin: public eoVector +template class eoBin: public eoVector { public: - typedef bool Type; - /// (Default) Constructor. - /// @param size Size of the binary string. + /** + * (Default) Constructor. + * @param size Size of the binary string. + */ eoBin(const unsigned& size = 0, const bool& value = false): eoVector(size, value) {} - - /// (Default) Constructor. - /// @param size Size of the binary string. + + /** + * Constructor. + * @param size Size of the binary string. + */ eoBin(const unsigned& size, const eoRnd& rnd): eoVector(size) { generate(begin(), end(), rnd); } - /// Constructor from istream. - /// @param is The istream to read from. + /** + * Constructor from istream. + * @param is The istream to read from. + */ eoBin(istrstream& is) { readFrom(is); @@ -48,15 +52,19 @@ template class eoBin: public eoVector return "eoBin"; } - /// To print me on a stream. - /// @param os The ostream. + /** + * To print me on a stream. + * @param os The ostream. + */ void printOn(ostream& os) const { copy(begin(), end(), ostream_iterator(os)); } - /// To read me from a stream. - /// @param is The istream. + /** + * To read me from a stream. + * @param is The istream. + */ void readFrom(istream& is) { string bits; diff --git a/eo/src/eoVector.h b/eo/src/eoVector.h index 02244721..a70723b7 100644 --- a/eo/src/eoVector.h +++ b/eo/src/eoVector.h @@ -24,6 +24,8 @@ template class eoVector: public eo1d, public vector { public: + typedef Type T; + /// Canonical part of the objects: several ctors, copy ctor, dtor and assignment operator //@{ @@ -31,7 +33,7 @@ public: @param _size Lineal length of the object @param _val Common initial value */ - eoVector( unsigned _size, T _val = 0) + eoVector( unsigned _size = 0, T _val = 0) : eo1d(), vector( _size, _val ){ }; /** Ctor using a random number generator @@ -80,7 +82,7 @@ which is supposed to be dynamic and dependent on environment. virtual T& gene( unsigned _i ) { if ( _i >= size() ) throw out_of_range( "out_of_range when writing a gene"); - return (*this)[_i]; + return operator[](_i); }; /** methods that implement the eo1d protocol