#include <emanaged.h>
class LManagedGuard |
Public Member Functions | |
---|---|
LManagedGuard(TCleanupOperation, TAny *) | |
~LManagedGuard() | |
void | Dismiss() |
void | Execute() |
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.
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.
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
LManagedGuard | ( | 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 | |
---|---|
aCleanupOperation | A cleanup operation. |
aData | Pointer to data to be passed to the cleanup operation |