/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- ----------------------------------------------------------------------------- eoExternalEO.h Definition of an object that allows an external struct to be inserted in EO (c) Maarten Keijzer (mkeijzer@mad.scientist.com) and GeNeura Team, 1999, 2000 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact: todos@geneura.ugr.es, http://geneura.ugr.es */ #ifndef eoExternalEO_h #define eoExternalEO_h #include // EO /** * Definition of an object that allows an external struct * to be inserted in EO. This struct or class can be of any * form, the only thing this class does is attach a fitness * value to it and makes it the appropriate type (derives it from EO). * * @ingroup Utilities */ template class eoExternalEO : public EO, virtual public External { public : eoExternalEO() : External(), EO() {} /** Init externalEo with the struct itself and set fitness to zero */ eoExternalEO(const External& ext) : EO(), External(ext) {} eoExternalEO(std::istream& is, const External& ext) : EO(), External(ext) { readFrom(is); } /** * Read object, the external struct needs to have an operator>> defined */ virtual void readFrom(std::istream& _is) { EO::readFrom(_is); _is >> static_cast(*this); } /** * Write object. Called printOn since it prints the object _on_ a stream. * @param _os A std::ostream. */ virtual void printOn(std::ostream& _os) const { EO::printOn(_os); _os << static_cast(*this); } }; /** @example t-eoExternalEO.cpp */ /** To remove ambiguities between EO and External, streaming operators are defined yet again * @ingroup Utilities */ template std::ostream& operator<<(std::ostream& os, const eoExternalEO& eo) { eo.printOn(os); return os; } /** To remove ambiguities between EO and External, streaming operators are defined yet again * @ingroup Utilities */ template std::istream& operator>>(std::istream& is, eoExternalEO& eo) { eo.readFrom(is); return is; } #endif