Bayeux  3.4.1
Core Foundation library for SuperNEMO
prng_state_manager.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2011-03-02
4  * Last modified : 2012-06-15
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 byx
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,
21  * Boston, MA 02110-1301, USA.
22  *
23  * Description:
24  *
25  * A manager that record the internal state of some PRNGs
26  *
27  * History:
28  *
29  */
30 
31 #ifndef MYGSL_PRNG_STATE_MANAGER_H
32 #define MYGSL_PRNG_STATE_MANAGER_H 1
33 
34 // Standard library:
35 #include <iostream>
36 #include <string>
37 #include <map>
38 
39 // Third party:
40 // - Boost:
41 #include <boost/cstdint.hpp>
42 
43 // This project:
44 #include <mygsl/rng.h>
45 
46 namespace mygsl {
47 
51  {
52  public:
53 
56  class record
57  {
58  public:
59 
61  static const size_t DEFAULT_BUFFER_SIZE = 65536;
62 
64  record ();
65 
67  virtual ~record ();
68 
69  public:
70 
73 
74  };
75 
77  typedef std::map<std::string, record> dict_type;
78 
79  public:
80 
81  static const int INVALID_COUNTER_VALUE = -1;
82 
83  const std::string & default_filename();
84 
86  bool has_filename () const;
87 
89  const std::string & get_filename () const;
90 
92  void set_filename (const std::string & = "");
93 
95  void reset_filename();
96 
98  bool has_counter () const;
99 
101  int get_counter () const;
102 
104  void set_counter (int);
105 
107  void reset_counter ();
108 
110  void increment_counter (unsigned int a_increment = 1);
111 
114 
116  prng_state_manager (const std::string &);
117 
119  virtual ~prng_state_manager ();
120 
122  void invalidate ();
123 
125  void get_labels (std::vector<std::string> & labels_) const;
126 
128  bool has_state (const std::string & label_) const;
129 
131  void add_state (const std::string & label_, size_t sz_);
132 
134  const record & get_state (const std::string & label_) const;
135 
137  record & get_state (const std::string & label_);
138 
139  //void update_state (const std::string & label_, int32_t seed_);
140 
142  void clear ();
143 
145  void reset ();
146 
148  size_t size () const;
149 
151  bool empty () const;
152 
154  void store (const std::string & filename_ = "") const;
155 
157  void load (const std::string & filename_ = "");
158 
160  void dump (std::ostream & out_ = std::clog) const;
161 
163  bool error() const;
164 
166  void reset_error();
167 
168  private:
169 
170  void _force_error(int e) const;
171 
172  private:
173 
174  int _error_code_;
175  std::string _filename_;
176  int32_t _counter_;
177  dict_type _dict_;
178 
179  };
180 
181 } // end of namespace mygsl
182 
183 #endif // MYGSL_PRNG_STATE_MANAGER_H
184 
185 /* Local Variables: */
186 /* mode: c++ */
187 /* coding: utf-8 */
188 /* End: */
virtual ~record()
Destructor.
void increment_counter(unsigned int a_increment=1)
Increment the manager's running counter value by a given value.
std::map< std::string, record > dict_type
An alias for the embedded dictionary container class.
Definition: prng_state_manager.h:77
void invalidate()
Invalidate :
record()
Default constructor.
const std::string & default_filename()
prng_state_manager()
Default constructor.
Internal record that store the internal state of a PRNG.
Definition: prng_state_manager.h:56
static const int INVALID_COUNTER_VALUE
Constant that represents an invalid value for a counter.
Definition: prng_state_manager.h:81
bool has_state(const std::string &label_) const
Check if the manager stores the internal state of a PRNG with a given label.
void reset_error()
Reset error.
size_t size() const
Return the number of internal state records.
A manager that can store the internal states associated to a set of PRNGs addressed with some labels.
Definition: prng_state_manager.h:50
void clear()
Clear the content of the manager.
void set_counter(int)
Set the manager's running counter value.
std::vector< unsigned char > state_buffer_type
Definition: rng.h:60
mygsl::rng::state_buffer_type state_buffer
Buffer to store a PRNG internal state.
Definition: prng_state_manager.h:72
virtual ~prng_state_manager()
Destructor:
bool has_counter() const
Check if the manager has a running counter value.
void set_filename(const std::string &="")
Set the backup filename associated to the manager.
const record & get_state(const std::string &label_) const
Get a record that hosts the internal state of a PRNG with a given label (non mutable)
void load(const std::string &filename_="")
Load the content of the manager from a file with given filename.
Top-level namespace of the Bayeux/mygsl module library.
Definition: base_decay_driver.h:47
void reset_counter()
Reset the manager's running counter value.
static const size_t DEFAULT_BUFFER_SIZE
Default size of a buffer used to store PRNG's internal state.
Definition: prng_state_manager.h:61
void add_state(const std::string &label_, size_t sz_)
Add storage for the internal state of given size for a PRNG with a given label.
const std::string & get_filename() const
Get the backup filename associated to the manager.
bool has_filename() const
Check if a backup filename is associated to the manager.
int get_counter() const
Get the manager's running counter value.
bool empty() const
Check if the manager has no stored internal state records.
void dump(std::ostream &out_=std::clog) const
Basic print.
void get_labels(std::vector< std::string > &labels_) const
Build an array with all PRNGs' labels stored in the manager.
void reset_filename()
Reset the backup filename associated to the manager.
void reset()
Reset the manager.
void store(const std::string &filename_="") const
Store the content of the manager in a file with given filename.
bool error() const
Check error status.