//----------------------------------------------------------------------------- // eoBin.h //----------------------------------------------------------------------------- #ifndef eoBin_h #define eoBin_h //----------------------------------------------------------------------------- #include // ostream, istream #include // bind2nd #include // string #include // EO /** eoBin: implementation of binary chromosome. * based on STL's bit_vector (vector). */ template class eoBin: public eoVector { public: /** * (Default) Constructor. * @param size Size of the binary string. */ eoBin(unsigned size = 0, bool value = false): eoVector(size, value) {} /** * Constructor. * @param size Size of the binary string. */ eoBin(unsigned size, const eoRnd& rnd): eoVector(size) { generate(begin(), end(), rnd); } /** Constructor from istream. @param is The istream to read from.*/ eoBin(istream& _is):eoVector(_is){}; /// My class name. string className() const { return "eoBin"; } /** * 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. */ void readFrom(istream& is) { string bits; is >> bits; if (is) { resize(bits.size()); transform(bits.begin(), bits.end(), begin(), bind2nd(equal_to(), '1')); } } }; //----------------------------------------------------------------------------- #endif eoBin_h