HandleRef#

Fully qualified name: carb::extras::HandleRef

Defined in carb/extras/HandleDatabase.h

template<class Mapped, class Handle, class Allocator = std::allocator<Mapped>>
struct HandleRef : public carb::extras::ConstHandleRef<Mapped, Handle, std::allocator<Mapped>>#

A smart-reference class for a Handle associated with a HandleDatabase.

When HandleRef is destroyed, the associated handle is released with the HandleDatabase.

Public Types

using BaseType = ConstHandleRef<Mapped, Handle, Allocator>#

Base type used for this container.

using MappedType = Mapped#

An alias to Mapped; the mapped value type.

using ReferenceType = Mapped&#

An alias to Mapped&.

using PointerType = Mapped*#

An alias to Mapped*.

using HandleType = Handle#

An alias to Handle; the key type used to associate a mapped value type.

using AllocatorType = Allocator#

An alias to Allocator; the allocator used to allocate memory.

using Database = HandleDatabase<Mapped, Handle, Allocator>#

The type specification for the associated HandleDatabase.

using element_type = MappedType#

Deprecated: Use MappedType instead.

using handle_type = HandleType#

Deprecated: Use HandleType instead.

Public Functions

constexpr HandleRef() noexcept = default#

Default constructor.

Produces an empty HandleRef.

inline HandleRef(Database &database, Handle handle) noexcept#

Attempts to atomically reference a Handle from the given database.

Parameters:
inline HandleRef clone() const noexcept#

Explicitly adds a reference to any referenced handle and returns a HandleRef.

Returns:

A HandleRef holding its own reference for the contained handle. May be empty if *this is empty.

inline PointerType operator->() noexcept#

Dereferences and returns a pointer to the mapped type.

Warning

Undefined behavior if *this is empty.

Returns:

A pointer to the mapped type.

inline PointerType operator->() const noexcept#

Dereferences and returns a const pointer to the mapped type.

Warning

Undefined behavior if *this is empty.

Returns:

A const pointer to the mapped type.

inline ReferenceType operator*() noexcept#

Dereferences and returns a reference to the mapped type.

Warning

Undefined behavior if *this is empty.

Returns:

A reference to the mapped type.

inline ReferenceType operator*() const noexcept#

Dereferences and returns a const reference to the mapped type.

Warning

Undefined behavior if *this is empty.

Returns:

A const reference to the mapped type.

inline PointerType get() noexcept#

Returns a pointer to the mapped type, or nullptr if empty.

Returns:

A pointer to the mapped type or nullptr if empty.

inline PointerType get() const noexcept#

Returns a const pointer to the mapped type, or nullptr if empty.

Returns:

A const pointer to the mapped type or nullptr if empty.

inline void swap(HandleRef &rhs)#

Swaps state with another HandleRef.

inline Handle handle() const noexcept#

Returns the Handle referenced by *this.

Returns:

The Handle referenced by *this.

inline explicit operator bool() const noexcept#

Tests if *this contains a valid reference.

Returns:

true if *this maintains a valid reference; false if *this is empty.

inline void reset()#

Releases any associated reference and resets *this to empty.

inline Mapped *release() noexcept#

Releases the ownership of the managed object, if any.

The caller becomes responsible for ownership of the returned object and must release it from the handle database.

Returns:

The managed object or nullptr if there was no managed object.

inline void swap(ConstHandleRef &rhs)#

Swaps state with another HandleRef.

Protected Attributes

Database *m_database = {}#

Handle database this reference points into.

Handle m_handle = {}#

Handle that this reference currently represents.

Mapped *m_mapped = {}#

The mapped value for this reference.