Generic nullable RAII resource handle with exclusive ownership of a resource that is automatically destroyed on handle destruction.
More...
|
constexpr | UniqueHandle () noexcept=default |
| Construct a null handle without an associated resource.
|
|
constexpr | UniqueHandle (Handle handle) noexcept |
| Construct a handle that takes ownership of an existing resource handle.
|
|
| ~UniqueHandle () |
| Destroy the handle and its associated resource if it has one.
|
|
| UniqueHandle (const UniqueHandle &)=delete |
| Copying a resource handle is disallowed to enforce exclusive ownership.
|
|
constexpr | UniqueHandle (UniqueHandle &&other) noexcept |
| Move constructor.
|
|
UniqueHandle & | operator= (const UniqueHandle &)=delete |
| Copying a resource handle is disallowed to enforce exclusive ownership.
|
|
constexpr UniqueHandle & | operator= (UniqueHandle &&other) noexcept |
| Move assignment.
|
|
constexpr | operator bool () const noexcept |
| Check if this handle has an associated resource, i.e.
|
|
constexpr bool | operator== (const UniqueHandle &other) const noexcept |
| Compare this resource handle against another for equality of the underlying handle value.
|
|
constexpr void | reset (Handle newHandle=NullHandle) noexcept |
| Destroy the resource associated with this handle, if any, and take ownership of a new resource handle, which may be null.
|
|
constexpr Handle | release () noexcept |
| Relinquish ownership of the associated resource.
|
|
constexpr Handle | get () const noexcept |
| Get the value of the underlying resource handle.
|
|
template<typename Handle, typename Deleter, Handle NullHandle = Handle{}>
class donut::UniqueHandle< Handle, Deleter, NullHandle >
Generic nullable RAII resource handle with exclusive ownership of a resource that is automatically destroyed on handle destruction.
- Template Parameters
-
Handle | the underlying handle type. Usually an integer or pointer type. |
Deleter | stateless functor type that destroys the associated resource when default-constructed and called with a non-null handle. Passing a handle equal to NullHandle must be a no-op. |
NullHandle | constant value representing a null handle that does not have an associated resource. Usually 0 or nullptr. |
template<typename Handle , typename Deleter , Handle NullHandle = Handle{}>
Relinquish ownership of the associated resource.
This handle will be reset to null, without destroying the associated resource.
- Returns
- the handle to the associated resource that was released, or NullHandle if the handle did not have an associated resource.
- Warning
- After calling this function, the associated resource will no longer be destroyed automatically along with the handle. It instead becomes the responsibility of the caller to ensure that the resource is properly cleaned up. If the intent is to reset the handle to null while destroying the associated resource in the process, use reset() instead.
- See also
- reset()
-
get()