Ignore:
Timestamp:
Nov 5, 2008, 9:08:55 PM (13 years ago)
Author:
Peter
Message:

implementing copying in RNG_state. Previously compiler generated versions were used which was not sound. Also disallowed assignment of singleton RNG. Assignment of a singleton class does not make sense.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/random/random.cc

    r1487 r1614  
    2525#include "yat/utility/Exception.h"
    2626
     27#include <cassert>
    2728#include <fstream>
    2829#include <sstream>
     
    115116  RNG_state::RNG_state(const RNG* rng)
    116117  {
    117     if (!(rng_ = gsl_rng_clone(rng->rng())))
    118       throw utility::GSL_error("RNG_state::RNG_state failed to allocate memory");
     118    clone(*rng->rng());
     119  }
     120 
     121
     122  RNG_state::RNG_state(const RNG_state& state)
     123  {
     124    clone(*state.rng());
    119125  }
    120126 
     
    129135  {
    130136    return rng_;
     137  }
     138
     139
     140  void RNG_state::clone(const gsl_rng& rng)
     141  {
     142    assert(rng_!=&rng);
     143    if (!(rng_ = gsl_rng_clone(&rng)))
     144      throw utility::GSL_error("RNG_state::RNG_state failed to allocate memory");
     145  }
     146
     147  RNG_state& RNG_state::operator=(const RNG_state& rhs)
     148  {
     149    if (this != &rhs) {
     150      gsl_rng_free(rng_);
     151      clone(*rhs.rng());
     152    }
     153    return *this;
    131154  }
    132155
Note: See TracChangeset for help on using the changeset viewer.