gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
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 175 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 181 of file util_types.hpp.

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

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 213 of file util_types.hpp.

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

214  {
215  str errmsg = "You just tried to dereference a GAMBIT safe pointer that has value";
216  errmsg += "\nNULL. Bad idea. Probably you tried to retrieve a conditional"
217  "\ndependency that has not been activated because the necessary condition"
218  "\nhas not been met, or you tried to access a model parameter for a model"
219  "\nthat you are not actually scanning. This means there is a bug in one"
220  "\nof your module functions.";
221  utils_error().raise(LOCAL_INFO,errmsg);
222  }
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 187 of file util_types.hpp.

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

◆ 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 201 of file util_types.hpp.

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

◆ 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 194 of file util_types.hpp.

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

◆ set()

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

Set pointer.

Definition at line 184 of file util_types.hpp.

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

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 210 of file util_types.hpp.


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