/* * RandomNumberGeneratorFactory.hpp * * Created on: Dec 31, 2010 * Author: heber */ #ifndef RANDOMNUMBERGENERATORFACTORY_HPP_ #define RANDOMNUMBERGENERATORFACTORY_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/Singleton.hpp" #include "RandomNumberDistribution.hpp" #include "RandomNumberEngine.hpp" #include "RandomNumberGenerator.hpp" #include #include "TemplatePowerSetGenerator.hpp" #include "RandomNumberGeneratorFactory.def" #include "unittests/RandomNumberGeneratorFactoryUnitTest.hpp" /** This is the abstract factory class for random number generators. * * The reason for creating the generators as this is that we would like to set * the generator's parameters, via some Action, and then onward only have * random number generator of this type using these parameters. Hence, we have * a singleton factory that is controlled by the Action and can then create * generators wherever we like in the code by having the factory create one. * */ class RandomNumberGeneratorFactory : public Singleton { friend class Singleton; friend class RandomNumberGeneratorFactoryTest; public: protected: RandomNumberGeneratorFactory(); virtual ~RandomNumberGeneratorFactory(); public: /** Enumeration of all (pseudo-)random number engines implemented in * boost::random, see * http://www.boost.org/doc/libs/1_45_0/doc/html/boost_random/reference.html#boost_random.reference.concepts */ enum Engine { BOOST_PP_REPEAT( engine_seq_size, seqitems_as_enum, engine_seq) , BOOST_PP_REPEAT( engine_seq_a_size, seqitems_as_enum, engine_seq_a) }; /** Enumeration of all distribution implemented in random::boost. */ enum Distribution { BOOST_PP_REPEAT( distribution_seq_size, seqitems_as_enum, distribution_seq) }; /** Create a Generator of previously set type. * * \return random number generator instance */ RandomNumberGenerator& makeRandomNumberGenerator() const; /** Create a Generator of desired combination of engine and distribution. * * Note that this does not affect the default setting of the engine or * distribution type. * * \param engine_type name of engine, give empty string for current default * \param distribution_type name of distribution, give empty string for current default * \return random number generator instance */ RandomNumberGenerator& makeRandomNumberGenerator(std::string engine_type, std::string distribution_type) const; /** Specify the precise type of the engine to build * * @param name of engine */ void setEngine(std::string engine_type); /** Getter for current type of engine. * * @return name of engine */ const std::string &getEngine() const; /** Specify the precise type of the distribution to build * * @param name of distribution */ void setDistribution(std::string distribution_type); /** Getter for current type of distribution. * * @return name of distribution */ const std::string &getDistribution() const; protected: private: /** Creates instances of all possible (engine,distribution) combinations * and stores them in \a PrototypeTable. */ void FillPrototypeTables(); typedef std::map< std::string, enum Engine > EngineMap; typedef std::map< enum Engine, RandomNumberEngine * > EngineTable; typedef std::map< enum Engine, std::string > EngineNamesMap; typedef std::map< std::string, enum Distribution > DistributionMap; typedef std::map< enum Distribution, RandomNumberDistribution * > DistributionTable; typedef std::map< enum Distribution, std::string > DistributionNamesMap; typedef std::map< enum Engine, std::map< enum Distribution, RandomNumberGenerator *> > EngineDistributionTable; static enum Engine engine; static enum Distribution distribution; static EngineMap engines; static EngineTable EnginePrototypeTable; static EngineNamesMap engineNames; static DistributionMap distributions; static DistributionTable DistributionPrototypeTable; static DistributionNamesMap distributionNames; static EngineDistributionTable GeneratorPrototypeTable; }; #include "RandomNumberGeneratorFactory.undef" #endif /* RANDOMNUMBERGENERATORFACTORY_HPP_ */