LManagedGuard Class Reference

#include <emanaged.h>

class LManagedGuard
Public Member Functions
LManagedGuard(TCleanupOperation, TAny *)

Detailed Description

A class that provides automatic cleanup using a TCleanupOperation on the destruction of the LManagedGuard object.


This class can only be used to define object scoped cleanup to guard object destruction, never local stack scoped cleanup. See below for an explanation and links to management classes suitable for use in different contexts.

This class can be used to manage a TCleanupOperation in such a way that the specified cleanup operation is guaranteed to be called when the guarding object is destroyed; typically when the object containing it is deleted.

The constructors of this class never leave, so data members defined with this type may be initialized safely during any phase of construction of the owning class.

Automatic cleanup may be disabled at any time by calling Dismiss(), while cleanup may be forced at any time by calling Execute().

   class CComposite : public CBase

	   CComposite(RCleanable* aObj)
		   : iObj(RCleanable::Cleanup, aObj)

		   // RCleanable::Cleanup(iObj) is automatically invoked

	   LManagedGuard<RCleanable> iObj;

Behind the scenes, this class template simply relies on reliable execution of its destructor. If used for a local variable rather than a data member, cleanup will occur but out-of-order compared to objects protected using the LCleanupXxx variants or the CleanupStack directly. Therefore it is not recommended for use in that context.

These management classes may be used as the basis for implementing leave-safe single-phase construction, since fully initialized data members protected in this way will get destroyed (so reliably triggering cleanup) if their containing classes leave during execution of their constructors. Note, however, that single-phase construction must be explicitly enabled in the containing class using the CONSTRUCTORS_MAY_LEAVE macro.

See also: LCleanedupGuard which has the same interface, but uses the cleanup stack and is suitable for use as a local to guard local scope exit CONSTRUCTORS_MAY_LEAVE

Constructor & Destructor Documentation

LManagedGuard ( TCleanupOperation, TAny * )

TAny *aData = 0

Constructor. Creates a LCleanedupGuard object that, when enabled, automatically invokes upon destruction a cleanup operation specified by the aCleanupOperation parameter with the pointer to data specified by the aData parameter.

aCleanupOperationA cleanup operation.
aDataPointer to data to be passed to the cleanup operation

~LManagedGuard ( )



Member Function Documentation

Dismiss ( )


Disables the guard.

Execute ( )


Executes the guard cleanup operation.