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

Base unique_handle functionality common to all template specializations. More...

#include <unique_handle.hpp>

Inheritance diagram for psystem::unique_handle_impl< T, D, kInvalidHandle >:
Collaboration diagram for psystem::unique_handle_impl< T, D, kInvalidHandle >:

Friends

template<typename T2 , typename , T2 kInvalidHandle2>
class unique_handle
 Limit use of this class ONLY to unique_handle; they are two halves of the same interface.
 

Type Declarations

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

The handle value that marks an "invalid" handle.

 unique_handle_impl (handle_type handle) noexcept
 Construct this base container object with a handle. More...
 

Copy Construction

 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.
 

Public Interface

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 Overloads

 operator bool () const noexcept
 Determines the validity of this instance. More...
 

Member Data

handle_type m_handle
 The handle that will be managed by this class.
 

Additional Inherited Members

- 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, typename D, T kInvalidHandle>
class psystem::unique_handle_impl< T, D, kInvalidHandle >

Base unique_handle functionality common to all template specializations.

Construction of this class is private, and only the declared friend, unique_handle can create an instance of this class. This class should be considered part of unique_handle — the part that provides the interface that has nothing to do with the "deleter". Template specializations for unique_handle focus on optimizing the memory size by removing the deleter field from the structure if it is a stateless function invocation (e.g., CloseHandle from the Win32 API).

Author
Matt Bisson
Date
24 August, 2014
Since
PSystem 2.0
Version
PSystem 2.0
Todo:
Irritatingly, constexpr is not possible on Windows, which makes the invalid_handle_value member not possible. It would be great to change the instances of kInvalidHandle back to invalid_handle_value when MSVC brings itself up to three years ago.
Todo:
Maybe we can keep the handle on a block that can be specialized to have/not have a deleter, rather than specializing pretty much the entire unique_handle class.

Constructor & Destructor Documentation

template<typename T, typename D, T kInvalidHandle>
psystem::unique_handle_impl< T, D, kInvalidHandle >::unique_handle_impl ( handle_type  handle)
inlineexplicitprivatenoexcept

Construct this base container object with a handle.

Parameters
[in]handleThe handle value to hold on behalf of derived classes. This may be invalid_handle_value.

Member Function Documentation

template<typename T, typename D, T kInvalidHandle>
handle_type psystem::unique_handle_impl< T, D, kInvalidHandle >::get ( ) const
inlinenoexcept

Access the handle contained in this object.

Returns
The handle (it may or may not be valid).
template<typename T, typename D, T kInvalidHandle>
psystem::unique_handle_impl< T, D, kInvalidHandle >::operator bool ( ) const
inlineexplicitnoexcept

Determines the validity of this instance.

This is comperable to a nullptr check for pointer types. The conversion is a "contextual" conversion, so it will work implicitly with boolean operators and if statements, but cannot implicitly convert to a boolean container.

Returns
true if this instance contains a valid handle, false, otherwise.
template<typename T, typename D, T kInvalidHandle>
handle_type psystem::unique_handle_impl< T, D, kInvalidHandle >::release ( )
inlinenoexcept

Release the handle from being managed by this class.

Returns
The handle (formerly) contained in this object (it may or may not be valid).
Postcondition
The handle will no longer be "closed" by this object.
Subsequent handle access will result in invalid_handle_value.

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