Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

RTAutoRes< T, Destruct, NilRes > Class Template Reference

#include <autores.h>

Inheritance diagram for RTAutoRes< T, Destruct, NilRes >:

RTCNonCopyable

List of all members.


Detailed Description

template<class T, void Destruct = RTAutoResDestruct<T>, T NilRes = RTAutoResNil<T>>
class RTAutoRes< T, Destruct, NilRes >

An auto pointer-type class for resources which take a C-style destructor (RTMemFree() or equivalent).

The idea of this class is to manage resources which the current code is responsible for freeing. By wrapping the resource in an RTAutoRes, you ensure that the resource will be freed when you leave the scope in which the RTAutoRes is defined, unless you explicitly release the resource.

A typical use case is when a function is allocating a number of resources. If any single allocation fails then all other resources must be freed. If all allocations succeed, then the resources should be returned to the caller. By placing all allocated resources in RTAutoRes containers, you ensure that they will be freed on failure, and only have to take care of releasing them when you return them.

Parameters:
T The type of the resource.
Destruct The function to be used to free the resource. This parameter must be supplied if there is no specialisation of RTAutoDestruct available for T.
NilRes The function returning the NIL value for T. Required. This parameter must be supplied if there is no specialisation of RTAutoResNil available for T.
Note:
The class can not be initialised directly using assignment, due to the lack of a copy constructor. This is intentional.

Definition at line 114 of file autores.h.


Public Member Functions

get (void)
bool operator! ()
RTAutoResoperator= (T a_hRes)
release (void)
void reset (T a_hRes=NilRes())
 RTAutoRes (T a_hRes=NilRes())
 ~RTAutoRes ()

Protected Attributes

m_hRes

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

Generated by  Doxygen 1.6.0   Back to index