AudRecordLib
Public Member Functions
WinType< Type, Ret > Class Template Reference

#include <scoped.h>

List of all members.

Public Member Functions

 WinType (const Type &data, ReleaseProc lpfnReleaser)
 WinType (ReleaseProc lpfnReleaser)
 WinType ()
 ~WinType ()
Type get () const
Type operator* () const
Type * operator& ()
 operator bool_type () const
void Init (const Type &newData, ReleaseProc lpfnNewReleaser)
Type Release ()
void Swap (WinType &other)

Detailed Description

template<class Type = HANDLE, class Ret = BOOL>
class WinType< Type, Ret >

Wrapper around a Windows resource such as HANDLE

Template Parameters:
TypeThe types of objects that'll be stored and released. Defaults to HANDLE
RetReturn type of the function that'll release said resource. Defaults to BOOL

Constructor & Destructor Documentation

template<class Type = HANDLE, class Ret = BOOL>
WinType< Type, Ret >::WinType ( const Type &  data,
ReleaseProc  lpfnReleaser 
) [inline]

Constructs the object with a resource and a releaser

Parameters:
dataThe resource to take ownership of
lpfnReleaserThe function used to free the resource on destruction
template<class Type = HANDLE, class Ret = BOOL>
WinType< Type, Ret >::WinType ( ReleaseProc  lpfnReleaser) [inline]

Constructs an object using the specified resource freeing function

The resource is left uninitialised. This constructor is primarily for use with operator& and passing the uninitialised resource to the creation function as a pointer-pointer parameter. E.g.

create with the releaser function WinType<PBYTE, NET_API_STATUS> memWrap(&NetApiBufferFree); initialise the wrapped resource indirectly NetGroupEnum(NULL, 1, &memWrap, ...);

template<class Type = HANDLE, class Ret = BOOL>
WinType< Type, Ret >::WinType ( ) [inline]

Constructs an uninitialised object

Init must be called to initialise the object at a later time

template<class Type = HANDLE, class Ret = BOOL>
WinType< Type, Ret >::~WinType ( ) [inline]

Frees the resource if the object has been initialised


Member Function Documentation

template<class Type = HANDLE, class Ret = BOOL>
Type WinType< Type, Ret >::get ( ) const [inline]

Retrieves the wrapped resource

The function asserts that the object is initialised before returning the pointer

Returns:
The objects resource
template<class Type = HANDLE, class Ret = BOOL>
void WinType< Type, Ret >::Init ( const Type &  newData,
ReleaseProc  lpfnNewReleaser 
) [inline]

Initialises an uninitialised object

Also asserts that the object hasn't been initialised

Parameters:
newDataA resource that the object takes ownership of.
lpfnNewReleaserFunction to use to release newData
template<class Type = HANDLE, class Ret = BOOL>
WinType< Type, Ret >::operator bool_type ( ) const [inline]

Safe bool idiom initialised check

Returns:
NULL if the object is in an uninitialised state, non-zero otherwise
template<class Type = HANDLE, class Ret = BOOL>
Type* WinType< Type, Ret >::operator& ( ) [inline]

Exposes the address of the wrapped, yet uninitialised resource

This operator is solely intended for use with the function pointer only constructor, whose use is asserted in the function.

Returns:
A pointer to an uninitialised resource
template<class Type = HANDLE, class Ret = BOOL>
Type WinType< Type, Ret >::operator* ( ) const [inline]

Retrieves the wrapped resource

Syntactic sugar for the get() function

Returns:
The resource
template<class Type = HANDLE, class Ret = BOOL>
Type WinType< Type, Ret >::Release ( ) [inline]

Releases the object's ownership of the stored resource

Returns the object back to an uninitialised state. The caller is then responsible for releasing the resource when it is no longer required.

Returns:
The stored resource
template<class Type = HANDLE, class Ret = BOOL>
void WinType< Type, Ret >::Swap ( WinType< Type, Ret > &  other) [inline]

Swaps the resources and functions stored in two disperate objects

Parameters:
otherThe object to swap this objects internals with

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Defines