source: src/RandomNumbers/RandomNumberGeneratorFactory.cpp@ ff4fff9

CombiningParticlePotentialParsing
Last change on this file since ff4fff9 was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 6.3 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * RandomNumberGeneratorFactory.cpp
25 *
26 * Created on: Dec 31, 2010
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "CodePatterns/MemDebug.hpp"
36
37#include <utility>
38#include "CodePatterns/Singleton_impl.hpp"
39#include "CodePatterns/Assert.hpp"
40
41#include "TemplatePowerSetGenerator.hpp"
42#include "EmptyPrototypeTable.hpp"
43
44#include <boost/preprocessor/facilities/empty.hpp>
45#include <boost/preprocessor/punctuation/paren.hpp>
46#include <boost/preprocessor/seq/for_each_product.hpp>
47#include <boost/preprocessor/facilities/identity.hpp>
48#include <boost/preprocessor/facilities/expand.hpp>
49#include <boost/preprocessor/seq/seq.hpp>
50
51#include "RandomNumberGenerator_Encapsulation.hpp"
52
53#include "RandomNumberGeneratorFactory.hpp"
54#include "RandomNumberGeneratorFactory.def"
55
56RandomNumberDistributionFactory::TypeList RandomNumberGeneratorFactory::distribution = (RandomNumberDistributionFactory::TypeList) 0;
57RandomNumberEngineFactory::TypeList RandomNumberGeneratorFactory::engine = (RandomNumberEngineFactory::TypeList) 0;
58RandomNumberGeneratorFactory::EngineDistributionTable RandomNumberGeneratorFactory::GeneratorPrototypeTable;
59
60RandomNumberGeneratorFactory::RandomNumberGeneratorFactory()
61{
62 FillPrototypeTable();
63}
64
65RandomNumberGeneratorFactory::~RandomNumberGeneratorFactory()
66{
67 // clear out factories map to allow boost::shared_ptr to do their work (i.e. to release mem)
68 // this is necessary as factories is a object
69 for (EngineDistributionTable::iterator iter = GeneratorPrototypeTable.begin();
70 !GeneratorPrototypeTable.empty();
71 iter = GeneratorPrototypeTable.begin()) {
72 EmptyPrototypeTable< std::map<RandomNumberDistributionFactory::TypeList,RandomNumberGenerator*> > (iter->second);
73 GeneratorPrototypeTable.erase(iter);
74 }
75 GeneratorPrototypeTable.clear();
76}
77
78void RandomNumberGeneratorFactory::FillPrototypeTable()
79{
80 // fill GeneratorPrototypeTable
81#define SequenceElementizer(z,data) (data)
82
83#define distributionengine_seqseq \
84 BOOST_PP_SEQ_FOR_EACH_PRODUCT(SequenceElementizer, (engine_seq)(distribution_seq))
85#define distributionengine_seqseq_a \
86 BOOST_PP_SEQ_FOR_EACH_PRODUCT(SequenceElementizer, (engine_seq_a)(distribution_seq))
87
88#define suffixseq ()(<>)
89#define tableseq (*EnginePrototypeTable)(*DistributionPrototypeTable)
90#define name_spaces_seq (RandomNumberEngineFactory::)(RandomNumberDistributionFactory::)
91
92#define size_tupels BOOST_PP_SEQ_SIZE(tableseq)
93
94#define TableItemPrinter(z,n,sequence) \
95 [ \
96 BOOST_PP_SEQ_ELEM(n,name_spaces_seq) \
97 BOOST_PP_SEQ_ELEM(n,sequence) \
98 ]
99
100#define TemplateItemPrinter(z,n,sequence) \
101 BOOST_PP_COMMA_IF(n) \
102 boost:: \
103 BOOST_PP_SEQ_ELEM(n,sequence) \
104 BOOST_PP_SEQ_ELEM(n,suffixseq)
105
106#define ParamItemPrinter(z,n,sequence)
107
108#define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_multidimmap(~, n, size_tupels, distributionengine_seqseq, GeneratorPrototypeTable, TableItemPrinter, new RandomNumberGenerator_Encapsulation , TemplateItemPrinter, ParamItemPrinter)
109#define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(distributionengine_seqseq)-1 )
110#include BOOST_PP_LOCAL_ITERATE()
111
112#define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_multidimmap(~, n, size_tupels, distributionengine_seqseq_a, GeneratorPrototypeTable, TableItemPrinter, new RandomNumberGenerator_Encapsulation , TemplateItemPrinter, ParamItemPrinter)
113#define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(distributionengine_seqseq_a)-1 )
114#include BOOST_PP_LOCAL_ITERATE()
115}
116
117RandomNumberGenerator& RandomNumberGeneratorFactory::makeRandomNumberGenerator() const
118{
119 // Instantiate and return (implicitly creates a copy of the stored prototype)
120 RandomNumberEngineFactory::TypeList eng_type =
121 RandomNumberEngineFactory::getInstance().getCurrentTypeEnum();
122 RandomNumberDistributionFactory::TypeList dis_type =
123 RandomNumberDistributionFactory::getInstance().getCurrentTypeEnum();
124
125 return (*GeneratorPrototypeTable[ eng_type ][ dis_type ]);
126}
127
128RandomNumberGenerator& RandomNumberGeneratorFactory::makeRandomNumberGenerator(
129 std::string engine_type,
130 std::string distribution_type
131 ) const
132{
133 RandomNumberEngineFactory::TypeList eng_type;
134 RandomNumberDistributionFactory::TypeList dis_type;
135
136 // Instantiate and return (implicitly creates a copy of the stored prototype)
137 if (!engine_type.empty()) {
138 eng_type = RandomNumberEngineFactory::getInstance().getEnum(engine_type);
139 } else
140 eng_type = RandomNumberEngineFactory::getInstance().getCurrentTypeEnum();
141 if (!distribution_type.empty()) {
142 dis_type = RandomNumberDistributionFactory::getInstance().getEnum(distribution_type);
143 } else
144 dis_type = RandomNumberDistributionFactory::getInstance().getCurrentTypeEnum();
145 return (*GeneratorPrototypeTable[ eng_type ][ dis_type ]);
146
147 return (*GeneratorPrototypeTable[ eng_type ][ dis_type ]);
148}
149
150void RandomNumberGeneratorFactory::setEngine(std::string engine_type)
151{
152 RandomNumberEngineFactory::getInstance().setCurrentType(engine_type);
153}
154
155const std::string &RandomNumberGeneratorFactory::getEngineName() const
156{
157 return RandomNumberEngineFactory::getInstance().getCurrentTypeName();
158}
159
160void RandomNumberGeneratorFactory::setDistribution(std::string distribution_type)
161{
162 RandomNumberDistributionFactory::getInstance().setCurrentType(distribution_type);
163}
164
165const std::string &RandomNumberGeneratorFactory::getDistributionName() const
166{
167 return RandomNumberDistributionFactory::getInstance().getCurrentTypeName();
168}
169
170CONSTRUCT_SINGLETON(RandomNumberGeneratorFactory)
171
172#include "RandomNumberGeneratorFactory.undef"
173
Note: See TracBrowser for help on using the repository browser.