![]() |
|
Stores a pointer to a ValueType
which uses TfDelegatedCountIncrement
and TfDelegatedCountDecrement
to bookkeep.
More...
#include <delegatedCountPtr.h>
Public Types | |
using | RawPtrType = std::add_pointer_t< ValueType > |
using | ReferenceType = std::add_lvalue_reference_t< ValueType > |
using | element_type = ValueType |
using | IncrementIsNoExcept = std::integral_constant< bool, noexcept(TfDelegatedCountIncrement(std::declval< RawPtrType >()))> |
using | DecrementIsNoExcept = std::integral_constant< bool, noexcept(TfDelegatedCountDecrement(std::declval< RawPtrType >()))> |
using | IncrementAndDecrementAreNoExcept = std::integral_constant< bool, IncrementIsNoExcept() &&DecrementIsNoExcept()> |
using | DereferenceIsNoExcept = std::integral_constant< bool, noexcept(*std::declval< RawPtrType >())> |
Public Member Functions | |
TfDelegatedCountPtr () noexcept=default | |
Create a pointer storing nullptr | |
TfDelegatedCountPtr (TfDelegatedCountDoNotIncrementTagType, RawPtrType rawPointer) noexcept | |
Create a new pointer storing rawPointer without calling TfDelegatedCountIncrement . | |
TfDelegatedCountPtr (TfDelegatedCountIncrementTagType, RawPtrType rawPointer) noexcept(IncrementIsNoExcept()) | |
Create a new pointer storing rawPointer and call TfDelegatedCountIncrement on it if it is not nullptr . | |
TfDelegatedCountPtr (const TfDelegatedCountPtr &ptr) noexcept(IncrementIsNoExcept()) | |
Copy construct from ptr , calling TfDelegatedCountIncrement on the held pointer if it is not nullptr . | |
template<typename OtherType > | |
TfDelegatedCountPtr (const TfDelegatedCountPtr< OtherType > &ptr, std::enable_if_t< _IsPtrConvertible< OtherType >::value, int >=0) noexcept(IncrementIsNoExcept()) | |
Copy construct from ptr if it is convertible to this class's RawPtrType . | |
TfDelegatedCountPtr (TfDelegatedCountPtr &&ptr) noexcept | |
Construct by moving from ptr . | |
TfDelegatedCountPtr & | operator= (const TfDelegatedCountPtr &ptr) noexcept(IncrementAndDecrementAreNoExcept()) |
Assign by copying from ptr . | |
template<typename OtherType > | |
TfDelegatedCountPtr & | operator= (const TfDelegatedCountPtr< OtherType > &ptr) noexcept(IncrementAndDecrementAreNoExcept()) |
Assign by copying from ptr if it is convertible to this class's RawPtrType . | |
TfDelegatedCountPtr & | operator= (TfDelegatedCountPtr &&ptr) noexcept(DecrementIsNoExcept()) |
Assign by moving from ptr . | |
TfDelegatedCountPtr & | operator= (std::nullptr_t) noexcept(DecrementIsNoExcept()) |
Reset this pointer to its default state (i.e. nullptr ) | |
~TfDelegatedCountPtr () noexcept(DecrementIsNoExcept::value) | |
Call TfDelegatedCountDecrement on the held pointer if it is not nullptr`. | |
ReferenceType | operator* () const noexcept(DereferenceIsNoExcept()) |
Dereference the underlying pointer. | |
RawPtrType | operator-> () const noexcept |
Arrow operator dispatch for the underlying pointer. | |
operator bool () const noexcept | |
Return true if the underlying pointer is non-null, false otherwise. | |
template<typename OtherType > | |
bool | operator== (const TfDelegatedCountPtr< OtherType > &other) const noexcept |
Return true if the underlying pointers are equivalent. | |
template<typename OtherType > | |
bool | operator!= (const TfDelegatedCountPtr< OtherType > &other) const noexcept |
Returns false if the underlying pointers are equivalent. | |
template<typename OtherType > | |
bool | operator< (const TfDelegatedCountPtr< OtherType > &other) const noexcept |
Orders based on the underlying pointer. | |
RawPtrType | get () const noexcept |
Return the underlying pointer. | |
void | reset () noexcept(DecrementIsNoExcept()) |
Reset the pointer to its default state (nullptr ), calling TfDelegatedCountDecrement if the held pointer is not null. | |
void | swap (TfDelegatedCountPtr &other) noexcept |
Swap this object's held pointer with other's. | |
Stores a pointer to a ValueType
which uses TfDelegatedCountIncrement
and TfDelegatedCountDecrement
to bookkeep.
This class is most useful to adapt existing types that have their own bespoke reference counting logic to a common C++-style "smart pointer" interface.
The TfDelegatedCountPtr
calls TfDelegatedCountIncrement
and TfDelegatedCountDecrement
as needed in construction, assignment, and destruction operations. These functions are expected to be provided by client code to do the specific resource management related to the pointed-to object. These functions must have the following signatures:
For example if MyObject
has a reference count member variable, the overload TfDelegatedCountIncrement(MyObject *obj)
could simply increment that count. The TfDelegatedCountDecrement(MyObject *obj)
might decrement the count and check to see if it has gone to zero. If so, it can clean up resources related to the object such as deleting it or freeing memory.
These increment and decrement functions are never passed null pointers.
A TfDelegatedCountPtr
can be created by construction with a raw pointer, or by TfMakeDelegatedCountPtr
to create and manage an object on the heap.
Definition at line 63 of file delegatedCountPtr.h.
using DecrementIsNoExcept = std::integral_constant< bool, noexcept(TfDelegatedCountDecrement(std::declval<RawPtrType>()))> |
Definition at line 82 of file delegatedCountPtr.h.
using DereferenceIsNoExcept = std::integral_constant<bool, noexcept(*std::declval<RawPtrType>())> |
Definition at line 89 of file delegatedCountPtr.h.
using element_type = ValueType |
Definition at line 67 of file delegatedCountPtr.h.
using IncrementAndDecrementAreNoExcept = std::integral_constant< bool, IncrementIsNoExcept() && DecrementIsNoExcept()> |
Definition at line 86 of file delegatedCountPtr.h.
using IncrementIsNoExcept = std::integral_constant< bool, noexcept(TfDelegatedCountIncrement(std::declval<RawPtrType>()))> |
Definition at line 78 of file delegatedCountPtr.h.
using RawPtrType = std::add_pointer_t<ValueType> |
Definition at line 65 of file delegatedCountPtr.h.
using ReferenceType = std::add_lvalue_reference_t<ValueType> |
Definition at line 66 of file delegatedCountPtr.h.
|
defaultnoexcept |
Create a pointer storing nullptr
|
inlinenoexcept |
Create a new pointer storing rawPointer
without calling TfDelegatedCountIncrement
.
Definition at line 104 of file delegatedCountPtr.h.
|
inlinenoexcept |
Create a new pointer storing rawPointer
and call TfDelegatedCountIncrement
on it if it is not nullptr
.
Definition at line 112 of file delegatedCountPtr.h.
|
inlinenoexcept |
Copy construct from ptr
, calling TfDelegatedCountIncrement
on the held pointer if it is not nullptr
.
Definition at line 121 of file delegatedCountPtr.h.
|
inlineexplicitnoexcept |
Copy construct from ptr
if it is convertible to this class's RawPtrType
.
Call TfDelegatedCountIncrement
on the held pointer if it is not nullptr
.
Definition at line 131 of file delegatedCountPtr.h.
|
inlinenoexcept |
Construct by moving from ptr
.
ptr
is left in its default state (i.e. nullptr
).
Definition at line 142 of file delegatedCountPtr.h.
|
inlinenoexcept |
Call TfDelegatedCountDecrement
on the held pointer if it is not nullptr`.
A bug occurs in VS2017 where calling DecrementIsNoExcept() may return void. The bug is possibly related to an issue with using noexcept expressions in destructors.
Definition at line 191 of file delegatedCountPtr.h.
|
inlinenoexcept |
Return the underlying pointer.
Definition at line 230 of file delegatedCountPtr.h.
|
inlineexplicitnoexcept |
Return true if the underlying pointer is non-null, false otherwise.
Definition at line 206 of file delegatedCountPtr.h.
|
inlinenoexcept |
Returns false if the underlying pointers are equivalent.
Definition at line 217 of file delegatedCountPtr.h.
|
inlinenoexcept |
Dereference the underlying pointer.
Definition at line 196 of file delegatedCountPtr.h.
|
inlinenoexcept |
Arrow operator dispatch for the underlying pointer.
Definition at line 201 of file delegatedCountPtr.h.
|
inlinenoexcept |
Orders based on the underlying pointer.
Definition at line 224 of file delegatedCountPtr.h.
|
inlinenoexcept |
Assign by copying from ptr
.
Call TfDelegatedCountIncrement
on the held pointer if it is not nullptr
.
Definition at line 151 of file delegatedCountPtr.h.
|
inlinenoexcept |
Assign by copying from ptr
if it is convertible to this class's RawPtrType
.
Call TfDelegatedCountIncrement
on the held pointer if it is not nullptr
.
Definition at line 161 of file delegatedCountPtr.h.
|
inlinenoexcept |
Reset this pointer to its default state (i.e. nullptr
)
Definition at line 181 of file delegatedCountPtr.h.
|
inlinenoexcept |
Assign by moving from ptr
.
ptr
is left in its default state (i.e. nullptr
).
Definition at line 172 of file delegatedCountPtr.h.
|
inlinenoexcept |
Return true if the underlying pointers are equivalent.
Definition at line 210 of file delegatedCountPtr.h.
|
inlinenoexcept |
Reset the pointer to its default state (nullptr
), calling TfDelegatedCountDecrement
if the held pointer is not null.
Definition at line 234 of file delegatedCountPtr.h.
|
inlinenoexcept |
Swap this object's held pointer with other's.
Definition at line 240 of file delegatedCountPtr.h.