Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Burger::SmartPointer< T > Class Template Reference

Template for auto reference counting a pointer. More...

Inheritance diagram for Burger::SmartPointer< T >:

Public Member Functions

 SmartPointer (T *pData) noexcept
 Initialize a smart pointer.
 
 SmartPointer () noexcept
 Initialize a smart pointer to nullptr.
 
 SmartPointer (const SmartPointer< T > &rData) noexcept
 Copy a smart pointer.
 
 ~SmartPointer ()
 Release a reference to a smart pointer.
 
void operator= (const SmartPointer< T > &rData) noexcept
 Replace the current pointer.
 
void operator= (T *pData) noexcept
 Replace the current pointer.
 
T * operator-> () const noexcept
 Get the current pointer.
 
T & operator* () const noexcept
 Get the current reference.
 
 operator T* () const noexcept
 Get the current pointer.
 
T * GetPtr () const noexcept
 Get the current pointer.
 
uint_t operator== (const SmartPointer< T > &rData) const noexcept
 Test for equality.
 
uint_t operator!= (const SmartPointer< T > &rData) const noexcept
 Test for inequality.
 
uint_t operator== (const T *pData) const noexcept
 Test for equality.
 
uint_t operator!= (const T *pData) const noexcept
 Test for inequality.
 

Private Member Functions

void Replace (T *pData) noexcept
 Replace the current pointer.
 

Private Attributes

T * m_pData
 Private copy of the pointer this class is tracking.
 

Detailed Description

template<class T>
class Burger::SmartPointer< T >

Template for auto reference counting a pointer.


For shared pointer classes that implement the AddRef() and Release() functions, this template will create a structure that contains a single pointer that is reference counted so shared data can be tracked.

// Declare an empty pointer
// Allocate a new object and +1 to the reference
g_pShared = new Burger::SmartObject;
// Allocate a new object and +1 to the reference
// and delete the old one by calling Release() on it
g_pShared = new Burger::SmartObject;
// Deletes the object by calling Release()
// which auto destructs the object
g_pShared = nullptr;
Template for auto reference counting a pointer.
Definition burger.h:13993

Constructor & Destructor Documentation

◆ SmartPointer() [1/3]

template<class T >
Burger::SmartPointer< T >::SmartPointer ( T * pData)
inlinenoexcept

Initialize a smart pointer.


Call AddRef() to the pointer if it's not nullptr and store the pointer inside the class for tracking.

Parameters
pDataPointer to an instance of the class T or nullptr
See also
SmartPointer() or SmartPointer(const SmartPointer &)

◆ SmartPointer() [2/3]

template<class T >
Burger::SmartPointer< T >::SmartPointer ( )
inlinenoexcept

Initialize a smart pointer to nullptr.


Initialize to power up default.

See also
SmartPointer(T*) or SmartPointer(const SmartPointer &)

◆ SmartPointer() [3/3]

template<class T >
Burger::SmartPointer< T >::SmartPointer ( const SmartPointer< T > & rData)
inlinenoexcept

Copy a smart pointer.


Call AddRef() to the pointer if it's not nullptr and store a copy of the pointer inside the class for tracking.

Parameters
rDataReference to an instance to another SmartPointer
See also
SmartPointer() or SmartPointer(T*)

◆ ~SmartPointer()

template<class T >
Burger::SmartPointer< T >::~SmartPointer ( )
inline

Release a reference to a smart pointer.


If the pointer contained is not nullptr, call Release() on it. The internal pointer is then set tonullptr to ensure there are no dangling pointers

See also
SmartPointer(T*) or SmartPointer(const SmartPointer &)

Member Function Documentation

◆ GetPtr()

template<class T >
T * Burger::SmartPointer< T >::GetPtr ( ) const
inlinenoexcept

Get the current pointer.


Return an untracked copy of the pointer. The pointer can be nullptr if there is no pointer being tracked.

Returns
nullptr or a pointer to an instance of a T class
See also
operator->() or SmartPointer::operator T*() const

◆ operator T*()

template<class T >
Burger::SmartPointer< T >::operator T* ( ) const
inlinenoexcept

Get the current pointer.


Return an untracked copy of the pointer. The pointer can be nullptr if there is no pointer being tracked.

Returns
nullptr or a pointer to an instance of a T class
See also
GetPtr() const or operator->()

Return an untracked copy of the pointer. The pointer can be nullptr if there is no pointer being tracked.

Returns
nullptr or a pointer to an instance of a T class
See also
GetPtr() const or operator->()

◆ operator!=() [1/2]

template<class T >
uint_t Burger::SmartPointer< T >::operator!= ( const SmartPointer< T > & rData) const
inlinenoexcept

Test for inequality.


Compare the pointers for inequality and if not equal, return TRUE

Parameters
rDataReference to an instance of another SmartPointer
Returns
TRUE if not equal, FALSE if equal
See also
operator==(const SmartPointer &) const or operator!=(const T*) const

◆ operator!=() [2/2]

template<class T >
uint_t Burger::SmartPointer< T >::operator!= ( const T * pData) const
inlinenoexcept

Test for inequality.


Compare the pointers for inequality and if not equal, return TRUE

Parameters
pDataPointer to an instance of the class T or nullptr
Returns
TRUE if not equal, FALSE if equal
See also
operator==(const T*) const or operator!=(const SmartPointer&) const

◆ operator*()

template<class T >
T & Burger::SmartPointer< T >::operator* ( ) const
inlinenoexcept

Get the current reference.


Return an untracked reference of the object. The reference can be nullptr if there is no pointer being tracked.

Returns
nullptr or a reference to an instance of a T class
See also
SmartPointer::operator T*() const, GetPtr() const or operator->()

◆ operator->()

template<class T >
T * Burger::SmartPointer< T >::operator-> ( ) const
inlinenoexcept

Get the current pointer.


Return an untracked copy of the pointer. The pointer can be nullptr if there is no pointer being tracked.

Returns
nullptr or a pointer to an instance of a T class
See also
GetPtr()

◆ operator=() [1/2]

template<class T >
void Burger::SmartPointer< T >::operator= ( const SmartPointer< T > & rData)
inlinenoexcept

Replace the current pointer.


Test if the pointer is different to what is already contained in the class and if so, it will Release() the old data (If not nullptr) and call AddRef() to the new data (If not nullptr) and store the pointer to the new data in the class.

Parameters
rDataReference to an instance of another SmartPointer
See also
operator=(T*)

◆ operator=() [2/2]

template<class T >
void Burger::SmartPointer< T >::operator= ( T * pData)
inlinenoexcept

Replace the current pointer.


Test if the pointer is different to what is already contained in the class and if so, it will Release() the old data (If not nullptr) and call AddRef() to the new data (If not nullptr) and store the pointer to the new data in the class.

Parameters
pDataPointer to an instance of the class T or nullptr
See also
operator=(const SmartPointer &)

◆ operator==() [1/2]

template<class T >
uint_t Burger::SmartPointer< T >::operator== ( const SmartPointer< T > & rData) const
inlinenoexcept

Test for equality.


Compare the pointers for equality and if equal, return TRUE

Parameters
rDataReference to an instance of another SmartPointer
Returns
TRUE if equal, FALSE if not
See also
operator!=(const SmartPointer &) const or operator==(const T*) const

◆ operator==() [2/2]

template<class T >
uint_t Burger::SmartPointer< T >::operator== ( const T * pData) const
inlinenoexcept

Test for equality.


Compare the pointers for equality and if equal, return TRUE

Parameters
pDataPointer to an instance of the class T or nullptr
Returns
TRUE if equal, FALSE if not
See also
operator!=(const T*) const or operator==(const SmartPointer &) const

◆ Replace()

template<class T >
void Burger::SmartPointer< T >::Replace ( T * pData)
inlineprivatenoexcept

Replace the current pointer.


This private function will test if the pointer is different to what is already contained in the class and if so, it will Release() the old data (If not nullptr) and call AddRef() to the new data (If not nullptr) and store the pointer to the new data in the class.

Parameters
pDataPointer to an instance of the class T or nullptr
See also
operator=(T*) or operator= (const SmartPointer &)

Member Data Documentation

◆ m_pData

template<class T >
T* Burger::SmartPointer< T >::m_pData
private

Private copy of the pointer this class is tracking.