Bayeux  3.4.1
Core Foundation library for SuperNEMO
seed_manager.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2011-02-26
4  * Last modified : 2012-06-08
5  *
6  * Copyright (C) 2011 Francois Mauger <mauger@lpccaen.in2p3.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or (at
11  * your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301, USA.
22  *
23  * Description:
24  *
25  * A manager for PRNG's seeds
26  *
27  * History:
28  *
29  */
30 
31 #ifndef MYGSL_SEED_MANAGER_H
32 #define MYGSL_SEED_MANAGER_H 1
33 
34 // Standard library:
35 #include <iostream>
36 #include <map>
37 #include <string>
38 #include <vector>
39 
40 // Third party:
41 // - Boost:
42 #include <boost/cstdint.hpp>
43 // - Bayeux/datatools :
44 #include <datatools/bit_mask.h>
45 
46 namespace mygsl {
47 class rng;
48 
60 class seed_manager {
61  public:
72  };
73 
75  static bool seed_is_valid(int32_t seed);
76 
77  public:
79  seed_manager ();
80 
82  virtual ~seed_manager ();
83 
85  void get_labels (std::vector<std::string> & labels_) const;
86 
88  bool has_seed (const std::string & label_) const;
89 
91  void add_seed (const std::string & label_, int32_t seed_);
92 
94  int32_t get_seed (const std::string & label_) const;
95 
97  void update_seed (const std::string & label_, int32_t seed_);
98 
100  void invalidate_seed (const std::string & label_);
101 
103  void clear ();
104 
106  void invalidate ();
107 
109  void all_time_seeds ();
110 
112  void all_auto_seeds ();
113 
115  void transform_time_seeds (bool allow_duplication_ = false);
116 
118  void ensure_different_seeds ();
119 
121  bool all_different_seeds () const;
122 
124  bool has_auto_seeds () const;
125 
127  bool has_time_seeds () const;
128 
130  bool has_invalid_seeds () const;
131 
133  size_t size () const;
134 
136  bool empty () const;
137 
138 
140  void set_init_seed_flags (uint32_t);
141 
143  uint32_t get_init_seed_flags () const;
144 
146  void dump (std::ostream &) const;
147 
149  friend std::ostream & operator<< (std::ostream &, const seed_manager &);
150 
152  friend std::istream & operator>> (std::istream &, seed_manager &);
153 
154  protected:
155  void _ensure_different_seeds (mygsl::rng * random_ = 0);
156 
157  int32_t _set_seed_for_seeds ();
158 
159  void _set_seed(const std::string & label_, int32_t seed_);
160 
161  private:
162  void _set_init_seed_flags_();
163 
164  private:
165  uint32_t _init_seed_flags_;
166  typedef std::map<std::string, int32_t> dict_type;
168  dict_type _dict_;
169 };
170 
173 
174 } // end of namespace mygsl
175 
176 #endif // MYGSL_SEED_MANAGER_H
177 
178 // Local Variables:
179 // mode: c++
180 // coding: utf-8
181 // End:
friend std::istream & operator>>(std::istream &, seed_manager &)
Load the seeds informations froma stream.
friend std::ostream & operator<<(std::ostream &, const seed_manager &)
Store the seeds informations in a stream.
int32_t get_seed(const std::string &label_) const
Get the seed value associated to a PRNG with a given label.
bool has_seed(const std::string &label_) const
Check is a PRNG with a given label has an associated seed.
void _set_seed(const std::string &label_, int32_t seed_)
bool has_time_seeds() const
Check if some valid seeds are 'time' :
static const uint32_t bit01
Definition: bit_mask.h:28
static const uint32_t bit03
Definition: bit_mask.h:30
void all_auto_seeds()
Make all seeds associated to all PRNGs set automatically.
void invalidate_seed(const std::string &label_)
Invalidate the seed value associated to a PRNG with a given label.
void clear()
Clear the list of stored seeds.
static const uint32_t bit04
Definition: bit_mask.h:31
bool has_auto_seeds() const
Check if some valid seeds are 'auto' :
bool empty() const
Check if the manager is empty.
bool has_invalid_seeds() const
Check if some seeds are 'invalid' :
int32_t _set_seed_for_seeds()
void set_init_seed_flags(uint32_t)
Set the entropy strategy flags.
void update_seed(const std::string &label_, int32_t seed_)
Change the seed value associated to a PRNG with a given label.
static bool seed_is_valid(int32_t seed)
Return true if supplied integer can be treated as a seed.
seed_manager prng_seed_manager
WHY IS THIS NEEDED???????
Definition: seed_manager.h:172
void _ensure_different_seeds(mygsl::rng *random_=0)
void transform_time_seeds(bool allow_duplication_=false)
Compute the effective seeds' values from the current time.
static const uint32_t bit02
Definition: bit_mask.h:29
void ensure_different_seeds()
Compute the effective seeds' values to be all different from each others.
void invalidate()
Make all seeds associated to all PRNGs invalid.
size_t size() const
Returns the number of PRNG's seed values storedin the manager.
Top-level namespace of the Bayeux/mygsl module library.
Definition: base_decay_driver.h:47
Definition: seed_manager.h:60
Definition: seed_manager.h:71
void dump(std::ostream &) const
Basic print.
void all_time_seeds()
Make all seeds associated to all PRNGs set by the current time.
Definition: seed_manager.h:67
init_seed_from_type
The entropy strategy used to choose a seed for randomization of seeds.
Definition: seed_manager.h:63
virtual ~seed_manager()
Destructor:
static const uint32_t bit00
Definition: bit_mask.h:27
void add_seed(const std::string &label_, int32_t seed_)
Install the seed value associated to a PRNG with a given label.
uint32_t get_init_seed_flags() const
Return the entropy strategy flags.
Definition: seed_manager.h:69
Pseudo random number generator.
Definition: rng.h:53
bool all_different_seeds() const
Check if all valid seeds are differents :
void get_labels(std::vector< std::string > &labels_) const
Build an array of all the PRNGs' labels stored in the manager.
seed_manager()
Default constructor: