Changeset 1d5a871 for src/RandomNumbers
- Timestamp:
- Feb 3, 2011, 9:51:19 AM (14 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 076a77
- Parents:
- c9bc2b7
- git-author:
- Frederik Heber <heber@…> (01/04/11 12:09:44)
- git-committer:
- Frederik Heber <heber@…> (02/03/11 09:51:19)
- Location:
- src/RandomNumbers
- Files:
-
- 2 added
- 4 deleted
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
src/RandomNumbers/RandomNumberDistributionFactory.cpp
rc9bc2b7 r1d5a871 10 10 * 11 11 * Created on: Jan 03, 2011 12 *Author: heber12 Author: heber 13 13 */ 14 14 … … 41 41 #include <boost/random/uniform_smallint.hpp> 42 42 43 #include <boost/preprocessor/facilities/empty.hpp>44 #include <boost/preprocessor/punctuation/paren.hpp>45 46 #include "TemplatePowerSetGenerator.hpp"47 #include "EmptyPrototypeTable.hpp"48 49 43 #include "RandomNumberDistribution_Encapsulation.hpp" 50 44 51 45 #include "RandomNumberDistributionFactory.hpp" 46 47 // has to be included BEFORE Factory_impl.hpp! 52 48 #include "RandomNumberDistributionFactory.def" 49 #include "CodePatterns/Factory_impl.hpp" 53 50 54 //enum RandomNumberDistributionFactory::Distribution RandomNumberDistributionFactory::distribution = (enum RandomNumberDistributionFactory::Distribution) 0; 55 RandomNumberDistributionFactory::DistributionMap RandomNumberDistributionFactory::distributions; 56 RandomNumberDistributionFactory::DistributionNamesMap RandomNumberDistributionFactory::distributionNames; 57 RandomNumberDistributionFactory::DistributionTable RandomNumberDistributionFactory::DistributionPrototypeTable; 58 59 60 RandomNumberDistributionFactory::RandomNumberDistributionFactory() 61 { 62 FillEnumTable(); 63 FillPrototypeTable(); 64 } 65 66 RandomNumberDistributionFactory::~RandomNumberDistributionFactory() 67 { 68 // clear out factories map to allow boost::shared_ptr to do their work (i.e. to release mem) 69 // this is necessary as factories is a object 70 distributions.clear(); 71 distributionNames.clear(); 72 EmptyPrototypeTable<DistributionTable> (DistributionPrototypeTable); 73 } 74 75 void RandomNumberDistributionFactory::FillEnumTable() 76 { 77 // insert all known distributions 78 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_string_enum_map(~, n, distribution_seq, distributions) 79 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(distribution_seq)-1 ) 80 #include BOOST_PP_LOCAL_ITERATE() 81 for (DistributionMap::const_iterator iter = distributions.begin(); 82 iter != distributions.end(); 83 ++iter) { 84 distributionNames.insert(make_pair(iter->second, iter->first)); 85 } 86 } 87 88 void RandomNumberDistributionFactory::FillPrototypeTable() 89 { 90 // fill DistributionPrototypeTable 91 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_map(~, n, distribution_seq, DistributionPrototypeTable, new RandomNumberDistribution_Creator< RandomNumberDistribution_Encapsulation, boost::, <> > ) 92 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(distribution_seq)-1 ) 93 #include BOOST_PP_LOCAL_ITERATE() 94 } 95 96 RandomNumberDistribution* RandomNumberDistributionFactory::getDistribution(enum Distribution distribution_type) const 97 { 98 return DistributionPrototypeTable[distribution_type]->create(); 99 } 100 101 RandomNumberDistribution* RandomNumberDistributionFactory::getDistribution(const std::string distribution_name) const 102 { 103 ASSERT(distributions.count(distribution_name) != 0, 104 "RandomNumberDistributionFactory::getDistribution() - distribution "+distribution_name+" is not registered."); 105 return DistributionPrototypeTable[ distributions[distribution_name] ]->create(); 106 } 107 108 const std::string &RandomNumberDistributionFactory::getName(enum Distribution distribution_type) const 109 { 110 return distributionNames[distribution_type]; 111 } 112 113 enum RandomNumberDistributionFactory::Distribution RandomNumberDistributionFactory::getEnum(const std::string distribution_name) const 114 { 115 ASSERT(distributions.count(distribution_name) != 0, 116 "RandomNumberDistributionFactory::getEnum() - distribution "+distribution_name+" is not registered."); 117 return distributions[distribution_name]; 118 } 51 RandomNumberDistributionFactory::RandomNumberDistributionFactory() {} 52 RandomNumberDistributionFactory::~RandomNumberDistributionFactory() {} 119 53 120 54 CONSTRUCT_SINGLETON(RandomNumberDistributionFactory) 55 CONSTRUCT_FACTORY(RandomNumberDistribution) 121 56 122 57 #include "RandomNumberDistributionFactory.undef" -
src/RandomNumbers/RandomNumberDistributionFactory.def
rc9bc2b7 r1d5a871 5 5 * see see http://www.boost.org/doc/libs/1_45_0/doc/html/boost_random/reference.html#boost_random.reference.concepts 6 6 */ 7 #define distribution_seq \7 #define type_seq \ 8 8 (uniform_smallint)\ 9 9 (uniform_int) … … 24 24 (uniform_on_sphere) 25 25 */ 26 #define distribution_seq_size BOOST_PP_SEQ_SIZE(distribution_seq) 26 27 #define Abstract_Interface_Class RandomNumberDistribution 28 #define Abstract_Encapsulation_Class RandomNumberDistribution_Encapsulation 29 #define type_name_space boost:: 30 #define type_name_space_suffix <> 27 31 28 32 #endif /* RANDOMNUMBERDISTRIBUTIONFACTORY_DEF_ */ -
src/RandomNumbers/RandomNumberDistributionFactory.hpp
rc9bc2b7 r1d5a871 16 16 #include "CodePatterns/Singleton.hpp" 17 17 18 // this defines stuff necessary PREVIOUS of Factory.hpp inclusion 19 #include "RandomNumberDistributionFactory.def" 20 #include "CodePatterns/FactoryTypeList.hpp" 21 #include "CodePatterns/Factory.hpp" 22 18 23 #include <map> 19 24 20 #include "TemplatePowerSetGenerator.hpp" 21 #include "RandomNumberDistributionFactory.def" 25 #include "unittests/RandomNumberDistributionFactoryUnitTest.hpp" 22 26 23 #include "RandomNumberDistribution_Creator.hpp"24 25 #include "unittests/RandomNumberDistributionFactoryUnitTest.hpp"26 27 27 28 class RandomNumberDistribution; … … 36 37 * 37 38 */ 38 class RandomNumberDistributionFactory : public Singleton<RandomNumberDistributionFactory> 39 class RandomNumberDistributionFactory : 40 public Singleton<RandomNumberDistributionFactory>, 41 public Factory<RandomNumberDistribution> 39 42 { 40 43 friend class Singleton<RandomNumberDistributionFactory>; 41 44 friend class RandomNumberDistributionFactoryTest; 42 public:43 45 44 46 protected: … … 46 48 virtual ~RandomNumberDistributionFactory(); 47 49 48 public:49 /** Enumeration of all distribution implemented in random::boost.50 */51 enum Distribution {52 BOOST_PP_REPEAT( distribution_seq_size, seqitems_as_enum, distribution_seq)53 };54 55 /** Getter for current type of distribution.56 *57 * @param enumeration index of distribution58 * @return reference to copy of distribution59 */60 RandomNumberDistribution* getDistribution(enum Distribution distribution_type) const;61 62 /** Getter for current type of distribution.63 *64 * @param name of distribution65 * @return reference to copy of distribution66 */67 RandomNumberDistribution* getDistribution(const std::string distribution_name) const;68 69 /** Getter for the name of the current type of distribution.70 *71 * @return name of distribution72 */73 const std::string &getName(enum Distribution distribution_type) const;74 75 /** Getter for the enumeration index of the current type of distribution.76 *77 * @return enum of distribution78 */79 enum Distribution getEnum(const std::string distribution_name) const;80 81 82 protected:83 private:84 85 /** Creates instances of all possible distribution types86 * and stores them in \a DistributionPrototypeTable.87 */88 void FillPrototypeTable();89 90 /** Create association for enums to strings and vice versa91 * and stores them in \a distributions tables.92 */93 void FillEnumTable();94 95 typedef std::map<96 std::string,97 enum Distribution98 > DistributionMap;99 typedef std::map<100 enum Distribution,101 IRandomNumberDistribution_Creator *102 > DistributionTable;103 typedef std::map<104 enum Distribution,105 std::string106 > DistributionNamesMap;107 108 //static enum Distribution distribution;109 static DistributionMap distributions;110 static DistributionTable DistributionPrototypeTable;111 static DistributionNamesMap distributionNames;112 50 }; 113 51 -
src/RandomNumbers/RandomNumberDistributionFactory.undef
rc9bc2b7 r1d5a871 1 1 #ifdef RANDOMNUMBERDISTRIBUTIONFACTORY_DEF_ 2 2 3 #undef distribution_seq 4 #undef distribution_seq_size 3 #undef type_seq 4 #undef type_seq_size 5 #undef Abstract_Interface_Class 6 #undef Abstract_Encapsulation_Class 7 #undef type_name_space 8 #undef type_name_space_suffix 5 9 6 10 #undef RANDOMNUMBERDISTRIBUTIONFACTORY_DEF_ 7 8 11 #endif /* RANDOMNUMBERDISTRIBUTIONFACTORY_DEF_ */ -
src/RandomNumbers/RandomNumberDistribution_Encapsulation.hpp
rc9bc2b7 r1d5a871 35 35 #include <boost/random/uniform_smallint.hpp> 36 36 37 #include " RandomNumberDistribution_Creator.hpp"37 #include "CodePatterns/Creator.hpp" 38 38 #include "RandomNumberDistribution.hpp" 39 39 40 #include "RandomNumberGeneratorFactory.hpp" 40 41 41 #include "unittests/RandomNumberGeneratorFactoryUnitTest.hpp" 42 42 … … 49 49 */ 50 50 template <class distribution> 51 class RandomNumberDistribution_Encapsulation : public RandomNumberDistribution, public RandomNumberDistribution_Creator< RandomNumberDistribution_Encapsulation<distribution> > 51 class RandomNumberDistribution_Encapsulation : 52 public RandomNumberDistribution, 53 public Creator< 54 RandomNumberDistribution, 55 RandomNumberDistribution_Encapsulation<distribution> 56 > 52 57 { 53 58 /** -
src/RandomNumbers/RandomNumberEngineFactory.cpp
rc9bc2b7 r1d5a871 24 24 #include "CodePatterns/Assert.hpp" 25 25 26 #include <boost/preprocessor/facilities/empty.hpp> 27 #include <boost/preprocessor/punctuation/paren.hpp> 28 29 #include "TemplatePowerSetGenerator.hpp" 30 #include "EmptyPrototypeTable.hpp" 26 #include <boost/nondet_random.hpp> 27 #include <boost/random.hpp> 28 #include <boost/random/additive_combine.hpp> 29 #include <boost/random/discard_block.hpp> 30 #include <boost/random/inversive_congruential.hpp> 31 #include <boost/random/lagged_fibonacci.hpp> 32 #include <boost/random/linear_congruential.hpp> 33 #include <boost/random/linear_feedback_shift.hpp> 34 #include <boost/random/mersenne_twister.hpp> 35 #include <boost/random/random_number_generator.hpp> 36 #include <boost/random/ranlux.hpp> 37 #include <boost/random/shuffle_output.hpp> 38 #include <boost/random/subtract_with_carry.hpp> 39 #include <boost/random/xor_combine.hpp> 31 40 32 41 #include "RandomNumberEngine_Encapsulation.hpp" 33 42 34 43 #include "RandomNumberEngineFactory.hpp" 44 45 // has to be included BEFORE Factory_impl.hpp! 35 46 #include "RandomNumberEngineFactory.def" 47 #include "CodePatterns/Factory_impl.hpp" 36 48 37 //enum RandomNumberEngineFactory::Engine RandomNumberEngineFactory::engine = (enum RandomNumberEngineFactory::Engine) 0; 38 RandomNumberEngineFactory::EngineMap RandomNumberEngineFactory::engines; 39 RandomNumberEngineFactory::EngineNamesMap RandomNumberEngineFactory::engineNames; 40 RandomNumberEngineFactory::EngineTable RandomNumberEngineFactory::EnginePrototypeTable; 41 42 43 RandomNumberEngineFactory::RandomNumberEngineFactory() 44 { 45 FillEnumTable(); 46 FillPrototypeTable(); 47 } 48 49 50 RandomNumberEngineFactory::~RandomNumberEngineFactory() 51 { 52 // clear out factories map to allow boost::shared_ptr to do their work (i.e. to release mem) 53 // this is necessary as factories is a object 54 engines.clear(); 55 engineNames.clear(); 56 EmptyPrototypeTable<EngineTable> (EnginePrototypeTable); 57 } 58 59 void RandomNumberEngineFactory::FillEnumTable() 60 { 61 // insert all known engines 62 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_string_enum_map(~, n, engine_seq, engines) 63 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(engine_seq)-1 ) 64 #include BOOST_PP_LOCAL_ITERATE() 65 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_string_enum_map(~, n, engine_seq_a, engines) 66 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(engine_seq_a)-1 ) 67 #include BOOST_PP_LOCAL_ITERATE() 68 for (EngineMap::const_iterator iter = engines.begin(); 69 iter != engines.end(); 70 ++iter) { 71 engineNames.insert(make_pair(iter->second, iter->first)); 72 } 73 } 74 75 void RandomNumberEngineFactory::FillPrototypeTable() 76 { 77 // fill EnginePrototypeTable 78 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_map(~, n, engine_seq, EnginePrototypeTable, new RandomNumberEngine_Creator< RandomNumberEngine_Encapsulation , boost::, >) 79 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(engine_seq)-1 ) 80 #include BOOST_PP_LOCAL_ITERATE() 81 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_map(~, n, engine_seq_a, EnginePrototypeTable, new RandomNumberEngine_Creator< RandomNumberEngine_Encapsulation , boost::, >) 82 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(engine_seq_a)-1 ) 83 #include BOOST_PP_LOCAL_ITERATE() 84 } 85 86 RandomNumberEngine* RandomNumberEngineFactory::getEngine(enum Engine engine_type) const 87 { 88 return EnginePrototypeTable[engine_type]->create(); 89 } 90 91 RandomNumberEngine* RandomNumberEngineFactory::getEngine(const std::string engine_name) const 92 { 93 ASSERT(engines.count(engine_name) != 0, 94 "RandomNumberEngineFactory::getEngine() - engine "+engine_name+" is not registered."); 95 return EnginePrototypeTable[ engines[engine_name] ]->create(); 96 } 97 98 const std::string &RandomNumberEngineFactory::getName(enum Engine engine_type) const 99 { 100 return engineNames[engine_type]; 101 } 102 103 enum RandomNumberEngineFactory::Engine RandomNumberEngineFactory::getEnum(const std::string engine_name) const 104 { 105 ASSERT(engines.count(engine_name) != 0, 106 "RandomNumberEngineFactory::getEnum() - engine "+engine_name+" is not registered."); 107 return engines[engine_name]; 108 } 49 RandomNumberEngineFactory::RandomNumberEngineFactory() {} 50 RandomNumberEngineFactory::~RandomNumberEngineFactory() {} 109 51 110 52 CONSTRUCT_SINGLETON(RandomNumberEngineFactory) 53 CONSTRUCT_FACTORY(RandomNumberEngine) 111 54 112 55 #include "RandomNumberEngineFactory.undef" -
src/RandomNumbers/RandomNumberEngineFactory.def
rc9bc2b7 r1d5a871 39 39 (ranlux64_4_01) 40 40 */ 41 #define engine_seq_size BOOST_PP_SEQ_SIZE(engine_seq) 42 #define engine_seq_a_size BOOST_PP_SEQ_SIZE(engine_seq_a) 41 42 #define type_seq engine_seq engine_seq_a 43 44 #define Abstract_Interface_Class RandomNumberEngine 45 #define Abstract_Encapsulation_Class RandomNumberEngine_Encapsulation 46 #define type_name_space boost:: 47 #undef type_name_space_suffix 43 48 44 49 #endif /* RANDOMNUMBERENGINEFACTORY_DEF_ */ -
src/RandomNumbers/RandomNumberEngineFactory.hpp
rc9bc2b7 r1d5a871 16 16 #include "CodePatterns/Singleton.hpp" 17 17 18 // this defines stuff necessary PREVIOUS of Factory.hpp inclusion 19 #include "RandomNumberEngineFactory.def" 20 #include "CodePatterns/FactoryTypeList.hpp" 21 #include "CodePatterns/Factory.hpp" 18 22 19 23 #include <map> 20 24 21 #include "TemplatePowerSetGenerator.hpp"22 #include "RandomNumberEngineFactory.def"23 24 25 #include "unittests/RandomNumberEngineFactoryUnitTest.hpp" 25 26 26 #include "RandomNumberEngine_Creator.hpp"27 27 28 28 class RandomNumberEngine; … … 37 37 * 38 38 */ 39 class RandomNumberEngineFactory : public Singleton<RandomNumberEngineFactory> 39 class RandomNumberEngineFactory : 40 public Singleton<RandomNumberEngineFactory>, 41 public Factory<RandomNumberEngine> 40 42 { 41 43 friend class Singleton<RandomNumberEngineFactory>; 42 44 friend class RandomNumberEngineFactoryTest; 43 public:44 45 45 46 protected: … … 47 48 virtual ~RandomNumberEngineFactory(); 48 49 49 public:50 /** Enumeration of all (pseudo-)random number engines implemented in51 * boost::random, see52 * http://www.boost.org/doc/libs/1_45_0/doc/html/boost_random/reference.html#boost_random.reference.concepts53 */54 enum Engine {55 BOOST_PP_REPEAT( engine_seq_size, seqitems_as_enum, engine_seq)56 ,57 BOOST_PP_REPEAT( engine_seq_a_size, seqitems_as_enum, engine_seq_a)58 };59 60 /** Getter for current type of engine.61 *62 * @param enumeration index of engine63 * @return reference to copy of engine64 */65 RandomNumberEngine* getEngine(enum Engine engine_type) const;66 67 /** Getter for current type of engine.68 *69 * @param name of engine70 * @return reference to copy of engine71 */72 RandomNumberEngine* getEngine(const std::string engine_name) const;73 74 /** Getter for the name of the current type of engine.75 *76 * @return name of engine77 */78 const std::string &getName(enum Engine engine_type) const;79 80 /** Getter for the enumeration index of the current type of engine.81 *82 * @return enum of engine83 */84 enum Engine getEnum(const std::string engine_name) const;85 86 protected:87 private:88 /** Creates instances of all possible engine types89 * and stores them in \a EnginePrototypeTable.90 */91 void FillPrototypeTable();92 93 /** Create association for enums to strings and vice versa94 * and stores them in \a engines tables.95 */96 void FillEnumTable();97 98 typedef std::map<99 std::string,100 enum Engine101 > EngineMap;102 typedef std::map<103 enum Engine,104 IRandomNumberEngine_Creator *105 > EngineTable;106 typedef std::map<107 enum Engine,108 std::string109 > EngineNamesMap;110 111 //static enum Engine engine;112 static EngineMap engines;113 static EngineTable EnginePrototypeTable;114 static EngineNamesMap engineNames;115 50 }; 116 51 -
src/RandomNumbers/RandomNumberEngineFactory.undef
rc9bc2b7 r1d5a871 1 1 #ifdef RANDOMNUMBERENGINEFACTORY_DEF_ 2 2 3 #undef engine_seq 4 #undef engine_seq_size 5 #undef engine_seq_a 6 #undef engine_seq_a_size 3 #undef type_seq 4 #undef type_seq_size 5 #undef Abstract_Interface_Class 6 #undef Abstract_Encapsulation_Class 7 #undef type_name_space 8 #undef type_name_space_suffix 7 9 8 10 #undef RANDOMNUMBERENGINEFACTORY_DEF_ 9 10 11 #endif /* RANDOMNUMBERENGINEFACTORY_DEF_ */ -
src/RandomNumbers/RandomNumberEngine_Encapsulation.hpp
rc9bc2b7 r1d5a871 31 31 #include <boost/random/xor_combine.hpp> 32 32 33 #include " RandomNumberEngine_Creator.hpp"33 #include "CodePatterns/Creator.hpp" 34 34 #include "RandomNumberEngine.hpp" 35 35 36 #include "RandomNumberGeneratorFactory.hpp" 37 #include "unittests/RandomNumberGeneratorFactoryUnitTest.hpp" 36 //#include "RandomNumberGeneratorFactory.hpp" 37 //#include "unittests/RandomNumberGeneratorFactoryUnitTest.hpp" 38 39 class RandomNumberGeneratorFactory; 40 class RandomNumberGeneratorFactoryTest; 38 41 39 42 /** Template class that encapsulates the random number engines from … … 45 48 */ 46 49 template <class engine> 47 class RandomNumberEngine_Encapsulation : public RandomNumberEngine, public RandomNumberEngine_Creator< RandomNumberEngine_Encapsulation<engine> > 50 class RandomNumberEngine_Encapsulation : 51 public RandomNumberEngine, 52 public Creator< 53 RandomNumberEngine, 54 RandomNumberEngine_Encapsulation<engine> 55 > 48 56 { 49 57 /** -
src/RandomNumbers/RandomNumberGeneratorFactory.cpp
rc9bc2b7 r1d5a871 27 27 #include "EmptyPrototypeTable.hpp" 28 28 29 #include "RandomNumberEngineFactory.hpp"30 #include "RandomNumberDistributionFactory.hpp"31 #include "RandomNumberGenerator_Encapsulation.hpp"32 33 29 #include <boost/preprocessor/facilities/empty.hpp> 34 30 #include <boost/preprocessor/punctuation/paren.hpp> … … 38 34 #include <boost/preprocessor/seq/seq.hpp> 39 35 36 #include "RandomNumberGenerator_Encapsulation.hpp" 40 37 41 38 #include "RandomNumberGeneratorFactory.hpp" 42 #include "RandomNumberDistributionFactory.def" 43 #include "RandomNumberEngineFactory.def" 39 #include "RandomNumberGeneratorFactory.def" 44 40 45 enum RandomNumberDistributionFactory::Distribution RandomNumberGeneratorFactory::distribution = (enum RandomNumberDistributionFactory::Distribution) 0;46 enum RandomNumberEngineFactory::Engine RandomNumberGeneratorFactory::engine = (enum RandomNumberEngineFactory::Engine) 0;41 RandomNumberDistributionFactory::TypeList RandomNumberGeneratorFactory::distribution = (RandomNumberDistributionFactory::TypeList) 0; 42 RandomNumberEngineFactory::TypeList RandomNumberGeneratorFactory::engine = (RandomNumberEngineFactory::TypeList) 0; 47 43 RandomNumberGeneratorFactory::EngineDistributionTable RandomNumberGeneratorFactory::GeneratorPrototypeTable; 48 44 … … 59 55 !GeneratorPrototypeTable.empty(); 60 56 iter = GeneratorPrototypeTable.begin()) { 61 EmptyPrototypeTable< std::map< enum RandomNumberDistributionFactory::Distribution,IRandomNumberGenerator_Creator*> > (iter->second);57 EmptyPrototypeTable< std::map<RandomNumberDistributionFactory::TypeList,ICreator<RandomNumberGenerator> *> > (iter->second); 62 58 GeneratorPrototypeTable.erase(iter); 63 59 } … … 95 91 #define ParamItemPrinter(z,n,sequence) 96 92 97 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_multidimmap(~, n, size_tupels, distributionengine_seqseq, GeneratorPrototypeTable, TableItemPrinter, new RandomNumberGenerator_Creator<RandomNumberGenerator_Encapsulation , TemplateItemPrinter, ParamItemPrinter)93 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_multidimmap(~, n, size_tupels, distributionengine_seqseq, GeneratorPrototypeTable, TableItemPrinter, new Creator< RandomNumberGenerator BOOST_PP_COMMA() RandomNumberGenerator_Encapsulation , TemplateItemPrinter, ParamItemPrinter) 98 94 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(distributionengine_seqseq)-1 ) 99 95 #include BOOST_PP_LOCAL_ITERATE() 100 96 101 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_multidimmap(~, n, size_tupels, distributionengine_seqseq_a, GeneratorPrototypeTable, TableItemPrinter, new RandomNumberGenerator_Creator<RandomNumberGenerator_Encapsulation , TemplateItemPrinter, ParamItemPrinter)97 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_multidimmap(~, n, size_tupels, distributionengine_seqseq_a, GeneratorPrototypeTable, TableItemPrinter, new Creator< RandomNumberGenerator BOOST_PP_COMMA() RandomNumberGenerator_Encapsulation , TemplateItemPrinter, ParamItemPrinter) 102 98 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(distributionengine_seqseq_a)-1 ) 103 99 #include BOOST_PP_LOCAL_ITERATE() … … 115 111 ) const 116 112 { 117 enum RandomNumberEngineFactory::Engineeng_type;118 enum RandomNumberDistributionFactory::Distributiondis_type;113 RandomNumberEngineFactory::TypeList eng_type; 114 RandomNumberDistributionFactory::TypeList dis_type; 119 115 120 116 // Instantiate and return (implicitly creates a copy of the stored prototype) … … 152 148 CONSTRUCT_SINGLETON(RandomNumberGeneratorFactory) 153 149 154 #include "RandomNumberDistributionFactory.undef" 155 #include "RandomNumberEngineFactory.undef" 150 #include "RandomNumberGeneratorFactory.undef" 156 151 -
src/RandomNumbers/RandomNumberGeneratorFactory.hpp
rc9bc2b7 r1d5a871 20 20 21 21 #include <map> 22 23 #include "RandomNumberGenerator_Creator.hpp"24 22 25 23 #include "unittests/RandomNumberGeneratorFactoryUnitTest.hpp" … … 98 96 99 97 typedef std::map< 100 enum RandomNumberEngineFactory::Engine,98 RandomNumberEngineFactory::TypeList, 101 99 std::map< 102 enum RandomNumberDistributionFactory::Distribution,103 I RandomNumberGenerator_Creator*>100 RandomNumberDistributionFactory::TypeList, 101 ICreator<RandomNumberGenerator> *> 104 102 > EngineDistributionTable; 105 103 106 static enum RandomNumberDistributionFactory::Distributiondistribution;107 static enum RandomNumberEngineFactory::Engineengine;104 static RandomNumberDistributionFactory::TypeList distribution; 105 static RandomNumberEngineFactory::TypeList engine; 108 106 static EngineDistributionTable GeneratorPrototypeTable; 109 107 }; -
src/RandomNumbers/RandomNumberGenerator_Encapsulation.hpp
rc9bc2b7 r1d5a871 48 48 #include <typeinfo> 49 49 50 #include " RandomNumberGenerator_Creator.hpp"50 #include "CodePatterns/Creator.hpp" 51 51 #include "RandomNumberGenerator.hpp" 52 52 … … 69 69 */ 70 70 template <class engine, class distribution> 71 class RandomNumberGenerator_Encapsulation : public RandomNumberGenerator, public RandomNumberGenerator_Creator< RandomNumberGenerator_Encapsulation<engine, distribution> > 71 class RandomNumberGenerator_Encapsulation : 72 public RandomNumberGenerator, 73 public Creator< 74 RandomNumberGenerator, 75 RandomNumberGenerator_Encapsulation<engine, distribution> 76 > 72 77 { 73 78 /** … … 77 82 friend class RandomNumberGeneratorFactoryTest; 78 83 79 friend class RandomNumberGenerator_Creator<RandomNumberGenerator_Encapsulation<engine, distribution> >;84 friend class Creator< RandomNumberGenerator, RandomNumberGenerator_Encapsulation<engine, distribution> >; 80 85 81 86 public: … … 109 114 } 110 115 111 protected:112 116 /** Constructor that instantiates a specific random number generator and 113 117 * distribution. … … 121 125 distribution_type) 122 126 ) 123 { 124 // note that we instantiate the variate_generator with the copied instances! 125 } 127 {} 126 128 127 129 /** Destructor of the class. -
src/RandomNumbers/TemplatePowerSetGenerator.hpp
rc9bc2b7 r1d5a871 91 91 * 92 92 * then we use 93 * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_string_enum_map(seqsize, n, seq, EnumMap )93 * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_string_enum_map(seqsize, n, seq, EnumMap, name_space) 94 94 * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seq)-1 ) 95 95 * #include BOOST_PP_LOCAL_ITERATE() 96 96 * 97 97 * which expands by the preprocessor to: 98 * EnumMap["one"] = one;99 * EnumMap["two"] = t wo;100 * EnumMap["three"] = t hree;101 * EnumMap["four"] = four;98 * EnumMap["one"] = test:: one; 99 * EnumMap["two"] = test:: two; 100 * EnumMap["three"] = test:: three; 101 * EnumMap["four"] = test:: four; 102 102 103 103 */ 104 #define seqitems_as_string_enum_map(z,n,seq_with_elements, map ) \104 #define seqitems_as_string_enum_map(z,n,seq_with_elements, map, name_space) \ 105 105 map [BOOST_PP_STRINGIZE( \ 106 106 BOOST_PP_SEQ_ELEM(n, seq_with_elements) \ 107 )] = BOOST_PP_SEQ_ELEM(n, seq_with_elements) \107 )] = name_space BOOST_PP_SEQ_ELEM(n, seq_with_elements) \ 108 108 ; 109 109 -
src/RandomNumbers/unittests/RandomNumberDistributionFactoryUnitTest.cpp
rc9bc2b7 r1d5a871 79 79 { 80 80 // check the injectiveness of enum and string map 81 for (RandomNumberDistributionFactory:: DistributionNamesMap::const_iterator82 iter = RandomNumberDistributionFactory::getInstance(). distributionNames.begin();83 iter != RandomNumberDistributionFactory::getInstance(). distributionNames.end();81 for (RandomNumberDistributionFactory::NameMap::const_iterator 82 iter = RandomNumberDistributionFactory::getInstance().names.begin(); 83 iter != RandomNumberDistributionFactory::getInstance().names.end(); 84 84 ++iter) { 85 85 CPPUNIT_ASSERT_EQUAL( … … 96 96 RandomNumberDistribution * rnd = 97 97 RandomNumberDistributionFactory::getInstance(). 98 DistributionPrototypeTable[RandomNumberDistributionFactory::uniform_smallint]->create();98 PrototypeTable[RandomNumberDistributionFactory::uniform_smallint]->create(); 99 99 CPPUNIT_ASSERT_EQUAL( 100 100 std::string(typeid(boost::uniform_smallint<> ).name()), -
src/RandomNumbers/unittests/RandomNumberEngineFactoryUnitTest.cpp
rc9bc2b7 r1d5a871 84 84 { 85 85 // check the injectiveness of enum and string map 86 for (RandomNumberEngineFactory:: EngineNamesMap::const_iterator87 iter = RandomNumberEngineFactory::getInstance(). engineNames.begin();88 iter != RandomNumberEngineFactory::getInstance(). engineNames.end();86 for (RandomNumberEngineFactory::NameMap::const_iterator 87 iter = RandomNumberEngineFactory::getInstance().names.begin(); 88 iter != RandomNumberEngineFactory::getInstance().names.end(); 89 89 ++iter) { 90 90 CPPUNIT_ASSERT_EQUAL( … … 101 101 RandomNumberEngine* rng = 102 102 RandomNumberEngineFactory::getInstance(). 103 EnginePrototypeTable[RandomNumberEngineFactory::minstd_rand0]->create();103 PrototypeTable[RandomNumberEngineFactory::minstd_rand0]->create(); 104 104 CPPUNIT_ASSERT_EQUAL( 105 105 std::string(typeid(boost::minstd_rand0).name()),
Note:
See TracChangeset
for help on using the changeset viewer.