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 
00050 template <class EOT>
00051 class eoPopStat : public eoStat<EOT, std::string>
00052 {
00053 public:
00054 
00055     using eoStat<EOT, std::string>::value;
00056 
00061    eoPopStat(unsigned _howMany = 0, std::string _desc ="")
00062          : eoStat<EOT, std::string>("", _desc), combien( _howMany) {}
00063 
00068 void operator()(const eoPop<EOT>& _pop)
00069 {
00070   value() = "\n# ====== pop dump =====\n";
00071   unsigned howmany=combien?combien:_pop.size();
00072   for (unsigned i = 0; i < howmany; ++i)
00073   {
00074       std::ostringstream os;
00075       os << _pop[i] << std::endl;
00076 
00077       // paranoid:
00078       value() += os.str();
00079   }
00080 }
00081 
00082 private:
00083   unsigned combien;
00084 };
00085 
00095 template <class EOT>
00096 class eoSortedPopStat : public eoSortedStat<EOT, std::string>
00097 {
00098 public:
00099 
00100     using eoSortedStat<EOT, std::string>::value;
00101 
00107     eoSortedPopStat(unsigned _howMany = 0, std::string _desc ="")
00108         : eoSortedStat<EOT, std::string>("", _desc) , combien( _howMany)
00109         {}
00110 
00116     void operator()(const std::vector<const EOT*>& _pop)
00117         {
00118     value() = "";                  // empty
00119     unsigned howMany=combien?combien:_pop.size();
00120     for (unsigned i = 0; i < howMany; ++i)
00121       {
00122         std::ostringstream os;
00123         os << *_pop[i] << std::endl;
00124 
00125         // paranoid:
00126         value() += os.str();
00127       }
00128   }
00129 private:
00130   unsigned combien;
00131 };
00132 
00133 #endif

Generated on Thu Oct 19 05:06:37 2006 for EO by  doxygen 1.3.9.1