Kanzi 4.0.0-beta2
kanzi::Handle< T, deleter > Class Template Reference

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 const NativeHandleType get () const noexcept
 Provides access to stored handle.
 
KZ_NO_DISCARD NativeHandleType get () noexcept
 Provides access to stored handle.
 
KZ_NO_DISCARD const NativeHandleType getNativeHandle () const noexcept
 Provides access to stored handle.
 
KZ_NO_DISCARD NativeHandleType getNativeHandle () noexcept
 Provides access to stored handle.
 
 Handle (const Handle &other)=delete
 Copy constructor.
 
 Handle (const NativeHandleType &value) noexcept
 Constructor.
 
 Handle (Handle &&other) noexcept=delete
 Move constructor.
 
Handleoperator= (const Handle &other)=delete
 Copy assignment operator.
 
Handleoperator= (const NativeHandleType &value)
 Copy assignment operator.
 
Handleoperator= (Handle &&other) noexcept=delete
 Move assignment operator.
 
Handleoperator= (NativeHandleType &&value) noexcept
 Move assignment operator.
 
template<typename U , typename = enable_if_t<is_convertible_v<decay_t<U>, NativeHandleType>>>
void reset (U &&newHandle) noexcept
 Stores a new handle inside.
 
void swap (Handle &other)
 Swap function.
 
 ~Handle ()
 Destructor.
 

Static Public Member Functions

static constexpr auto getDeleter () noexcept
 Gets deleter function.
 

Detailed Description

template<typename T, auto deleter>
class kanzi::Handle< T, deleter >

Represents a handle that was created by an external source.

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 can have a sentinel value to represent invalid handle, use OptionalHandle instead.

Template Parameters
THandle type.
deleterDeleter function, used for freeing resources that handle represents.
Since
Kanzi 4.0.0

Member Typedef Documentation

◆ NativeHandleType

template<typename T , auto deleter>
using kanzi::Handle< T, deleter >::NativeHandleType

Alias for the underlying native handle type.

◆ HandleType

template<typename T , auto deleter>
using kanzi::Handle< T, deleter >::HandleType

Alias for this handle type.

Constructor & Destructor Documentation

◆ Handle() [1/3]

template<typename T , auto deleter>
kanzi::Handle< T, deleter >::Handle ( const NativeHandleType & value)
inlineexplicitnoexcept

Constructor.

Parameters
valueHandle to store.

◆ ~Handle()

template<typename T , auto deleter>
kanzi::Handle< T, deleter >::~Handle ( )
inline

Destructor.

◆ Handle() [2/3]

template<typename T , auto deleter>
kanzi::Handle< T, deleter >::Handle ( const Handle< T, deleter > & other)
delete

Copy constructor.

◆ Handle() [3/3]

template<typename T , auto deleter>
kanzi::Handle< T, deleter >::Handle ( Handle< T, deleter > && other)
deletenoexcept

Move constructor.

Member Function Documentation

◆ operator=() [1/4]

template<typename T , auto deleter>
Handle & kanzi::Handle< T, deleter >::operator= ( const Handle< T, deleter > & other)
delete

Copy assignment operator.

◆ operator=() [2/4]

template<typename T , auto deleter>
Handle & kanzi::Handle< T, deleter >::operator= ( Handle< T, deleter > && other)
deletenoexcept

Move assignment operator.

◆ operator=() [3/4]

template<typename T , auto deleter>
Handle & kanzi::Handle< T, deleter >::operator= ( const NativeHandleType & value)
inline

Copy assignment operator.

Takes an ownership of the resource.

Parameters
valueHandle to store.

◆ operator=() [4/4]

template<typename T , auto deleter>
Handle & kanzi::Handle< T, deleter >::operator= ( NativeHandleType && value)
inlinenoexcept

Move assignment operator.

Takes an ownership of the resource.

Parameters
valueHandle to store.

◆ swap()

template<typename T , auto deleter>
void kanzi::Handle< T, deleter >::swap ( Handle< T, deleter > & other)
inline

Swap function.

Parameters
otherSecond object to swap with.

◆ getDeleter()

template<typename T , auto deleter>
static constexpr auto kanzi::Handle< T, deleter >::getDeleter ( )
inlinestaticconstexprnoexcept

Gets deleter function.

Returns
Deleter function.

◆ get() [1/2]

template<typename T , auto deleter>
KZ_NO_DISCARD NativeHandleType kanzi::Handle< T, deleter >::get ( )
inlinenoexcept

Provides access to stored handle.

Returns
Pointer to stored handle.

◆ get() [2/2]

template<typename T , auto deleter>
KZ_NO_DISCARD const NativeHandleType kanzi::Handle< T, deleter >::get ( ) const
inlinenoexcept

Provides access to stored handle.

Returns
Const stored handle.

◆ getNativeHandle() [1/2]

template<typename T , auto deleter>
KZ_NO_DISCARD NativeHandleType kanzi::Handle< T, deleter >::getNativeHandle ( )
inlinenoexcept

Provides access to stored handle.

Returns
Stored handle.

◆ getNativeHandle() [2/2]

template<typename T , auto deleter>
KZ_NO_DISCARD const NativeHandleType kanzi::Handle< T, deleter >::getNativeHandle ( ) const
inlinenoexcept

Provides access to stored handle.

Returns
Const stored handle.

◆ reset()

template<typename T , auto deleter>
template<typename U , typename = enable_if_t<is_convertible_v<decay_t<U>, NativeHandleType>>>
void kanzi::Handle< T, deleter >::reset ( U && newHandle)
inlinenoexcept

Stores a new handle inside.

Takes an ownership of the resource.

Note
Resources associated with old handle are properly destroyed.
Template Parameters
UDeduced type for universal reference of T.
Parameters
newHandleNew handle to store.

The documentation for this class was generated from the following file: