|
Core Library
|
A class for temporarily managing the lifetime of resources that require a custom destroy function. More...
#include <Scoped.hpp>
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. | |
| T | 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. | |
| T | detach () |
| Release ownership of the resource. | |
Private Attributes | |
| T | m_resource |
| The value to manage. | |
| Deleter | m_deleter |
| The function used to destroy the resource. | |
| T | m_null |
| The resource specific NULL value. | |
Friends | |
| T * | attachTo (Scoped< T > &guard) |
| Allow attachment via an output parameter. | |
A class for temporarily managing the lifetime of resources that require a custom destroy function.
| typedef void(* Core::Scoped< T >::Deleter)(T) |
The type of the function used to destroy the resource.
| Core::Scoped< T >::Scoped | ( | Deleter | deleter, |
| T | 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.
| Core::Scoped< T >::Scoped | ( | T | resource, |
| Deleter | deleter, | ||
| T | null = 0 |
||
| ) | [inline] |
Construction from a resource, its destroy function and null value.
| Core::Scoped< T >::~Scoped | ( | ) | [inline] |
Destructor.
| T Core::Scoped< T >::get | ( | ) | const [inline] |
Get the managed resource.
| bool Core::Scoped< T >::empty | ( | ) | const [inline] |
Query if we are not owning a resource.
| void Core::Scoped< T >::reset | ( | ) | [inline] |
Destroy the resource.
| void Core::Scoped< T >::attach | ( | T | resource | ) | [inline] |
Acquire ownership of a resource.
If a resource is already held it is destroyed first.
| T Core::Scoped< T >::detach | ( | ) | [inline] |
Release ownership of the resource.
Allow attachment via an output parameter.
e.g. LoadTypeLib(..., attachTo(p)).
T Core::Scoped< T >::m_resource [private] |
The value to manage.
Deleter Core::Scoped< T >::m_deleter [private] |
The function used to destroy the resource.
T Core::Scoped< T >::m_null [private] |
The resource specific NULL value.
1.7.6.1