ADTF  3.14.3
weak_object_ptr< T >

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

Public Member Functions

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

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 26 of file weak_object_ptr.h.

Constructor & Destructor Documentation

◆ ~weak_object_ptr()

~weak_object_ptr ( )
inline

Destructs the weak_object_ptr.

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

Definition at line 67 of file weak_object_ptr.h.

◆ weak_object_ptr() [1/3]

weak_object_ptr ( const weak_object_ptr< T > &  i_oOther)
inline

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 86 of file weak_object_ptr.h.

◆ weak_object_ptr() [2/3]

weak_object_ptr ( weak_object_ptr< T > &&  oOther)
inline

Move constructor.

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

Definition at line 109 of file weak_object_ptr.h.

References weak_object_ptr< T >::Swap().

◆ weak_object_ptr() [3/3]

weak_object_ptr ( const iobject_ptr< U > &  i_pOther)
inline

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 123 of file weak_object_ptr.h.

Member Function Documentation

◆ Lock()

object_ptr<T> Lock ( ) const
inline

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 204 of file weak_object_ptr.h.

◆ operator=() [1/2]

weak_object_ptr& operator= ( const iobject_ptr< U > &  i_pOther)
inline

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 138 of file weak_object_ptr.h.

References weak_object_ptr< T >::weak_object_ptr(), iobject_ptr_base< T >::Get(), and iobject_ptr_base< T >::GetObjPtrRef().

◆ operator=() [2/2]

weak_object_ptr& operator= ( weak_object_ptr< T >  oOther)
inline

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 99 of file weak_object_ptr.h.

References weak_object_ptr< T >::Swap().

◆ Reset() [1/3]

void Reset ( )
inline

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 179 of file weak_object_ptr.h.

References weak_object_ptr< T >::weak_object_ptr().

◆ Reset() [2/3]

tResult Reset ( const iobject_ptr< T > &  i_oOther)
inline

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 168 of file weak_object_ptr.h.

◆ Reset() [3/3]

tResult Reset ( const iobject_ptr< U > &  i_oOther)
inline

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 155 of file weak_object_ptr.h.

References iobject_ptr_base< T >::Get().

◆ Swap()

void Swap ( weak_object_ptr< T > &  o_oOther)
inline

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 189 of file weak_object_ptr.h.

References a_util::memory::swap().

Referenced by weak_object_ptr< T >::weak_object_ptr(), and weak_object_ptr< T >::operator=().


Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Thu Jun 9 2022 by doxygen 1.9.1)