| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
|---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | /*
|
|---|
| 9 | * RandomNumberDistributionFactory.cpp
|
|---|
| 10 | *
|
|---|
| 11 | * Created on: Jan 03, 2011
|
|---|
| 12 | * Author: heber
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 | // include config.h
|
|---|
| 16 | #ifdef HAVE_CONFIG_H
|
|---|
| 17 | #include <config.h>
|
|---|
| 18 | #endif
|
|---|
| 19 |
|
|---|
| 20 | #include "CodePatterns/MemDebug.hpp"
|
|---|
| 21 |
|
|---|
| 22 | #include <utility>
|
|---|
| 23 | #include "CodePatterns/Singleton_impl.hpp"
|
|---|
| 24 | #include "CodePatterns/Assert.hpp"
|
|---|
| 25 |
|
|---|
| 26 | #include <boost/random/bernoulli_distribution.hpp>
|
|---|
| 27 | #include <boost/random/binomial_distribution.hpp>
|
|---|
| 28 | #include <boost/random/cauchy_distribution.hpp>
|
|---|
| 29 | #include <boost/random/exponential_distribution.hpp>
|
|---|
| 30 | #include <boost/random/gamma_distribution.hpp>
|
|---|
| 31 | #include <boost/random/geometric_distribution.hpp>
|
|---|
| 32 | #include <boost/random/linear_congruential.hpp>
|
|---|
| 33 | #include <boost/random/lognormal_distribution.hpp>
|
|---|
| 34 | #include <boost/random/normal_distribution.hpp>
|
|---|
| 35 | #include <boost/random/poisson_distribution.hpp>
|
|---|
| 36 | #include <boost/random/triangle_distribution.hpp>
|
|---|
| 37 | #include <boost/random/uniform_01.hpp>
|
|---|
| 38 | #include <boost/random/uniform_int.hpp>
|
|---|
| 39 | #include <boost/random/uniform_on_sphere.hpp>
|
|---|
| 40 | #include <boost/random/uniform_real.hpp>
|
|---|
| 41 | #include <boost/random/uniform_smallint.hpp>
|
|---|
| 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 | #include "RandomNumberDistribution_Encapsulation.hpp"
|
|---|
| 50 |
|
|---|
| 51 | #include "RandomNumberDistributionFactory.hpp"
|
|---|
| 52 | #include "RandomNumberDistributionFactory.def"
|
|---|
| 53 |
|
|---|
| 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 | }
|
|---|
| 119 |
|
|---|
| 120 | CONSTRUCT_SINGLETON(RandomNumberDistributionFactory)
|
|---|
| 121 |
|
|---|
| 122 | #include "RandomNumberDistributionFactory.undef"
|
|---|
| 123 |
|
|---|