carb::extras::HandleRef
Defined in carb/extras/HandleDatabase.h
-
template<class Mapped, class Handle, class Allocator = std::allocator<Mapped>>
struct HandleRef 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 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
-
HandleRef() = default
Default constructor.
Produces an empty HandleRef.
-
inline HandleRef(Database &database, Handle handle)
Attempts to atomically reference a Handle from the given
database
.- Parameters
database – The HandleDatabase containing
handle
.handle – The handle previously returned from HandleDatabase::createHandle(). Providing an invalid or previously-valid handle results in an empty HandleRef.
-
inline ~HandleRef()
Destructor.
If
*this
is non-empty, releases the associated Handle with the associated HandleDatabase.
-
inline HandleRef(HandleRef &&other)
Move-constructor.
Post-condition:
other
is an empty HandleRef.- Parameters
other – The other HandleRef to move a reference from.
-
inline HandleRef &operator=(HandleRef &&other)
Move-assign operator.
Swaps state with
other
.- Parameters
other – The other HandleRef to move a reference from.
-
inline HandleRef clone() const
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 Mapped *operator->()
Dereferences and returns a pointer to the mapped type.
Warning
Undefined behavior if
*this
is empty.- Returns
A pointer to the mapped type.
-
inline const Mapped *operator->() const
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 Mapped &operator*()
Dereferences and returns a reference to the mapped type.
Warning
Undefined behavior if
*this
is empty.- Returns
A reference to the mapped type.
-
inline const Mapped &operator*() const
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 Mapped *get()
Returns a pointer to the mapped type, or
nullptr
if empty.- Returns
A pointer to the mapped type or
nullptr
if empty.
-
inline const Mapped *get() const
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 Handle handle() const
Returns the Handle referenced by
*this
.- Returns
The Handle referenced by
*this
.
-
inline explicit operator bool() const
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.
-
using Database = HandleDatabase<Mapped, Handle, Allocator>