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

enum class InitPolicy#

Policy directing how the smart pointer is initialized from from raw pointer.

Values:

enumerator eBorrow#

Increases reference count.

enumerator eSteal#

Assign the pointer without increasing the reference count.

Public Functions

inline ObjectPtr()#

Default Constructor.

inline ObjectPtr(std::nullptr_t)#

Nullptr 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 T &operator*() const#

Dereference operator.

Returns:

A reference to the pointed-at object.

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

inline void swap(ObjectPtr &other)#

Swaps with another smart pointer.

Parameters:

other – The smart pointer to swap with.