ObjectPtr#
Fully qualified name: carb::ObjectPtr
Defined in carb/IObject.h
-
template<class T>
class ObjectPtr# Smart pointer type for ref counting
IObject
.It automatically controls reference count for the underlying
IObject
pointer.Public Types
Public Functions
-
inline ObjectPtr()#
Default Constructor.
-
inline explicit ObjectPtr(T *object)#
Constructor.
- Parameters:
object – The raw pointer to an object. If not
nullptr
, it will be “borrowed”; that is, the reference count will be increased as long as*this
contains it.
-
inline ObjectPtr(T *object, InitPolicy policy)#
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>
inline ObjectPtr(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>
inline ObjectPtr(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=(
)# 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
-
inline ObjectPtr()#