NEST  2.6.0,not_revisioned_source_dir@0
randomdev.h
Go to the documentation of this file.
1 /*
2  * randomdev.h
3  *
4  * This file is part of NEST.
5  *
6  * Copyright (C) 2004 The NEST Initiative
7  *
8  * NEST 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 2 of the License, or
11  * (at your option) any later version.
12  *
13  * NEST is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef RANDOMDEV_H
24 #define RANDOMDEV_H
25 
26 #include <cassert>
27 #include "randomgen.h"
28 #include "dictdatum.h"
29 #include "librandom_exceptions.h"
30 
109 namespace librandom {
110 
111  class RandomDev;
112 
119  typedef lockPTR<RandomDev> RdvPtr;
120 
121 
122 
131  class RandomDev {
132 
133  public:
134 
139  RandomDev(RngPtr rng = RngPtr(0)) : rng_(rng) {}
140 
142  virtual ~RandomDev() {};
143 
155  virtual double operator()(void);
156  virtual double operator()(RngPtr) const = 0;
157 
161  virtual long ldev(void);
162  virtual long ldev(RngPtr) const;
163 
167  virtual bool has_ldev() const { return false; }
168 
170  void set_rng(RngPtr rng) { rng_ = rng; }
171 
181  virtual void set_status(const DictionaryDatum&) =0;
182 
192  virtual void get_status(DictionaryDatum&) const =0;
193 
194  protected:
196  };
197 
198  inline
200  {
201  assert(rng_.valid());
202  return (*this)(rng_);
203  }
204 
205  inline
206  long RandomDev::ldev(void)
207  {
208  assert(rng_.valid());
209  return this->ldev(rng_);
210  }
211 
212 
217  public:
219  virtual RdvPtr create() const =0;
220  virtual RdvPtr create(RngPtr rng) const =0;
221  };
222 
227  template <typename DevType>
229 
230  public:
231 
233  RdvPtr create() const
234  {
235  return RdvPtr(new DevType());
236  }
237 
239  RdvPtr create(RngPtr rng) const
240  {
241  return RdvPtr(new DevType(rng));
242  }
243 
244  };
245 
246 
247 }
248 
249 #endif
RandomDev(RngPtr rng=RngPtr(0))
Construct with (single-threaded) or without (multithreaded) RNG.
Definition: randomdev.h:139
virtual bool has_ldev() const
true if RDG implements ldev function
Definition: randomdev.h:167
virtual double operator()(void)
Operator delivering doubles.
Definition: randomdev.h:199
assert(pNet!=0)
RngPtr rng_
store underlying RNG
Definition: randomdev.h:195
bool valid(void) const
< returns true if and only if obj->pointee != NULL
Definition: lockptr.h:307
lockPTR< RandomGen > RngPtr
Common lock-pointer type for RNG.
Definition: randomgen.h:208
virtual ~GenericRandomDevFactory()
Definition: randomdev.h:218
virtual ~RandomDev()
ensure proper clean-up
Definition: randomdev.h:142
void set_rng(RngPtr rng)
set RNG
Definition: randomdev.h:170
RdvPtr create() const
create unbound deviate generator
Definition: randomdev.h:233
Abstract base class for access to non-uniform random deviate generators.
Definition: randomdev.h:131
lockPTR< RandomDev > RdvPtr
Common lock-pointer type for Random deviate generators.
Definition: randomdev.h:111
RdvPtr create(RngPtr rng) const
create deviate generator given uniform number generator
Definition: randomdev.h:239
Generic factory class for RandomDev.
Definition: randomdev.h:216
virtual void set_status(const DictionaryDatum &)=0
set distribution parameters from SLI interface
virtual long ldev(void)
integer valued functions for discrete distributions
Definition: randomdev.h:206
virtual RdvPtr create() const =0
virtual void get_status(DictionaryDatum &) const =0
get distribution parameters from SLI interface
Factory class for generating objects of type RandomDev.
Definition: randomdev.h:228