BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
ROOT::Math::GSLRngWrapper Class Reference

Description

GSLRngWrapper class to wrap gsl_rng structure

Definition at line 25 of file GSLRngWrapper.h.

Public Member Functions

 GSLRngWrapper ()
 
 GSLRngWrapper (const gsl_rng *r)
 
 GSLRngWrapper (const gsl_rng_type *type)
 
 GSLRngWrapper (GSLRngWrapper &r)
 
 ~GSLRngWrapper ()
 
void Allocate ()
 
void Free ()
 
GSLRngWrapperoperator= (const GSLRngWrapper &rhs)
 
void PrintState () const
 
gsl_rng * Rng ()
 
const gsl_rng * Rng () const
 
void SetDefaultType ()
 
void SetType (const gsl_rng_type *type)
 

Private Attributes

bool fOwn
 
gsl_rng * fRng
 
const gsl_rng_type * fRngType
 

Constructor & Destructor Documentation

◆ GSLRngWrapper() [1/4]

ROOT::Math::GSLRngWrapper::GSLRngWrapper ( )
inline

Default constructor

Definition at line 33 of file GSLRngWrapper.h.

33  :
34  fOwn(0),
35  fRng(0),
36  fRngType(0)
37  {
38  }
const gsl_rng_type * fRngType

◆ GSLRngWrapper() [2/4]

ROOT::Math::GSLRngWrapper::GSLRngWrapper ( const gsl_rng_type *  type)
inline

Constructor with type

Definition at line 43 of file GSLRngWrapper.h.

43  :
44  fOwn(1),
45  fRng(0),
46  fRngType(type)
47  {
48  }

◆ GSLRngWrapper() [3/4]

ROOT::Math::GSLRngWrapper::GSLRngWrapper ( const gsl_rng *  r)
inline

construct from an existing gsl_rng it is managed externally - so will not be deleted at the end

Definition at line 54 of file GSLRngWrapper.h.

54  :
55  fOwn(0),
56  fRngType(0)
57  {
58  fRng = const_cast<gsl_rng *>(r);
59  }

References fRng.

◆ GSLRngWrapper() [4/4]

ROOT::Math::GSLRngWrapper::GSLRngWrapper ( GSLRngWrapper r)
inline

Copy constructor - clone the GSL object and manage it

Definition at line 64 of file GSLRngWrapper.h.

64  :
65  fOwn(1),
66  fRngType(r.fRngType)
67  {
68  fRng = gsl_rng_clone(r.fRng);
69  }

References fRng.

◆ ~GSLRngWrapper()

ROOT::Math::GSLRngWrapper::~GSLRngWrapper ( )
inline

Destructor (free the rng if not done before)

Definition at line 92 of file GSLRngWrapper.h.

92  {
93  if (fOwn) Free();
94  }

References fOwn, and Free().

Here is the call graph for this function:

Member Function Documentation

◆ Allocate()

void ROOT::Math::GSLRngWrapper::Allocate ( )
inline

Definition at line 96 of file GSLRngWrapper.h.

96  {
97  if (fRngType == 0) SetDefaultType();
98  if (fRng != 0 && fOwn) Free();
99  fRng = gsl_rng_alloc( fRngType );
100  fOwn = true;
101  }

References fOwn, Free(), fRng, fRngType, and SetDefaultType().

Here is the call graph for this function:

◆ Free()

void ROOT::Math::GSLRngWrapper::Free ( )
inline

Definition at line 103 of file GSLRngWrapper.h.

103  {
104  if (!fOwn) return; // no operation if pointer is not own
105  //std::cout << "free gslrng " << fRngType << " " << fRng << std::endl;
106  if (fRng != 0) gsl_rng_free(fRng);
107  fRng = 0;
108  }

References fOwn, and fRng.

Referenced by ~GSLRngWrapper(), Allocate(), and operator=().

◆ operator=()

GSLRngWrapper& ROOT::Math::GSLRngWrapper::operator= ( const GSLRngWrapper rhs)
inline

Assignment operator

Definition at line 74 of file GSLRngWrapper.h.

74  {
75  if (this == &rhs) return *this; // time saving self-test
76  fRngType = rhs.fRngType;
77  int iret = 0;
78  if (fRngType == rhs.fRngType) {
79  iret = gsl_rng_memcpy(fRng, rhs.fRng);
80  if (!iret) return *this;
81  }
82  // otherwise create a new copy
83  if (fOwn) Free();
84  fRng = gsl_rng_clone(rhs.fRng);
85  fOwn = true;
86  return *this;
87  }

References fOwn, Free(), fRng, and fRngType.

Here is the call graph for this function:

◆ PrintState()

void ROOT::Math::GSLRngWrapper::PrintState ( ) const
inline

Definition at line 121 of file GSLRngWrapper.h.

121  {
122  gsl_rng_print_state(fRng);
123  }

References fRng.

◆ Rng() [1/2]

gsl_rng* ROOT::Math::GSLRngWrapper::Rng ( )
inline

Definition at line 125 of file GSLRngWrapper.h.

125 { return fRng; }

References fRng.

◆ Rng() [2/2]

const gsl_rng* ROOT::Math::GSLRngWrapper::Rng ( ) const
inline

Definition at line 127 of file GSLRngWrapper.h.

127 { return fRng; }

References fRng.

◆ SetDefaultType()

void ROOT::Math::GSLRngWrapper::SetDefaultType ( )
inline

Definition at line 115 of file GSLRngWrapper.h.

115  {
116  // construct default engine
117  gsl_rng_env_setup();
118  fRngType = gsl_rng_default;
119  }

References fRngType.

Referenced by Allocate().

◆ SetType()

void ROOT::Math::GSLRngWrapper::SetType ( const gsl_rng_type *  type)
inline

Definition at line 111 of file GSLRngWrapper.h.

111  {
112  fRngType = type;
113  }

References fRngType.

Member Data Documentation

◆ fOwn

bool ROOT::Math::GSLRngWrapper::fOwn
private

Definition at line 133 of file GSLRngWrapper.h.

Referenced by ~GSLRngWrapper(), Allocate(), Free(), and operator=().

◆ fRng

gsl_rng* ROOT::Math::GSLRngWrapper::fRng
private

Definition at line 134 of file GSLRngWrapper.h.

Referenced by GSLRngWrapper(), Allocate(), Free(), operator=(), PrintState(), and Rng().

◆ fRngType

const gsl_rng_type* ROOT::Math::GSLRngWrapper::fRngType
private

Definition at line 135 of file GSLRngWrapper.h.

Referenced by Allocate(), operator=(), SetDefaultType(), and SetType().


The documentation for this class was generated from the following file: