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_ptr & | operator= (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_ptr & | operator= (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. | |
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.
T | Type of the shared resource the weak reference counting is performed on. |
Definition at line 33 of file weak_object_ptr.h.
|
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().
|
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().
|
inlineconstexprnoexcept |
Construct the weak_ptr
from a nullptr
- for empty construction.
Definition at line 83 of file weak_object_ptr.h.
|
inlinenoexcept |
Copy constructor.
Does not have any effect on the shared count.
[in] | i_oOther | weak_ptr to copy from. |
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().
|
inlinenoexcept |
Move constructor.
[in] | oOther | weak_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().
|
inlinenoexcept |
Copy construction from an iobject_ptr
.
Does not have any effect on the shared count.
U | Type of managed resource - must be ucom_cast castable to object of type T |
[in] | i_pOther | Shared object pointer *this gets created from. |
Definition at line 132 of file weak_object_ptr.h.
|
inlinenoexcept |
Create an object_ptr<>
from *this weak pointer (thread safe).
Does not have any effect on the weak count.
object_ptr<>
referencing the shared resource. Empty object_ptr<>
otherwise. Definition at line 218 of file weak_object_ptr.h.
|
inlinenoexcept |
Assignment from an iobject_ptr
.
Does not have any effect on the shared count.
U | Type of managed resource - must be ucom_cast castable to object of type T |
[in] | i_pOther | Shared object pointer *this gets created from. |
Definition at line 147 of file weak_object_ptr.h.
References weak_object_ptr().
|
inlinenoexcept |
Assignment operator.
Does not have any effect on the shared count.
[in] | oOther | Other weak_object_ptr<> to create this from. Call-by-value is intentional to make use of the copy-swap-idiom and the copy elision. |
nullptr
, the weak count of the reference counting object gets increased by one. Definition at line 107 of file weak_object_ptr.h.
References weak_object_ptr(), and Swap().
|
inlinenoexcept |
Reset to an empty weak_ptr
object.
Definition at line 188 of file weak_object_ptr.h.
References m_pObject, and m_pRefer.
Referenced by ~weak_object_ptr().
|
inlinenoexcept |
Reset this weak_object_ptr<> with the content of another iobject_ptr<>
[in] | i_oOther | Contains the shared object to reset this type with |
i_oOther
manages a valid shared resource, the weak count gets increased by one for this resource ERR_NOERROR | Everything went fine |
Definition at line 177 of file weak_object_ptr.h.
|
inlinenoexcept |
Reset this weak_object_ptr<> with the content of another iobject_ptr<>
[in] | i_oOther | Contains the shared object to reset this type with |
i_oOther
manages a valid shared resource, the weak count gets increased by one for this resource ERR_NOERROR | Everything went fine |
ERR_NO_INTERFACE | Managed 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.
|
inlinenoexcept |
Swap content of *this with o_oOther
(only shallow copies are performed!)
[in,out] | o_oOther | Other object_ptr object whose content is swapped with *this. |
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=().
|
private |
The managed object.
Definition at line 224 of file weak_object_ptr.h.
Referenced by weak_object_ptr(), Reset(), Reset(), and Swap().
|
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().