PStack  2.0
Stack trace printer for MSVC and GCC binaries
shared_handle.hpp File Reference

Declare an RAII container for sharing system API handles (psystem::shared_handle). More...

#include "platform.hpp"
#include <atomic>
#include "default_close_handle.hpp"
#include "stack_allocated.hpp"
#include "unique_handle.hpp"
Include dependency graph for shared_handle.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  psystem::shared_handle< T, kInvalidHandle >
 Share management of a single "handle" between multiple owners. More...
 
struct  psystem::shared_handle< T, kInvalidHandle >::shared_handle_data
 The basic control block for a shared_handle. More...
 
struct  psystem::shared_handle< T, kInvalidHandle >::shared_handle_data_with_delete< D >
 A control block for a shared_handle with a user-specified deleter. More...
 
struct  std::hash< psystem::shared_handle< T, kInvalidHandle > >
 Forward the hash functor along to the underlying handle type for psystem::shared_handle. More...
 

Namespaces

 psystem
 Contains the process examination "system" and basic frameworks.
 

Functions

template<typename T , T kInvalidHandle>
void std::swap (psystem::shared_handle< T, kInvalidHandle > &o1, psystem::shared_handle< T, kInvalidHandle > &o2) noexcept
 Delegate std::swap calls for shared_handle to the member function. More...
 
template<typename T , T kInvalidHandle>
bool operator== (psystem::shared_handle< T, kInvalidHandle > const &h1, psystem::shared_handle< T, kInvalidHandle > const &h2) noexcept
 Test for equality of two handles. More...
 
template<typename T , T kInvalidHandle>
bool operator!= (psystem::shared_handle< T, kInvalidHandle > const &h1, psystem::shared_handle< T, kInvalidHandle > const &h2) noexcept
 Test for inequality of two handles. More...
 
template<typename T , T kInvalidHandle>
bool operator< (psystem::shared_handle< T, kInvalidHandle > const &h1, psystem::shared_handle< T, kInvalidHandle > const &h2) noexcept
 Test if the first handle is less than the second. More...
 
template<typename T , T kInvalidHandle>
bool operator<= (psystem::shared_handle< T, kInvalidHandle > const &h1, psystem::shared_handle< T, kInvalidHandle > const &h2) noexcept
 Test if the first handle is less than or equal to the second. More...
 
template<typename T , T kInvalidHandle>
bool operator> (psystem::shared_handle< T, kInvalidHandle > const &h1, psystem::shared_handle< T, kInvalidHandle > const &h2) noexcept
 Test if the first handle is greater than the second. More...
 
template<typename T , T kInvalidHandle>
bool operator>= (psystem::shared_handle< T, kInvalidHandle > const &h1, psystem::shared_handle< T, kInvalidHandle > const &h2) noexcept
 Test if the first handle is greater than or equal to the second. More...
 

Detailed Description

Declare an RAII container for sharing system API handles (psystem::shared_handle).

Note
There are no comparison operators for shared_handle to simple handle types for a few reasons. First, it is difficult challenging (not impossible) to decide on a type for the unmanaged handle because handles are generally pointers or even integers that have been given another name via typedef. They may also be forward declarations of a type as well. The second reason is that many handle types will conflict with the bool operator—the expression "shared_handle(hndl) == hndl" may first convert the shared_handle to a bool, then use a simple equality operator that compares POD integers, or it call the operator== that takes shared_handle and the handle type. There is ambiguity. We will therefore not defined these operators, and only compare shared_handle to shared_handle.
Author
Matt Bisson
Date
5 August, 2014
Since
PSystem 2.0
Version
PSystem 2.0

Function Documentation

template<typename T , T kInvalidHandle>
bool operator!= ( psystem::shared_handle< T, kInvalidHandle > const &  h1,
psystem::shared_handle< T, kInvalidHandle > const &  h2 
)
inlinenoexcept

Test for inequality of two handles.

This ignores any deleter instance in the shared_handle.

Inequality is defined in terms of operator=().

Template Parameters
TThe handle type.
kInvalidHandleThe value of an "invalid" handle.
Parameters
[in]h1The first shared_handle to compare.
[in]h2The second shared_handle to compare.
Returns
The value of the comparison.
template<typename T , T kInvalidHandle>
bool operator< ( psystem::shared_handle< T, kInvalidHandle > const &  h1,
psystem::shared_handle< T, kInvalidHandle > const &  h2 
)
inlinenoexcept

Test if the first handle is less than the second.

This ignores any deleter instance in the shared_handle.

This comparison is defined in terms of std::less.

Template Parameters
TThe handle type.
kInvalidHandleThe value of an "invalid" handle.
Parameters
[in]h1The first shared_handle to compare.
[in]h2The second shared_handle to compare.
Returns
The value of the comparison.
template<typename T , T kInvalidHandle>
bool operator<= ( psystem::shared_handle< T, kInvalidHandle > const &  h1,
psystem::shared_handle< T, kInvalidHandle > const &  h2 
)
inlinenoexcept

Test if the first handle is less than or equal to the second.

This ignores any deleter instance in the shared_handle.

This comparison is defined in terms of operator<()

Template Parameters
TThe handle type.
kInvalidHandleThe value of an "invalid" handle.
Parameters
[in]h1The first shared_handle to compare.
[in]h2The second shared_handle to compare.
Returns
The value of the comparison.
template<typename T , T kInvalidHandle>
bool operator== ( psystem::shared_handle< T, kInvalidHandle > const &  h1,
psystem::shared_handle< T, kInvalidHandle > const &  h2 
)
inlinenoexcept

Test for equality of two handles.

This ignores any deleter instance in the shared_handle.

Template Parameters
TThe handle type.
kInvalidHandleThe value of an "invalid" handle.
Parameters
[in]h1The first shared_handle to compare.
[in]h2The second shared_handle to compare.
Returns
The value of the comparison.
template<typename T , T kInvalidHandle>
bool operator> ( psystem::shared_handle< T, kInvalidHandle > const &  h1,
psystem::shared_handle< T, kInvalidHandle > const &  h2 
)
inlinenoexcept

Test if the first handle is greater than the second.

This ignores any deleter instance in the shared_handle.

This comparison is defined in terms of operator<()

Template Parameters
TThe handle type.
kInvalidHandleThe value of an "invalid" handle.
Parameters
[in]h1The first shared_handle to compare.
[in]h2The second shared_handle to compare.
Returns
The value of the comparison.
template<typename T , T kInvalidHandle>
bool operator>= ( psystem::shared_handle< T, kInvalidHandle > const &  h1,
psystem::shared_handle< T, kInvalidHandle > const &  h2 
)
inlinenoexcept

Test if the first handle is greater than or equal to the second.

This ignores any deleter instance in the shared_handle.

This comparison is defined in terms of operator<()

Template Parameters
TThe handle type.
kInvalidHandleThe value of an "invalid" handle.
Parameters
[in]h1The first shared_handle to compare.
[in]h2The second shared_handle to compare.
Returns
The value of the comparison.