source: src/RandomNumbers/RandomNumberEngine_Parameters.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: 4.9 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 * RandomNumberEngine_Parameters.cpp
25 *
26 * Created on: Jan 6, 2011
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 <iostream>
38#include <boost/tokenizer.hpp>
39#include <string>
40#include <map>
41
42#include "CodePatterns/Assert.hpp"
43#include "CodePatterns/Log.hpp"
44#include "CodePatterns/Verbose.hpp"
45
46#include "RandomNumberEngine_Parameters.hpp"
47
48#include "RandomNumberEngine.hpp"
49
50RandomNumberEngine_Parameters::ParamNames RandomNumberEngine_Parameters::params;
51const double RandomNumberEngine_Parameters::noset_value = -1.;
52
53RandomNumberEngine_Parameters::RandomNumberEngine_Parameters() :
54 seed(noset_value)
55{
56 // if param names map not yet filled, do so
57 if (params.begin() == params.end()) {
58 params["seed"] = param_seed;
59 }
60}
61
62RandomNumberEngine_Parameters::RandomNumberEngine_Parameters(
63 const RandomNumberEngine_Parameters &_ref)
64{
65 // check self assignment
66 if (&_ref != this) {
67 seed = _ref.seed;
68 }
69}
70
71RandomNumberEngine_Parameters::~RandomNumberEngine_Parameters()
72{}
73
74void RandomNumberEngine_Parameters::getParameters(const RandomNumberEngine* const _engine)
75{
76 seed = _engine->getseed();
77}
78
79void RandomNumberEngine_Parameters::update(const RandomNumberEngine_Parameters &_params)
80{
81 seed = _params.seed != noset_value ? _params.seed : seed;
82}
83
84bool RandomNumberEngine_Parameters::isDefault() const
85{
86 bool status = true;
87 status = status && (seed == noset_value);
88 return status;
89}
90
91std::ostream & operator << (std::ostream& ost, const RandomNumberEngine_Parameters &params)
92{
93 std::ostringstream output;
94 output << "seed=" << params.seed << ";";
95 ost << output.str();
96 return ost;
97}
98
99// TODO: These should throw exceptions such that invalid user entry can be detected.
100std::istream & operator >> (std::istream& ist, RandomNumberEngine_Parameters &params)
101{
102 typedef boost::tokenizer<boost::char_separator<char> >
103 tokenizer;
104 boost::char_separator<char> semicolonsep(";");
105 boost::char_separator<char> equalitysep("=");
106 std::string line;
107 double tmp;
108 std::getline( ist, line );
109 //LOG(0, "INFO: full line of parameters is '" << line << "'");
110 tokenizer tokens(line, semicolonsep);
111 ASSERT(tokens.begin() != tokens.end(),
112 "operator<< on RandomNumberEngine_Parameters - empty string, need at least ';'!");
113 for (tokenizer::iterator tok_iter = tokens.begin();
114 tok_iter != tokens.end(); ++tok_iter) {
115 tokenizer paramtokens(*tok_iter, equalitysep);
116 if (paramtokens.begin() != paramtokens.end()) {
117 tokenizer::iterator tok_paramiter = paramtokens.begin();
118 tokenizer::iterator tok_valueiter = tok_paramiter;
119 tokenizer::iterator tok_checkiter = ++tok_valueiter;
120 ASSERT(tok_paramiter != paramtokens.end(),
121 "operator<< on RandomNumberEngine_Parameters - missing value before '=' in token"
122 +*tok_iter+"!");
123 ASSERT(tok_valueiter != paramtokens.end(),
124 "operator<< on RandomNumberEngine_Parameters - missing value after '=' in token"
125 +*tok_iter+"!");
126 ++tok_checkiter;
127 ASSERT(tok_checkiter == paramtokens.end(),
128 "operator<< on RandomNumberEngine_Parameters - still tokens before ';' in token"
129 +*tok_iter+": "+*tok_checkiter+"!");
130 LOG(0, "INFO: Token pair is " << *tok_paramiter << "," << *tok_valueiter);
131 std::stringstream value(*tok_valueiter);
132 value >> tmp;
133 if ((RandomNumberEngine_Parameters::params.count(*tok_paramiter) != 0)
134 && (tmp != RandomNumberEngine_Parameters::noset_value)) {
135 switch (RandomNumberEngine_Parameters::params[*tok_paramiter]) {
136 case (RandomNumberEngine_Parameters::param_seed):
137 params.seed = tmp;
138 break;
139 default:
140 std::cerr << "This is weird, we cannot get here!" << std::endl;
141 }
142 LOG(1, "ACCEPT: Value for token " << *tok_paramiter << " set.");
143 } else {
144 LOG(1, "REJECT: Value for token " << *tok_paramiter << " not specified.");
145 }
146 } else {
147 ist.setstate(std::ios::eofbit);
148 }
149 }
150 return ist;
151}
Note: See TracBrowser for help on using the repository browser.