cppyabm  1.0.17
An agent-based library to integrate C++ and Python
Public Member Functions | List of all members
ref< T > Class Template Reference

Reference counting helper. More...

#include <object.h>

Public Member Functions

 ref ()
 Create a nullptr reference. More...
 
 ref (T *ptr)
 Construct a reference from a pointer. More...
 
 ref (const ref &r)
 Copy constructor. More...
 
 ref (ref &&r)
 Move constructor. More...
 
 ~ref ()
 Destroy this reference. More...
 
refoperator= (ref &&r)
 Move another reference into the current one. More...
 
refoperator= (const ref &r)
 Overwrite this reference with another reference. More...
 
refoperator= (T *ptr)
 Overwrite this reference with a pointer to another object. More...
 
bool operator== (const ref &r) const
 Compare this reference with another reference. More...
 
bool operator!= (const ref &r) const
 Compare this reference with another reference. More...
 
bool operator== (const T *ptr) const
 Compare this reference with a pointer. More...
 
bool operator!= (const T *ptr) const
 Compare this reference with a pointer. More...
 
T * operator-> ()
 Access the object referenced by this reference. More...
 
const T * operator-> () const
 Access the object referenced by this reference. More...
 
T & operator* ()
 Return a C++ reference to the referenced object. More...
 
const T & operator* () const
 Return a const C++ reference to the referenced object. More...
 
 operator T* ()
 Return a pointer to the referenced object. More...
 
T * get_ptr ()
 Return a const pointer to the referenced object. More...
 
const T * get_ptr () const
 Return a pointer to the referenced object. More...
 

Detailed Description

template<typename T>
class ref< T >

Reference counting helper.

The ref refeference template is a simple wrapper to store a pointer to an object. It takes care of increasing and decreasing the reference count of the object. When the last reference goes out of scope, the associated object will be deallocated.

Definition at line 62 of file object.h.

Constructor & Destructor Documentation

◆ ref() [1/4]

template<typename T >
ref< T >::ref ( )
inline

Create a nullptr reference.

Definition at line 65 of file object.h.

◆ ref() [2/4]

template<typename T >
ref< T >::ref ( T *  ptr)
inline

Construct a reference from a pointer.

Definition at line 68 of file object.h.

◆ ref() [3/4]

template<typename T >
ref< T >::ref ( const ref< T > &  r)
inline

Copy constructor.

Definition at line 76 of file object.h.

◆ ref() [4/4]

template<typename T >
ref< T >::ref ( ref< T > &&  r)
inline

Move constructor.

Definition at line 84 of file object.h.

◆ ~ref()

template<typename T >
ref< T >::~ref ( )
inline

Destroy this reference.

Definition at line 91 of file object.h.

Member Function Documentation

◆ get_ptr() [1/2]

template<typename T >
T* ref< T >::get_ptr ( )
inline

Return a const pointer to the referenced object.

Definition at line 167 of file object.h.

◆ get_ptr() [2/2]

template<typename T >
const T* ref< T >::get_ptr ( ) const
inline

Return a pointer to the referenced object.

Definition at line 170 of file object.h.

◆ operator T*()

template<typename T >
ref< T >::operator T* ( )
inline

Return a pointer to the referenced object.

Definition at line 164 of file object.h.

◆ operator!=() [1/2]

template<typename T >
bool ref< T >::operator!= ( const ref< T > &  r) const
inline

Compare this reference with another reference.

Definition at line 143 of file object.h.

◆ operator!=() [2/2]

template<typename T >
bool ref< T >::operator!= ( const T *  ptr) const
inline

Compare this reference with a pointer.

Definition at line 149 of file object.h.

◆ operator*() [1/2]

template<typename T >
T& ref< T >::operator* ( )
inline

Return a C++ reference to the referenced object.

Definition at line 158 of file object.h.

◆ operator*() [2/2]

template<typename T >
const T& ref< T >::operator* ( ) const
inline

Return a const C++ reference to the referenced object.

Definition at line 161 of file object.h.

◆ operator->() [1/2]

template<typename T >
T* ref< T >::operator-> ( )
inline

Access the object referenced by this reference.

Definition at line 152 of file object.h.

◆ operator->() [2/2]

template<typename T >
const T* ref< T >::operator-> ( ) const
inline

Access the object referenced by this reference.

Definition at line 155 of file object.h.

◆ operator=() [1/3]

template<typename T >
ref& ref< T >::operator= ( const ref< T > &  r)
inline

Overwrite this reference with another reference.

Definition at line 112 of file object.h.

◆ operator=() [2/3]

template<typename T >
ref& ref< T >::operator= ( ref< T > &&  r)
inline

Move another reference into the current one.

Definition at line 99 of file object.h.

◆ operator=() [3/3]

template<typename T >
ref& ref< T >::operator= ( T *  ptr)
inline

Overwrite this reference with a pointer to another object.

Definition at line 126 of file object.h.

◆ operator==() [1/2]

template<typename T >
bool ref< T >::operator== ( const ref< T > &  r) const
inline

Compare this reference with another reference.

Definition at line 140 of file object.h.

◆ operator==() [2/2]

template<typename T >
bool ref< T >::operator== ( const T *  ptr) const
inline

Compare this reference with a pointer.

Definition at line 146 of file object.h.


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