LCleanedupGuard Class Reference

#include <emanaged.h>

class LCleanedupGuard

Detailed Description

A class that provides CleanupStack-based local-scope automatic cleanup using a TCleanupOperation on the destruction of the LManagedGuard object.

Note:

This class can only be used to define a local stack scoped cleanup, never an object scoped cleanup to guard object destruction. 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 either of the following occur:
  • The guarding local variable goes out of scope normally

  • The guarding local variable goes out of scope due to an untrapped leave causing the scope to be exited non-locally

The constructors of this class may leave.

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

	// block scope example
	{
	RCleanable obj;
	LCleanedupGuard cleanGuard(RCleanable::Cleanup, &obj);

	obj.DoSomethingL(); // leave-safe
	if (Finished())
		return; // RCleanable::Cleanup is invoked automatically when exiting from scope
	obj.DoSomethingElseL(); // leave-safe
	//	RCleanable::Cleanup is invoked automatically when exiting from scope
	}

Behind the scenes, this class template is implemented in terms of the thread-local CleanupStack, restricting its use to local stack scope. This use of the CleanupStack ensures a consistent cleanup order between functions that call one another, even if they use different cleanup idioms.

See also: LManagedGuard which has the same interface, but does not use the cleanup stack and is suitable for use as the data member of a class to guard object destruction.

Constructor & Destructor Documentation

LCleanedupGuard ( TCleanupOperation, TAny * )

LCleanedupGuard(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
aCleanupOperationA cleanup operation.
aDataPointer to data to be passed to the cleanup operation

~LCleanedupGuard ( )

~LCleanedupGuard()[inline]

Destructor.

Member Function Documentation

Cleanup ( TAny * )

voidCleanup(TAny *aPtr)[static, inline]

Dismiss ( )

voidDismiss()[inline]

Disables the guard.

Execute ( )

voidExecute()[inline]

Executes the guard cleanup operation.