LManagedGuard Class Reference

class LManagedGuard

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

Note:

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
	   {
	 public:
	   CONSTRUCTORS_MAY_LEAVE

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

	   ~CComposite()
		   {
		   // RCleanable::Cleanup(iObj) is automatically invoked
		   }

	 private:
	   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.

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

Public Member Functions
LManagedGuard(TCleanupOperation, TAny *)
~LManagedGuard()
voidDismiss()
voidExecute()
Private Member Functions
LManagedGuard(const LManagedGuard &)
LManagedGuard &operator=(const LManagedGuard &)
Private Attributes
TCleanupOperation iCleanupOperation
TAny *iData

Constructor & Destructor Documentation

LManagedGuard(TCleanupOperation, TAny *)

LManagedGuard(TCleanupOperationaCleanupOperation,
TAny *aData = 0
)[inline]

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.

Parameters

TCleanupOperation aCleanupOperationA cleanup operation.
TAny * aData = 0Pointer to data to be passed to the cleanup operation

LManagedGuard(const LManagedGuard &)

LManagedGuard(const LManagedGuard &)[private]

Parameters

const LManagedGuard &

~LManagedGuard()

~LManagedGuard()[inline]

Destructor.

Member Functions Documentation

Dismiss()

voidDismiss()[inline]

Disables the guard.

Execute()

voidExecute()[inline]

Executes the guard cleanup operation.

operator=(const LManagedGuard &)

LManagedGuard &operator=(const LManagedGuard &)[private]

Parameters

const LManagedGuard &

Member Data Documentation

TCleanupOperation iCleanupOperation

TCleanupOperation iCleanupOperation[private]

TAny * iData

TAny *iData[private]