DistributionRegistry.h

Go to the documentation of this file.
00001 /*
00002  *  BEEN: Benchmarking Environment
00003  *  ==============================
00004  *
00005  *  File author: Branislav Repcek
00006  *
00007  *  GNU Lesser General Public License Version 2.1
00008  *  ---------------------------------------------
00009  *  Copyright (C) 2004-2006 Distributed Systems Research Group,
00010  *  Faculty of Mathematics and Physics, Charles University in Prague
00011  *
00012  *  This library is free software; you can redistribute it and/or
00013  *  modify it under the terms of the GNU Lesser General Public
00014  *  License version 2.1, as published by the Free Software Foundation.
00015  *
00016  *  This library is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  *  Lesser General Public License for more details.
00020  *
00021  *  You should have received a copy of the GNU Lesser General Public
00022  *  License along with this library; if not, write to the Free Software
00023  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024  *  MA  02111-1307  USA
00025  */
00026 
00034 #ifndef DISTRIBUTION_REGISTRY_INCLUDED
00035 #define DISTRIBUTION_REGISTRY_INCLUDED
00036 
00037 #include <vector>
00038 #include "Distribution.h"
00039 #include "DefaultDistribution.h"
00040 
00045 #define AUTO_FREE_DISTRIBUTIONS 1
00046 
00047 namespace hwdet
00048 {
00056     class DistributionRegistry
00057     {
00058     public:
00064         DistributionRegistry(MessageReporter *parent_reporter) :
00065         default_distro(new DefaultDistribution(parent_reporter))
00066         {
00067         }
00068         
00070         ~DistributionRegistry(void)
00071         {
00072 #if AUTO_FREE_DISTRIBUTIONS != 0
00073             // Destroy all registered distros.
00074             for (std::vector< Distribution * >::iterator it = registry.begin();
00075                  it != registry.end();
00076                  ++it)
00077             {
00078                 delete (*it);
00079             }
00080 #endif
00081             delete default_distro;
00082         }
00083         
00088         void Register(Distribution *distro)
00089         {
00090             if (distro)
00091             {
00092                 registry.push_back(distro);
00093             }
00094         }
00095         
00109         Distribution *GetBestFit(void)
00110         {
00111             Distribution *current_best = default_distro;
00112             float        best_fitness = default_distro->GetFitness();
00113             
00114             for (std::vector< Distribution * >::iterator it = registry.begin();
00115                  it != registry.end();
00116                  ++it)
00117             {
00118                 // Is this one better than the current best?
00119                 if ((*it)->GetFitness() > best_fitness)
00120                 {
00121                     // Yep -> update current best
00122                     best_fitness = (*it)->GetFitness();
00123                     current_best = *it;
00124                 }
00125             }
00126             
00127             return current_best;
00128         }
00129         
00130     private:
00132         std::vector< Distribution * > registry;
00133         
00135         DefaultDistribution           *default_distro;
00136         
00139         DistributionRegistry(const DistributionRegistry &) { }
00140         
00145         DistributionRegistry operator =(const DistributionRegistry &);
00146     };
00147 }
00148 
00149 #endif

Generated on Tue Dec 19 17:43:51 2006 for Detector for Linux by  doxygen 1.4.7