ADTF
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
weak_object_ptr< T >

Implementation of a weak pointer for usage with iobject_ptr and object_ptr. More...

#include <weak_object_ptr.h>

Public Member Functions

constexpr weak_object_ptr () noexcept
 Default constructor for empty construction.
 
 ~weak_object_ptr () noexcept
 Destructs the weak_object_ptr.
 
constexpr weak_object_ptr (std::nullptr_t) noexcept
 Construct the weak_ptr from a nullptr - for empty construction.
 
 weak_object_ptr (const weak_object_ptr &i_oOther) noexcept
 Copy constructor.
 
weak_object_ptroperator= (weak_object_ptr oOther) noexcept
 Assignment operator.
 
 weak_object_ptr (weak_object_ptr &&oOther) noexcept
 Move constructor.
 
template<typename U>
 weak_object_ptr (const iobject_ptr< U > &i_pOther) noexcept
 Copy construction from an iobject_ptr.
 
template<typename U>
weak_object_ptroperator= (const iobject_ptr< U > &i_pOther) noexcept
 Assignment from an iobject_ptr.
 
template<typename U>
tResult Reset (const iobject_ptr< U > &i_oOther) noexcept
 Reset this weak_object_ptr<> with the content of another iobject_ptr<>
 
tResult Reset (const iobject_ptr< T > &i_oOther) noexcept
 Reset this weak_object_ptr<> with the content of another iobject_ptr<>
 
void Reset () noexcept
 Reset to an empty weak_ptr object.
 
void Swap (weak_object_ptr &o_oOther) noexcept
 Swap content of *this with o_oOther (only shallow copies are performed!)
 
object_ptr< T > Lock () const noexcept
 Create an object_ptr<> from *this weak pointer (thread safe).
 

Private Attributes

T * m_pObject
 The managed object.
 
detail::iobject_ptr_ref< size_type > * m_pRefer
 Refer to control the weak counting.
 

Detailed Description

template<typename T>
class adtf::ucom::ant::weak_object_ptr< T >

Implementation of a weak pointer for usage with iobject_ptr and object_ptr.

This weak_ptr<> implementation is almost exactly according to the standard. Some functionality required by the standard has been left out to focus on the main task - weak counting! For a detailed explanation of a weak pointer implementation, C++-11 reference websites may be consulted.

Template Parameters
TType of the shared resource the weak reference counting is performed on.

Definition at line 33 of file weak_object_ptr.h.

Constructor & Destructor Documentation

◆ weak_object_ptr() [1/5]

template<typename T>
weak_object_ptr ( )
inlineconstexprnoexcept

Default constructor for empty construction.

Definition at line 66 of file weak_object_ptr.h.

References m_pObject, and m_pRefer.

Referenced by weak_object_ptr(), weak_object_ptr(), operator=(), operator=(), and Swap().

◆ ~weak_object_ptr()

template<typename T>
~weak_object_ptr ( )
inlinenoexcept

Destructs the weak_object_ptr.

Does not have any effect on the shared resource. The weak_count is decreased by one.

Definition at line 75 of file weak_object_ptr.h.

References Reset().

◆ weak_object_ptr() [2/5]

template<typename T>
weak_object_ptr ( std::nullptr_t )
inlineconstexprnoexcept

Construct the weak_ptr from a nullptr - for empty construction.

Definition at line 83 of file weak_object_ptr.h.

◆ weak_object_ptr() [3/5]

template<typename T>
weak_object_ptr ( const weak_object_ptr< T > & i_oOther)
inlinenoexcept

Copy constructor.

Does not have any effect on the shared count.

Parameters
[in]i_oOtherweak_ptr to copy from.
Postcondition
If pointer to the shared object is not nullptr, the weak count of the reference counting object gets increased by one.

Definition at line 94 of file weak_object_ptr.h.

References weak_object_ptr().

◆ weak_object_ptr() [4/5]

template<typename T>
weak_object_ptr ( weak_object_ptr< T > && oOther)
inlinenoexcept

Move constructor.

Parameters
[in]oOtherweak_object_ptr object to create this from. Will be reset.

Definition at line 117 of file weak_object_ptr.h.

References weak_object_ptr(), and Swap().

◆ weak_object_ptr() [5/5]

template<typename T>
template<typename U>
weak_object_ptr ( const iobject_ptr< U > & i_pOther)
inlinenoexcept

Copy construction from an iobject_ptr.

Does not have any effect on the shared count.

Template Parameters
UType of managed resource - must be ucom_cast castable to object of type T
Parameters
[in]i_pOtherShared object pointer *this gets created from.
Postcondition
If the object pointer manages a valid shared resource, the weak count gets increased by one.

Definition at line 132 of file weak_object_ptr.h.

Member Function Documentation

◆ Lock()

template<typename T>
object_ptr< T > Lock ( ) const
inlinenoexcept

Create an object_ptr<> from *this weak pointer (thread safe).

Does not have any effect on the weak count.

Postcondition
If the shared count for the managed shared resource is greater than zero, the shared count gets increased by one.
Returns
If the shared resource still exists, an object_ptr<> referencing the shared resource. Empty object_ptr<> otherwise.

Definition at line 218 of file weak_object_ptr.h.

◆ operator=() [1/2]

template<typename T>
template<typename U>
weak_object_ptr & operator= ( const iobject_ptr< U > & i_pOther)
inlinenoexcept

Assignment from an iobject_ptr.

Does not have any effect on the shared count.

Template Parameters
UType of managed resource - must be ucom_cast castable to object of type T
Parameters
[in]i_pOtherShared object pointer *this gets created from.
Postcondition
If the object pointer manages a valid shared resource, the weak count gets increased by one.
Returns
Reference to *this

Definition at line 147 of file weak_object_ptr.h.

References weak_object_ptr().

◆ operator=() [2/2]

template<typename T>
weak_object_ptr & operator= ( weak_object_ptr< T > oOther)
inlinenoexcept

Assignment operator.

Does not have any effect on the shared count.

Parameters
[in]oOtherOther weak_object_ptr<> to create this from. Call-by-value is intentional to make use of the copy-swap-idiom and the copy elision.
Postcondition
If pointer to the shared object is not nullptr, the weak count of the reference counting object gets increased by one.
Returns
Reference to *this.

Definition at line 107 of file weak_object_ptr.h.

References weak_object_ptr(), and Swap().

◆ Reset() [1/3]

template<typename T>
void Reset ( )
inlinenoexcept

Reset to an empty weak_ptr object.

Postcondition
The weak count on any previously referenced shared resource gets decreased by one.
Returns
Nothing

Definition at line 188 of file weak_object_ptr.h.

References m_pObject, and m_pRefer.

Referenced by ~weak_object_ptr().

◆ Reset() [2/3]

template<typename T>
tResult Reset ( const iobject_ptr< T > & i_oOther)
inlinenoexcept

Reset this weak_object_ptr<> with the content of another iobject_ptr<>

Parameters
[in]i_oOtherContains the shared object to reset this type with
Postcondition
Weak count of previously held shared resource is decreased by one. If i_oOther manages a valid shared resource, the weak count gets increased by one for this resource
Return values
ERR_NOERROREverything went fine

Definition at line 177 of file weak_object_ptr.h.

◆ Reset() [3/3]

template<typename T>
template<typename U>
tResult Reset ( const iobject_ptr< U > & i_oOther)
inlinenoexcept

Reset this weak_object_ptr<> with the content of another iobject_ptr<>

Parameters
[in]i_oOtherContains the shared object to reset this type with
Postcondition
Weak count of previously held shared resource is decreased by one. If i_oOther manages a valid shared resource, the weak count gets increased by one for this resource
Return values
ERR_NOERROREverything went fine
ERR_NO_INTERFACEManaged resource owned by i_oOther does not expose interface type T. *this is reset to nullptr

Definition at line 164 of file weak_object_ptr.h.

References m_pObject.

◆ Swap()

template<typename T>
void Swap ( weak_object_ptr< T > & o_oOther)
inlinenoexcept

Swap content of *this with o_oOther (only shallow copies are performed!)

Parameters
[in,out]o_oOtherOther object_ptr object whose content is swapped with *this.
Returns
Nothing

Definition at line 203 of file weak_object_ptr.h.

References weak_object_ptr(), m_pObject, and m_pRefer.

Referenced by weak_object_ptr(), and operator=().

Member Data Documentation

◆ m_pObject

template<typename T>
T* m_pObject
private

The managed object.

Definition at line 224 of file weak_object_ptr.h.

Referenced by weak_object_ptr(), Reset(), Reset(), and Swap().

◆ m_pRefer

template<typename T>
detail::iobject_ptr_ref<size_type>* m_pRefer
private

Refer to control the weak counting.

Definition at line 225 of file weak_object_ptr.h.

Referenced by weak_object_ptr(), Reset(), and Swap().