carb::ObjectPtr¶
Defined in carb/IObject.h
-
template<class
T
>
classcarb
::
ObjectPtr
¶ Smart pointer type for ref counting
IObject
.It automatically controls reference count for the underlying
IObject
pointer.Public Types
Public Functions
-
inline explicit
ObjectPtr
(T *object = nullptr, InitPolicy policy = InitPolicy::eBorrow)¶ Constructor.
- Parameters
object – The raw pointer to an object.
policy – Directive on whether the reference count should be increased or not.
-
inline
ObjectPtr
(const ObjectPtr<T> &other)¶ Copy constructor.
Always increases the reference count.
- Parameters
other – The smart pointer from which to copy a reference.
-
template<class
U
>
inlineObjectPtr
(const ObjectPtr<U> &other)¶ Copy constructor.
Always increases the reference count.
- Parameters
other – The smart pointer from which to copy a reference.
-
inline
ObjectPtr
(ObjectPtr<T> &&other)¶ Move constructor.
Steals the reference count from
other
and leaves it empty.- Parameters
other – The smart pointer from which to steal a reference.
-
template<class
U
>
inlineObjectPtr
(ObjectPtr<U> &&other)¶ Move constructor.
Steals the reference count from
other
and leaves it empty.- Parameters
other – The smart pointer from which to steal a reference.
-
inline
~ObjectPtr
()¶ Destructor.
-
inline T *
get
() const¶ Converts the smart pointer to a raw pointer.
- Returns
The raw pointer referenced by the smart pointer. May be
nullptr
.
-
inline T *
operator->
() const¶ Pointer dereference operator.
- Returns
The raw pointer referenced by the smart pointer.
-
inline explicit
operator bool
() const¶ Boolean conversion operator.
- Returns
true
if the smart pointer is not empty;false
if the smart pointer is empty.
-
inline T *const *
getAddressOf
() const¶ Returns the address of the internal reference.
- Returns
The address of the internal reference.
-
inline T **
getAddressOf
()¶ Returns the address of the internal reference.
- Returns
The address of the internal reference.
-
inline T **
releaseAndGetAddressOf
()¶ Helper function to release any current reference and return the address of the internal reference pointer.
- Returns
The address of the internal reference.
-
inline T *
detach
()¶ Resets this smart pointer to
nullptr
and returns the previously reference object without releasing the held reference.- Returns
The previously referenced object.
-
inline void
attach
(T *other)¶ Releases the reference on any held object and instead steals the given object.
- Parameters
other – The object to steal a reference to.
-
inline ObjectPtr &
operator=
(decltype(nullptr))¶ Assignment to nullptr.
Releases any previously held reference.
- Returns
*this
-
inline ObjectPtr &
operator=
(T *other)¶ Releases any previously held reference and copies a reference to
other
.- Parameters
other – The object to reference.
- Returns
*this
-
template<typename
U
>
inline ObjectPtr &operator=
(U *other)¶ Assignment to nullptr.
Releases any previously held reference.
- Returns
*this
-
inline ObjectPtr &
operator=
(const ObjectPtr &other)¶ Assignment to nullptr.
Releases any previously held reference.
- Returns
*this
-
template<class
U
>
inline ObjectPtr &operator=
(const ObjectPtr<U> &other)¶ Assignment to nullptr.
Releases any previously held reference.
- Returns
*this
-
inline ObjectPtr &
operator=
(ObjectPtr &&other)¶ Releases any previously held reference and steals the reference from
other
.- Parameters
other – The reference to steal. Will be swapped with *this.
- Returns
*this
-
template<class
U
>
inline ObjectPtr &operator=
(ObjectPtr<U> &&other)¶ Releases any previously held reference and steals the reference from
other
.- Parameters
other – The reference to steal. Will be swapped with *this.
- Returns
*this
-
template<class
U
>
inline booloperator==
(const ObjectPtr<U> &other) const¶ Compares equality of this object and another one of the same type.
- Parameters
other – [in] The other object to compare this one to.
- Returns
true
if the two objects identify the same underlying object. Returnsfalse
otherwise.
-
template<class
U
>
inline booloperator!=
(const ObjectPtr<U> &other) const¶ Compares inequality of this object and another one of the same type.
- Parameters
other – [in] The other object to compare this one to.
- Returns
true
if the two objects do not identify the same underlying object. Returnsfalse
otherwise.
-
inline explicit