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