gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool

A safe pointer that throws an informative error if you try to dereference it when nullified, and cannot be used to overwrite the thing it points to. More...

#include <util_types.hpp>

Inheritance diagram for Gambit::safe_ptr< TYPE >:

Public Member Functions

 safe_ptr (TYPE *in_ptr=NULL)
 Construct-o-safe_ptr. More...
 
virtual void set (TYPE *in_ptr)
 Set pointer. More...
 
virtual const TYPE & operator* () const
 Dereference pointer. More...
 
virtual const TYPE & operator[] (int index) const
 Dereference pointer as if it is an array. More...
 
virtual const TYPE * operator-> () const
 Access is allowed to const member functions only. More...
 

Static Protected Member Functions

static void dieGracefully ()
 Failure message invoked when the user tries to dereference a null safe_ptr. More...
 

Protected Attributes

const TYPE * ptr
 The actual underlying pointer, interpreted as a pointer to constant value. More...
 

Detailed Description

template<typename TYPE>
class Gambit::safe_ptr< TYPE >

A safe pointer that throws an informative error if you try to dereference it when nullified, and cannot be used to overwrite the thing it points to.

Definition at line 167 of file util_types.hpp.

Constructor & Destructor Documentation

◆ safe_ptr()

template<typename TYPE>
Gambit::safe_ptr< TYPE >::safe_ptr ( TYPE *  in_ptr = NULL)
inline

Construct-o-safe_ptr.

Definition at line 173 of file util_types.hpp.

173 { ptr = in_ptr; }
const TYPE * ptr
The actual underlying pointer, interpreted as a pointer to constant value.
Definition: util_types.hpp:202

Member Function Documentation

◆ dieGracefully()

template<typename TYPE>
static void Gambit::safe_ptr< TYPE >::dieGracefully ( )
inlinestaticprotected

Failure message invoked when the user tries to dereference a null safe_ptr.

Definition at line 205 of file util_types.hpp.

Referenced by Gambit::omp_safe_ptr< TYPE >::operator*().

206  {
207  str errmsg = "You just tried to dereference a GAMBIT safe pointer that has value";
208  errmsg += "\nNULL. Bad idea. Probably you tried to retrieve a conditional"
209  "\ndependency that has not been activated because the necessary condition"
210  "\nhas not been met, or you tried to access a model parameter for a model"
211  "\nthat you are not actually scanning. This means there is a bug in one"
212  "\nof your module functions.";
213  utils_error().raise(LOCAL_INFO,errmsg);
214  }
EXPORT_SYMBOLS error & utils_error()
Utility errors.
#define LOCAL_INFO
Definition: local_info.hpp:34
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
Here is the caller graph for this function:

◆ operator*()

template<typename TYPE>
virtual const TYPE& Gambit::safe_ptr< TYPE >::operator* ( ) const
inlinevirtual

Dereference pointer.

Reimplemented in Gambit::omp_safe_ptr< TYPE >.

Definition at line 179 of file util_types.hpp.

180  {
181  if (ptr == NULL) dieGracefully();
182  return *ptr;
183  }
static void dieGracefully()
Failure message invoked when the user tries to dereference a null safe_ptr.
Definition: util_types.hpp:205
const TYPE * ptr
The actual underlying pointer, interpreted as a pointer to constant value.
Definition: util_types.hpp:202

◆ operator->()

template<typename TYPE>
virtual const TYPE* Gambit::safe_ptr< TYPE >::operator-> ( ) const
inlinevirtual

Access is allowed to const member functions only.

Definition at line 193 of file util_types.hpp.

194  {
195  if (ptr == NULL) dieGracefully();
196  return ptr;
197  }
static void dieGracefully()
Failure message invoked when the user tries to dereference a null safe_ptr.
Definition: util_types.hpp:205
const TYPE * ptr
The actual underlying pointer, interpreted as a pointer to constant value.
Definition: util_types.hpp:202

◆ operator[]()

template<typename TYPE>
virtual const TYPE& Gambit::safe_ptr< TYPE >::operator[] ( int  index) const
inlinevirtual

Dereference pointer as if it is an array.

Definition at line 186 of file util_types.hpp.

187  {
188  if (ptr == NULL) dieGracefully();
189  return *(ptr+index);
190  }
static void dieGracefully()
Failure message invoked when the user tries to dereference a null safe_ptr.
Definition: util_types.hpp:205
const TYPE * ptr
The actual underlying pointer, interpreted as a pointer to constant value.
Definition: util_types.hpp:202

◆ set()

template<typename TYPE>
virtual void Gambit::safe_ptr< TYPE >::set ( TYPE *  in_ptr)
inlinevirtual

Set pointer.

Definition at line 176 of file util_types.hpp.

176 { ptr = in_ptr; }
const TYPE * ptr
The actual underlying pointer, interpreted as a pointer to constant value.
Definition: util_types.hpp:202

Member Data Documentation

◆ ptr

template<typename TYPE>
const TYPE* Gambit::safe_ptr< TYPE >::ptr
protected

The actual underlying pointer, interpreted as a pointer to constant value.

Definition at line 202 of file util_types.hpp.


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