PStack  2.0
Stack trace printer for MSVC and GCC binaries
psystem::unique_handle< T, default_close_handle< T >, kInvalidHandle > Class Template Reference

Uniquely manage a single "handle" with (optimized for the default "deleter"). More...

#include <unique_handle.hpp>

Inheritance diagram for psystem::unique_handle< T, default_close_handle< T >, kInvalidHandle >:
Collaboration diagram for psystem::unique_handle< T, default_close_handle< T >, kInvalidHandle >:

Type Declarations

using base = unique_handle_impl< T, default_close_handle< T >, kInvalidHandle >
 A convenient name for the base-class type.
 
using safe_address_container = psystem::internal::managed_handle_proxy< handle_type, unique_handle< handle_type, deleter_type, kInvalidHandle > >
 A safe container for altering the handle by the address-of operator.
 
using deleter_type = D
 The data-type of the clean-up facility.
 
using handle_type = T
 The data-type of the handle being managed.
 

Construction / Destruction

 unique_handle (handle_type hndl=kInvalidHandle) noexcept
 Construct an instance to manage a handle. More...
 
 unique_handle (unique_handle &&other) noexcept
 Transfer ownership of a handle from another unique_handle. More...
 
 ~unique_handle () noexcept
 Destroy this container, freeing the handle managed within. More...
 

Operator Overloads

unique_handleoperator= (unique_handle &&o) noexcept
 Transfer ownership of a handle into this instance. More...
 
safe_address_container operator& () noexcept
 Allow safe alteration of the handle by routines that return data by C-style output parameters. More...
 

Public Interface

void reset (handle_type hndl=kInvalidHandle) noexcept
 Assign a new handle to be managed by this instance. More...
 
void swap (unique_handle &o) noexcept
 Swap ownership of two unique_handle instances. More...
 

Additional Inherited Members

- Public Types inherited from psystem::unique_handle_impl< T, default_close_handle< T >, kInvalidHandle >
using deleter_type = default_close_handle< T >
 The data-type of the clean-up facility.
 
using handle_type = T
 The data-type of the handle being managed.
 
- Public Member Functions inherited from psystem::unique_handle_impl< T, default_close_handle< T >, kInvalidHandle >
 unique_handle_impl (unique_handle_impl const &)=delete
 Disable copying because it will likely be deleted twice.
 
unique_handle_imploperator= (unique_handle_impl &)=delete
 Disable copy-assignment to prevent double-frees.
 
handle_type get () const noexcept
 Access the handle contained in this object. More...
 
handle_type release () noexcept
 Release the handle from being managed by this class. More...
 
 operator bool () const noexcept
 Determines the validity of this instance. More...
 
- Static Public Member Functions inherited from psystem::stack_allocated
static void operator delete (void *)=delete
 Individual object deletion.
 
static void operator delete[] (void *)=delete
 Array of type object deletion.
 
static void * operator new (size_t)=delete
 Individual object allocation.
 
static void * operator new[] (size_t)=delete
 Array of type allocation.
 

Detailed Description

template<typename T, T kInvalidHandle>
class psystem::unique_handle< T, default_close_handle< T >, kInvalidHandle >

Uniquely manage a single "handle" with (optimized for the default "deleter").

See the discussion in the unspecialized psystem::unique_handle for the full rationale behind this class template. Essentially, this class exists to optimize away the runtime storage for a deleter that we know how to use. Naturally, this causes the API to remove deleter-specific items like unique_handle::get_deleter().

Note
Part of this API exists within unique_handle_impl, but Doxygen isn't supplying this connection when explicit subgroupings are used. See this class template for basic accessors to the handle.
Author
Matt Bisson
Date
24 August, 2014
Since
PSystem 2.0
Version
PSystem 2.0

Constructor & Destructor Documentation

template<typename T , T kInvalidHandle>
psystem::unique_handle< T, default_close_handle< T >, kInvalidHandle >::unique_handle ( handle_type  hndl = kInvalidHandle)
inlineexplicitnoexcept

Construct an instance to manage a handle.

Construction always succeeds, as exceptions are not allowed. If no parameter is specified, this constructs an instance that does not (initially) own an handle.

Parameters
[in]hndlThe handle (or invalid handle value) that this instance will manage.
template<typename T , T kInvalidHandle>
psystem::unique_handle< T, default_close_handle< T >, kInvalidHandle >::unique_handle ( unique_handle< T, default_close_handle< T >, kInvalidHandle > &&  other)
inlinenoexcept

Transfer ownership of a handle from another unique_handle.

Warning
This differs from the std::unique_ptr in that it does not allow the transfer of related handle types. Often, handles are convertable types (void* to void* or long to long) that are merely obscured via a typedef. Transferring ownership of different handle types would also require changing the type of the deleter_type and the value of invalid_handle_value.
Parameters
[in,out]otherThe unique_handle from which we're moving data.
template<typename T , T kInvalidHandle>
psystem::unique_handle< T, default_close_handle< T >, kInvalidHandle >::~unique_handle ( )
inlinenoexcept

Destroy this container, freeing the handle managed within.

If the handle is invalid_handle_value, this method does not call the deleter. The deleter contained within this instance will also be destroyed.

Member Function Documentation

template<typename T , T kInvalidHandle>
safe_address_container psystem::unique_handle< T, default_close_handle< T >, kInvalidHandle >::operator& ( )
inlinenoexcept

Allow safe alteration of the handle by routines that return data by C-style output parameters.

Returns
A temporary object designed to track any changes to the handle when accessed by address. If the handle changes while the "safe" container tracks it, the prior handle will be released safely.
template<typename T , T kInvalidHandle>
unique_handle& psystem::unique_handle< T, default_close_handle< T >, kInvalidHandle >::operator= ( unique_handle< T, default_close_handle< T >, kInvalidHandle > &&  o)
inlinenoexcept

Transfer ownership of a handle into this instance.

Warning
This differs from the std::unique_ptr in that it does not allow the transfer of related handle types. Often, handles are convertable types (void* to void* or long to long) that are merely obscured via a typedef. Transferring ownership of different handle types would also require changing the type of the deleter_type and the value of invalid_handle_value.
Parameters
[in,out]oThe unique_handle from which we're moving data.
Returns
A reference to this, after the assignment.
template<typename T , T kInvalidHandle>
void psystem::unique_handle< T, default_close_handle< T >, kInvalidHandle >::reset ( handle_type  hndl = kInvalidHandle)
inlinenoexcept

Assign a new handle to be managed by this instance.

If there was a valid handle managed previously by this unique_handle instance, its resources will be cleaned up prior to assigning the new handle. If the new handle equals (==) the old handle, this method does nothing.

If no parameters are specified, this resets the unique_handle to the "invalid" state.

Parameters
[in]hndlThe new handle to manage. It need not be "valid."
template<typename T , T kInvalidHandle>
void psystem::unique_handle< T, default_close_handle< T >, kInvalidHandle >::swap ( unique_handle< T, default_close_handle< T >, kInvalidHandle > &  o)
inlinenoexcept

Swap ownership of two unique_handle instances.

Parameters
[in,out]oThe unique_handle instance that will swap handle data with this instance.

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