ADTF
Loading...
Searching...
No Matches
adtf::ucom::ant::weak_object_ptr< T > Class Template Reference

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).
 

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.

Constructor & Destructor Documentation

◆ ~weak_object_ptr()

template<typename T>
adtf::ucom::ant::weak_object_ptr< 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.

◆ weak_object_ptr() [1/3]

template<typename T>
adtf::ucom::ant::weak_object_ptr< 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.

◆ weak_object_ptr() [2/3]

template<typename T>
adtf::ucom::ant::weak_object_ptr< 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.

◆ weak_object_ptr() [3/3]

template<typename T>
template<typename U>
adtf::ucom::ant::weak_object_ptr< T >::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.

Member Function Documentation

◆ Lock()

template<typename T>
object_ptr< T > adtf::ucom::ant::weak_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.

◆ operator=() [1/2]

template<typename T>
template<typename U>
weak_object_ptr & adtf::ucom::ant::weak_object_ptr< T >::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

◆ operator=() [2/2]

template<typename T>
weak_object_ptr & adtf::ucom::ant::weak_object_ptr< T >::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.

◆ Reset() [1/3]

template<typename T>
void adtf::ucom::ant::weak_object_ptr< T >::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

◆ Reset() [2/3]

template<typename T>
tResult adtf::ucom::ant::weak_object_ptr< T >::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

◆ Reset() [3/3]

template<typename T>
template<typename U>
tResult adtf::ucom::ant::weak_object_ptr< T >::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

◆ Swap()

template<typename T>
void adtf::ucom::ant::weak_object_ptr< T >::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

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