EvolvingObjects
eoPopStat.h
00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // eoPopStat.h
00005 // (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
00006 /*
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     Contact: todos@geneura.ugr.es, http://geneura.ugr.es
00022              Marc.Schoenauer@polytechnique.fr
00023              mkeijzer@dhi.dk
00024  */
00025 //-----------------------------------------------------------------------------
00026 
00035 #ifndef _eoPopStat_h
00036 #define _eoPopStat_h
00037 
00038 #include <utils/eoStat.h>
00039 
00040 
00052 template <class EOT>
00053 class eoPopStat : public eoStat<EOT, std::string>
00054 {
00055 public:
00056 
00057     using eoStat<EOT, std::string>::value;
00058 
00063    eoPopStat(unsigned _howMany = 0, std::string _desc ="")
00064          : eoStat<EOT, std::string>("", _desc), combien( _howMany) {}
00065 
00070 void operator()(const eoPop<EOT>& _pop)
00071 {
00072   value() = "\n# ====== pop dump =====\n";
00073   unsigned howmany=combien?combien:_pop.size();
00074   for (unsigned i = 0; i < howmany; ++i)
00075   {
00076       std::ostringstream os;
00077       os << _pop[i] << std::endl;
00078 
00079       // paranoid:
00080       value() += os.str();
00081   }
00082 }
00083 
00084 private:
00085   unsigned combien;
00086 };
00087 
00099 template <class EOT>
00100 class eoSortedPopStat : public eoSortedStat<EOT, std::string>
00101 {
00102 public:
00103 
00104     using eoSortedStat<EOT, std::string>::value;
00105 
00111     eoSortedPopStat(unsigned _howMany = 0, std::string _desc ="")
00112         : eoSortedStat<EOT, std::string>("", _desc) , combien( _howMany)
00113         {}
00114 
00120     void operator()(const std::vector<const EOT*>& _pop)
00121         {
00122     value() = "";                  // empty
00123     unsigned howMany=combien?combien:_pop.size();
00124     for (unsigned i = 0; i < howMany; ++i)
00125       {
00126         std::ostringstream os;
00127         os << *_pop[i] << std::endl;
00128 
00129         // paranoid:
00130         value() += os.str();
00131       }
00132   }
00133 private:
00134   unsigned combien;
00135 };
00136 
00137 #endif
 All Classes Namespaces Files Functions Variables Typedefs Friends