ADTF  3.18.2
enable_object_ptr_from_this< T >

Safely retrieve a valid object_ptr<> instance to *this when all we have is *this. More...

Public Member Functions

object_ptr< T > object_ptr_from_this ()
 Retrieve an object_ptr with *this being the shared resource. More...
 
object_ptr< const T > object_ptr_from_this () const
 Retrieve an object_ptr with *this being the shared resource - const correct. More...
 

Protected Member Functions

 enable_object_ptr_from_this ()=default
 Default constructor.
 
 ~enable_object_ptr_from_this ()=default
 Default destructor.
 
 enable_object_ptr_from_this (const enable_object_ptr_from_this &)=default
 Default copy construction.
 
enable_object_ptr_from_thisoperator= (const enable_object_ptr_from_this &)=default
 Default copy assignment.
 

Private Member Functions

void Assign (const object_ptr< T > &i_pObject)
 Assign an existing shared resource in form of the managing object ptr. More...
 

Private Attributes

weak_object_ptr< T > m_pWeak
 weak pointer managing the object_ptr to enable
 

Detailed Description

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

Safely retrieve a valid object_ptr<> instance to *this when all we have is *this.

This may be used in complete analogy to std::enable_shared_from_this, so please consult a documentation for that for further questions on the usage of this class.

Note
To make sure the only way to get a valid shared resource wrapped inside an object_ptr is from an shared resource managed by an already existing object_ptr, friend function make_object_ptr is the only possible way to assign a valid object_ptr. In other words, retrieving an object_ptr of *this from an object not managed by an object_ptr results in an empty object_ptr<T>.
Template Parameters
TType of the shared resource that is managed by the object_ptr<> to retrieve.

Definition at line 29 of file object_ptr_utilities.h.

Member Function Documentation

◆ Assign()

void Assign ( const object_ptr< T > &  i_pObject)
inlineprivate

Assign an existing shared resource in form of the managing object ptr.

Parameters
[in]i_pObjectThe object ptr *this gets assigned to.
Returns
Nothing

Definition at line 81 of file object_ptr_utilities.h.

References enable_object_ptr_from_this< T >::m_pWeak.

Referenced by adtf::ucom::ant::make_object_ptr().

◆ object_ptr_from_this() [1/2]

object_ptr<T> object_ptr_from_this ( )
inline

Retrieve an object_ptr with *this being the shared resource.

Returns
object_ptr with *this as the shared resource. If *this is not managed by a valid object_ptr, the returned object_ptr is empty.

Definition at line 47 of file object_ptr_utilities.h.

References enable_object_ptr_from_this< T >::m_pWeak.

Referenced by cGraphObject::CreateInterfaceServer().

◆ object_ptr_from_this() [2/2]

object_ptr<const T> object_ptr_from_this ( ) const
inline

Retrieve an object_ptr with *this being the shared resource - const correct.

Returns
object_ptr with *this as the shared resource. If *this is not managed by a valid object_ptr, the returned object_ptr is empty.

Definition at line 57 of file object_ptr_utilities.h.

References enable_object_ptr_from_this< T >::m_pWeak.