Represents a handle that was created by an external source. More...
#include <kanzi/core/util/handle.hpp>
Public Types | |
| using | HandleType |
| Alias for this handle type. | |
| using | NativeHandleType |
| Alias for the underlying native handle type. | |
Public Member Functions | |
| KZ_NO_DISCARD optional< T > | createOptional () const noexcept |
| Creates a kanzi::optional copy of the native handle. | |
| KZ_NO_DISCARD const T | get () const noexcept |
| Provides access to stored handle. | |
| KZ_NO_DISCARD T | get () noexcept |
| Provides access to stored handle. | |
| KZ_NO_DISCARD const T | getNativeHandle () const noexcept |
| Provides access to stored handle. | |
| KZ_NO_DISCARD T | getNativeHandle () noexcept |
| Provides access to stored handle. | |
| KZ_NO_DISCARD bool | hasValue () const noexcept |
| Checks if a handle is stored. | |
| KZ_NO_DISCARD | operator bool () const noexcept |
| Conversion operator to bool. | |
| KZ_NO_DISCARD T && | operator* () &&noexcept |
| Provides access to stored handle via rvalue reference. | |
| KZ_NO_DISCARD T & | operator* () &noexcept |
| Provides access to stored handle via reference. | |
| KZ_NO_DISCARD const T && | operator* () const &&noexcept |
| Provides access to stored handle via const rvalue reference. | |
| KZ_NO_DISCARD const T & | operator* () const &noexcept |
| Provides access to stored handle via const reference. | |
| OptionalHandle & | operator= (const OptionalHandle &other)=delete |
| Copy assignment operator. | |
| OptionalHandle & | operator= (const T &value) |
| Copy assignment operator. | |
| OptionalHandle & | operator= (OptionalHandle &&other) noexcept |
| Move assignment operator. | |
| OptionalHandle & | operator= (T &&value) noexcept |
| Move assignment operator. | |
| OptionalHandle () noexcept | |
| Constructor. | |
| OptionalHandle (const OptionalHandle &other)=delete | |
| Copy constructor. | |
| OptionalHandle (const T &nativeHandle) noexcept | |
| Constructor. | |
| OptionalHandle (OptionalHandle &&other) noexcept | |
| Move constructor. | |
| T | release () noexcept |
| Releases ownership of a native handle without destroying the resource. | |
| void | reset () noexcept |
| Replaces stored handle with sentinel value. | |
| template<typename U , typename = enable_if_t<is_same_v<T, decay_t<U>>>> | |
| void | reset (U &&newHandle) noexcept |
| Stores a new handle inside. | |
| void | swap (OptionalHandle &other) |
| Swap function. | |
| KZ_NO_DISCARD optional< T > | toOptional () &&noexcept |
| Converts OptionalHandle to kanzi::optional. | |
| ~OptionalHandle () | |
| Destructor. | |
Static Public Member Functions | |
| static constexpr auto | getDeleter () noexcept |
| Gets deleter function. | |
| static constexpr T | getSentinel () noexcept |
| Gets sentinel value that can be used to represent invalid handle. | |
Protected Attributes | |
| FlatOptional< T, sentinel > | m_handle |
| Native handle that is managed by this class. | |
Represents a handle that was created by an external source.
Can hold an invalid handle represented by sentinel value.
The purpose of this class is to hold the external handle and free the associated resources after this class has been destroyed.
For handles that cannot have a sentinel value (every value of T is a valid handle), use Handle instead.
Derive from this class using protected inheritance and use OptionalHandleWrapper to create a wrapper around it.
Example code
| T | Handle type. |
| sentinel | Sentinel value that represents invalid handle. |
| deleter | Deleter function, used for freeing resources that handle represents. |
Alias for the underlying native handle type.
Alias for this handle type.
|
inlineexplicitnoexcept |
Constructor.
|
inlineexplicitnoexcept |
Constructor.
| nativeHandle | Native handle to store. |
|
inline |
Destructor.
|
delete |
Copy constructor.
|
inlinenoexcept |
Move constructor.
|
delete |
Copy assignment operator.
|
inlinenoexcept |
Move assignment operator.
|
inline |
|
inlinenoexcept |
|
inline |
Swap function.
| other | Second object to swap with. |
|
inlinenoexcept |
Provides access to stored handle via reference.
|
inlinenoexcept |
Provides access to stored handle via const reference.
|
inlinenoexcept |
Provides access to stored handle via rvalue reference.
|
inlinenoexcept |
Provides access to stored handle via const rvalue reference.
|
inlinenoexcept |
Checks if a handle is stored.
|
inlineexplicitnoexcept |
Conversion operator to bool.
|
inlinenoexcept |
Provides access to stored handle.
|
inlinenoexcept |
Provides access to stored handle.
|
inlinenoexcept |
Provides access to stored handle.
|
inlinenoexcept |
Provides access to stored handle.
Replaces stored handle with sentinel value.
|
inlinenoexcept |
Stores a new handle inside.
Takes an ownership of the resource.
| U | Deduced type for universal reference. |
| newHandle | New handle to store. |
Releases ownership of a native handle without destroying the resource.
|
inlinestaticconstexprnoexcept |
Gets sentinel value that can be used to represent invalid handle.
|
inlinestaticconstexprnoexcept |
Gets deleter function.
|
inlinenoexcept |
Converts OptionalHandle to kanzi::optional.
Use by moving the value first:
As the value is being moved, the responsibilities of deleting the handle are now upon the caller.
| nullopt | OptionalHandle represented an empty value. |
|
inlinenoexcept |
Creates a kanzi::optional copy of the native handle.
| nullopt | OptionalHandle represented an empty value. |
|
protected |
Native handle that is managed by this class.