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::WeakPointer< T > Class Template Reference

Template for tracking an object that could self destruct. More...

Inheritance diagram for Burger::WeakPointer< T >:
Collaboration diagram for Burger::WeakPointer< T >:

Public Member Functions

 WeakPointer () noexcept
 Initialize a weak pointer to nullptr.
 
 WeakPointer (T *pData) noexcept
 Initialize a weak pointer.
 
 WeakPointer (const WeakPointer< T > &rData) noexcept
 Copy a weak pointer.
 
 WeakPointer (const SmartPointer< T > &rData) noexcept
 Copy a weak pointer from a SmartPointer object.
 
 ~WeakPointer ()
 Release a reference to a weak pointer.
 
void operator= (T *pData) noexcept
 Track a new object.
 
void operator= (const SmartPointer< T > &rData) noexcept
 Track a new object.
 
T * operator-> () const noexcept
 Get the current pointer.
 
T * GetPtr () const noexcept
 Get the current pointer.
 
 operator SmartPointer< T > () noexcept
 Award shared ownership of an object.
 
uint_t operator== (const T *pData) const noexcept
 Test for equality.
 
uint_t operator!= (const T *pData) const noexcept
 Test for inequality.
 
uint_t operator== (const T *pData) noexcept
 Test for equality.
 
uint_t operator!= (const T *pData) noexcept
 Test for inequality.
 
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 SmartPointer< T > &rData) noexcept
 Test for equality.
 
uint_t operator!= (const SmartPointer< T > &rData) noexcept
 Test for inequality.
 
uint_t operator== (const WeakPointer< T > &rData) const noexcept
 Test for equality.
 
uint_t operator!= (const WeakPointer< T > &rData) const noexcept
 Test for inequality.
 

Private Member Functions

T * Dereference (void) const noexcept
 Return the pointer to an object.
 

Private Attributes

T * m_pData
 Pointer to the object being tracked.
 
SmartPointer< ProxyReferenceCounterm_pProxy
 Pointer to the object the tracked object will notify if it's deleted.
 

Detailed Description

template<class T>
class Burger::WeakPointer< T >

Template for tracking an object that could self destruct.


For objects that can be destroyed by other systems or can self destruct, this pointer template class will handle monitoring the object and will detect if the object isn't present in the system anymore.

class SharedObject {
// Allow WeakPointer to work
public:
void DoStuff(void);
};
void foo()
{
{
SharedObject shared;
pShared = &shared;
if (pShared.GetPtr()!=nullptr) {
printf("shared is in scope!!");
}
}
if (pShared.GetPtr()==nullptr) {
printf("shared is out of scope!!");
}
}
#define BURGER_ALLOW_WEAK_POINTERS()
Creates support for Burger::WeakPointer.
Definition burger.h:13976
Template for tracking an object that could self destruct.
Definition burger.h:14087
T * GetPtr() const noexcept
Get the current pointer.
Definition burger.h:14153
See also
BURGER_ALLOW_WEAK_POINTERS()

Constructor & Destructor Documentation

◆ WeakPointer() [1/4]

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

Initialize a weak pointer to nullptr.


Initialize to power up default.

See also
WeakPointer::WeakPointer(T*) or WeakPointer::WeakPointer(const WeakPointer &)

◆ WeakPointer() [2/4]

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

Initialize a weak pointer.


Obtain the pointer to the object's ProxyReferenceCounter and call ProxyReferenceCounter::AddRef() on it. Store the pointer inside the class for tracking.

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

◆ WeakPointer() [3/4]

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

Copy a weak pointer.


Obtain the pointer to the object's ProxyReferenceCounter and call ProxyReferenceCounter::AddRef() on it. Store the pointer inside the class for tracking.

Parameters
rDataReference to an instance of another WeakPointer
See also
WeakPointer::WeakPointer() or WeakPointer::WeakPointer(T*)

◆ WeakPointer() [4/4]

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

Copy a weak pointer from a SmartPointer object.


Obtain the pointer to the object's ProxyReferenceCounter and call ProxyReferenceCounter::AddRef() on it. Store the pointer inside the class for tracking.

Parameters
rDataReference to an instance of a SmartPointer
See also
WeakPointer::WeakPointer() or WeakPointer::WeakPointer(T*)

◆ ~WeakPointer()

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

Release a reference to a weak pointer.


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

See also
WeakPointer::WeakPointer(T*) or WeakPointer::WeakPointer(const WeakPointer &)

Member Function Documentation

◆ Dereference()

template<class T >
T * Burger::WeakPointer< T >::Dereference ( void ) const
inlineprivatenoexcept

Return the pointer to an object.


Test if the object exists, and if so, or if no object is being tracked, return nullptr

Note
If it was detected that an object has been destroyed, this function will call ProxyReferenceCounter::Release() on the tracking object to release interest in further tracking.
Returns
nullptr if no object is being tracked or exists, or a valid pointer
See also
WeakPointer::operator->() const or WeakPointer::GetPtr() const

◆ GetPtr()

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

Get the current pointer.


Return an untracked copy of the pointer. The pointer can be nullptr if the object being track was destroyed.

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

◆ operator SmartPointer< T >()

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

Award shared ownership of an object.


Obtain the pointer to the object or nullptr if the object was destroyed and create a SmartPointer with a reference to the object. If the object exists, the SmartPointer will call AddRef() on it or the SmartPointer will contain a nullptr

Returns
A SmartPointer for the shared instance of a T class (Which may be nullptr )
See also
WeakPointer::WeakPointer(const SmartPointer &)

◆ operator!=() [1/5]

template<class T >
uint_t Burger::WeakPointer< 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
WeakPointer::operator==(const SmartPointer &) const or WeakPointer::operator!=(const T*) const

◆ operator!=() [2/5]

template<class T >
uint_t Burger::WeakPointer< T >::operator!= ( const SmartPointer< T > & rData)
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
WeakPointer::operator==(const SmartPointer &) or WeakPointer::operator!=(const T*)

◆ operator!=() [3/5]

template<class T >
uint_t Burger::WeakPointer< 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
WeakPointer::operator==(const T*) const or WeakPointer::operator!=(const WeakPointer&) const

◆ operator!=() [4/5]

template<class T >
uint_t Burger::WeakPointer< T >::operator!= ( const T * pData)
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
WeakPointer::operator==(const T*) or WeakPointer::operator!=(const WeakPointer&) const

◆ operator!=() [5/5]

template<class T >
uint_t Burger::WeakPointer< T >::operator!= ( const WeakPointer< 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 WeakPointer
Returns
TRUE if not equal, FALSE if equal
See also
WeakPointer::operator==(const WeakPointer &) const or WeakPointer::operator!=(const T*) const

◆ operator->()

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

Get the current pointer.


Return an untracked copy of the pointer. The pointer can be nullptr if the object being track was destroyed.

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

◆ operator=() [1/2]

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

Track a new object.


Obtain the pointer to the object's ProxyReferenceCounter and call ProxyReferenceCounter::AddRef() on it. Store the pointer inside the class for tracking. If there was an object previously being tracked, call ProxyReferenceCounter::Release() on it.

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

◆ operator=() [2/2]

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

Track a new object.


Obtain the pointer to the object's ProxyReferenceCounter and call ProxyReferenceCounter::AddRef() on it. Store the pointer inside the class for tracking. If there was an object previously being tracked, call ProxyReferenceCounter::Release() on it.

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

◆ operator==() [1/5]

template<class T >
uint_t Burger::WeakPointer< 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
WeakPointer::operator!=(const SmartPointer &) const or WeakPointer::operator==(const T*) const

◆ operator==() [2/5]

template<class T >
uint_t Burger::WeakPointer< T >::operator== ( const SmartPointer< T > & rData)
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
WeakPointer::operator!=(const SmartPointer &) or WeakPointer::operator==(const T*)

◆ operator==() [3/5]

template<class T >
uint_t Burger::WeakPointer< 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
WeakPointer::operator!=(const T*) const or WeakPointer::operator==(const WeakPointer &) const

◆ operator==() [4/5]

template<class T >
uint_t Burger::WeakPointer< T >::operator== ( const T * pData)
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
WeakPointer::operator!=(const T*) or WeakPointer::operator==(const WeakPointer &) const

◆ operator==() [5/5]

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

Test for equality.


Compare the pointers for equality and if equal, return TRUE

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

Member Data Documentation

◆ m_pData

template<class T >
T* Burger::WeakPointer< T >::m_pData
mutableprivate

Pointer to the object being tracked.

◆ m_pProxy

template<class T >
SmartPointer<ProxyReferenceCounter> Burger::WeakPointer< T >::m_pProxy
mutableprivate

Pointer to the object the tracked object will notify if it's deleted.