LCleanedupGuard Class Reference

class LCleanedupGuard

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.

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 ( TCleanupOperation aCleanupOperation,
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 aCleanupOperation A cleanup operation.
TAny * aData = 0 Pointer to data to be passed to the cleanup operation

LCleanedupGuard(const LCleanedupGuard &)

LCleanedupGuard ( const LCleanedupGuard & ) [private]

Parameters

const LCleanedupGuard &

~LCleanedupGuard()

~LCleanedupGuard ( ) [inline]

Destructor.

Member Functions Documentation

Cleanup(TAny *)

void Cleanup ( TAny * aPtr ) [static, inline]

Parameters

TAny * aPtr

Dismiss()

void Dismiss ( ) [inline]

Disables the guard.

Execute()

void Execute ( ) [inline]

Executes the guard cleanup operation.

operator=(const LCleanedupGuard &)

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

Parameters

const LCleanedupGuard &

Member Data Documentation

TCleanupOperation iCleanupOperation

TCleanupOperation iCleanupOperation [private]

TAny * iData

TAny * iData [private]