Core Library
Public Types | Public Member Functions | Private Attributes | Friends
Core::Scoped< T > Class Template Reference

A class for temporarily managing the lifetime of resources that require a custom destroy function. More...

#include <Scoped.hpp>

Inheritance diagram for Core::Scoped< T >:
Core::NotCopyable

List of all members.

Public Types

typedef void(* Deleter )(T)
 The type of the function used to destroy the resource.

Public Member Functions

 Scoped (Deleter deleter, T null=0)
 Construction from a destroy function and null value.
 Scoped (T resource, Deleter deleter, T null=0)
 Construction from a resource, its destroy function and null value.
 ~Scoped ()
 Destructor.
get () const
 Get the managed resource.
bool empty () const
 Query if we are not owning a resource.
void reset ()
 Destroy the resource.
void attach (T resource)
 Acquire ownership of a resource.
detach ()
 Release ownership of the resource.

Private Attributes

m_resource
 The value to manage.
Deleter m_deleter
 The function used to destroy the resource.
m_null
 The resource specific NULL value.

Friends

T * attachTo (Scoped< T > &guard)
 Allow attachment via an output parameter.

Detailed Description

template<typename T>
class Core::Scoped< T >

A class for temporarily managing the lifetime of resources that require a custom destroy function.


Member Typedef Documentation

template<typename T >
typedef void(* Core::Scoped< T >::Deleter)(T)

The type of the function used to destroy the resource.


Constructor & Destructor Documentation

template<typename T >
Core::Scoped< T >::Scoped ( Deleter  deleter,
null = 0 
) [inline]

Construction from a destroy function and null value.

This ctor is used with the attachTo() free function to setup the deleter before attaching the resource.

template<typename T >
Core::Scoped< T >::Scoped ( resource,
Deleter  deleter,
null = 0 
) [inline]

Construction from a resource, its destroy function and null value.

template<typename T >
Core::Scoped< T >::~Scoped ( ) [inline]

Destructor.


Member Function Documentation

template<typename T >
T Core::Scoped< T >::get ( ) const [inline]

Get the managed resource.

template<typename T >
bool Core::Scoped< T >::empty ( ) const [inline]

Query if we are not owning a resource.

template<typename T >
void Core::Scoped< T >::reset ( ) [inline]

Destroy the resource.

template<typename T >
void Core::Scoped< T >::attach ( resource) [inline]

Acquire ownership of a resource.

If a resource is already held it is destroyed first.

template<typename T >
T Core::Scoped< T >::detach ( ) [inline]

Release ownership of the resource.


Friends And Related Function Documentation

template<typename T >
T* attachTo ( Scoped< T > &  guard) [friend]

Allow attachment via an output parameter.

e.g. LoadTypeLib(..., attachTo(p)).


Member Data Documentation

template<typename T >
T Core::Scoped< T >::m_resource [private]

The value to manage.

template<typename T >
Deleter Core::Scoped< T >::m_deleter [private]

The function used to destroy the resource.

template<typename T >
T Core::Scoped< T >::m_null [private]

The resource specific NULL value.


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