/* * RandomNumberEngineFactory.hpp * * Created on: Jan 03, 2011 * Author: heber */ #ifndef RANDOMNUMBERENGINEFACTORY_HPP_ #define RANDOMNUMBERENGINEFACTORY_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/Singleton.hpp" #include #include "TemplatePowerSetGenerator.hpp" #include "RandomNumberEngineFactory.def" #include "unittests/RandomNumberEngineFactoryUnitTest.hpp" #include "RandomNumberEngine_Creator.hpp" class RandomNumberEngine; /** This is the abstract factory class for random number engines. * * The reason for creating the engines as this is that we would like to set * the engines parameters, via some Action, and then onward only have * random number engines of this type using these parameters. Hence, we have * a singleton factory that is controlled by the Action and can then create * engines wherever we like in the code by having the factory create one. * */ class RandomNumberEngineFactory : public Singleton { friend class Singleton; friend class RandomNumberEngineFactoryTest; public: protected: RandomNumberEngineFactory(); virtual ~RandomNumberEngineFactory(); 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) }; /** Getter for current type of engine. * * @param enumeration index of engine * @return reference to copy of engine */ RandomNumberEngine* getEngine(enum Engine engine_type) const; /** Getter for current type of engine. * * @param name of engine * @return reference to copy of engine */ RandomNumberEngine* getEngine(const std::string engine_name) const; /** Getter for the name of the current type of engine. * * @return name of engine */ const std::string &getName(enum Engine engine_type) const; /** Getter for the enumeration index of the current type of engine. * * @return enum of engine */ enum Engine getEnum(const std::string engine_name) const; protected: private: /** Creates instances of all possible engine types * and stores them in \a EnginePrototypeTable. */ void FillPrototypeTable(); /** Create association for enums to strings and vice versa * and stores them in \a engines tables. */ void FillEnumTable(); typedef std::map< std::string, enum Engine > EngineMap; typedef std::map< enum Engine, IRandomNumberEngine_Creator * > EngineTable; typedef std::map< enum Engine, std::string > EngineNamesMap; //static enum Engine engine; static EngineMap engines; static EngineTable EnginePrototypeTable; static EngineNamesMap engineNames; }; #include "RandomNumberEngineFactory.undef" #endif /* RANDOMNUMBERENGINEFACTORY_HPP_ */