📄 eoexternaleo.h
字号:
/* -*- 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.h> // 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).*/template <class Fit, class External>class eoExternalEO : public EO<Fit>, virtual public External{public : eoExternalEO() : EO<Fit>(), External() {} /** Init externalEo with the struct itself and set fitness to zero */ eoExternalEO(const External& ext) : EO<Fit>(), External(ext) {} eoExternalEO(std::istream& is, const External& ext) : EO<Fit>(), External(ext) { readFrom(is); } /** * Read object, the external struct needs to have an operator>> defined */ virtual void readFrom(std::istream& _is) { EO<Fit>::readFrom(_is); _is >> static_cast<External&>(*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<Fit>::printOn(_os); _os << static_cast<const External&>(*this); }};/// To remove ambiguities between EO<F> and External, streaming operators are defined yet againtemplate <class F, class External>std::ostream& operator<<(std::ostream& os, const eoExternalEO<F, External>& eo){ eo.printOn(os); return os;}/// To remove ambiguities between EO<F> and External, streaming operators are defined yet againtemplate <class F, class External>std::istream& operator>>(std::istream& is, eoExternalEO<F, External>& eo){ eo.readFrom(is); return is;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -