class LCleanedupPtr : protected LCleanedupPtrBase |
A class template that provides CleanupStack-based local-scope automatic management of pointers.
This class can only be used to define locals, never data members. See below for an explanation and links to management classes suitable for use in different contexts. It should never be used in the same function as code that uses the CleanupStack API directly
The referring local variable goes out of scope normally
The referring local variable goes out of scope due to an untrapped leave causing the scope to be exited non-locally
By default, the cleanup action is to delete the managed pointer using non-array delete. An alternative cleanup strategy may be selected by specifying a cleanup strategy template class in the optional second template parameter position. The most common alternative cleanup strategies are predefined.
The constructors of this class may leave.
As a convenience, the methods of the managed pointer may be accessed via "->" notation directly on the management object, while "." notation is used to access the interface of the management object itself. Using "*" to dereference the management object yields a T&, and is often useful when passing the managed object as an argument.
Automatic cleanup may be disabled at any time by calling Unmanage(), while cleanup may be forced at any time by calling ReleaseResource().
// block scope example { LCleanedupPtr<CDynamic> autop(new(ELeave) CDynamic); autop->DoSomethingL(); // leave-safe if (autop->Finished()) return; // the pointer is deleted automatically when exiting from scope autop->DoSomethingElseL(); // leave-safe // the pointer is deleted automatically when exiting from scope }
Behind the scenes, this class template is implemented in terms of the thread-local CleanupStack, restricting its use to locals on the stack. This use of the CleanupStack ensures a consistent cleanup order between functions that call one another, even if they use different cleanup idioms.
This class template together with the cleanup strategy class templates provide a template-based implementation of the Strategy design pattern (See also: Policy-based design).
TPointerDelete which implements the default deleting cleanup strategy
TPointerFree which implements the alternative User::Free() cleanup strategy
LManagedPtr which has the same interface, but does not use the cleanup stack and is suitable for protecting the data members of classes
Public Member Functions | |
---|---|
LCleanedupPtr() | |
LCleanedupPtr(T *) | |
T * | Get() |
void | Swap(LCleanedupPtr &) |
T * | Unmanage() |
operator TUnspecifiedBoolType() | |
T & | operator*() |
T * | operator->() |
LCleanedupPtr & | operator=(T *) |
LCleanedupPtr & | operator=(U *) |
Public Member Type Definitions | |
---|---|
typedef | CleanupStrategyType CleanupStrategy |
typedef | LCleanedupPtrBase::BaseManagedType * LCleanedupPtr< T, CleanupStrategy >TUnspecifiedBoolType |
typedef | T ManagedType |
Private Member Type Definitions | |
---|---|
typedef | LCleanedupPtrBase< T, CleanupStrategyType > LCleanedupPtrBase |
Inherited Attributes | |
---|---|
LAutoPtrBase< TPtrCleanupTraits< T, CleanupStrategyType >::BaseManagedType >::iPtr |
LCleanedupPtr | ( | ) | [inline] |
Default constructor. Constructs an empty LCleanedupPtr object.
Get() == NULL
LCleanedupPtr | ( | T * | aPtr | ) | [inline, explicit] |
Explicit constructor template. Constructs a LCleanedupPtr object that manages the pointer aPtr of a type convertible to T* that can be cleaned up using the cleanup strategy of the LCleanedupPtr class. The default cleanup strategy is to delete the pointer to a heap-allocated object by using non-array delete. Alternative cleanup strategies can be specified by using the CleanupStrategy template parameter of the LCleanedupPtr class template.
aPtr is of a type convertible to T* and can be cleaned up using the cleanup strategy.
Get() == aPtr
T * aPtr | A pointer of a type that is convertible to T* that can be cleaned up using the cleanup strategy. |
T * | Get | ( | ) | const [inline] |
Returns a pointer to the managed object of type T.
A pointer to the managed object of type T.
void | Swap | ( | LCleanedupPtr & | aCleanedupPtr | ) | [inline] |
LCleanedupPtr & aCleanedupPtr |
T * | Unmanage | ( | ) | [inline] |
Disables the automatic resource management for this object and returns a pointer to the object of type T.
A pointer to the object of type T.
operator TUnspecifiedBoolType | ( | ) | [inline] |
Conversion operator that enables LCleanedupPtr objects to be used in boolean contexts.
An unspecified value of an unspecified type convertible to boolean, which has a boolean value equal to Get() != NULL
T & | operator* | ( | ) | const [inline] |
Overloaded indirection operator function.
A reference to the managed object of type T.
T * | operator-> | ( | ) | const [inline] |
Overloaded class member access operator function.
A pointer to the managed object of type T.
LCleanedupPtr & | operator= | ( | T * | aPtr | ) | [inline] |
Assigns a new pointer to be managed. The new pointer must be of a type convertible to T* and it must be possible to use the cleanup strategy of the LCleanedupPtr object for the cleanup of the new managed pointer. If the LCleanedupPtr object already contains a managed pointer, then the cleanup strategy is invoked with the managed pointer before assigning the new managed pointer.
aPtr is a pointer of a type that is convertible to T* and can be cleaned up using the cleanup strategy.
Get() == aPtr
T * aPtr | A pointer of a type that is convertible to T* that can be cleaned up using the cleanup strategy. |
LCleanedupPtr & | operator= | ( | U * | aPtr | ) | [inline] |
Assigns a new pointer to be managed. The new pointer must be of a type convertible to T* and it must be possible to use the cleanup strategy of the LCleanedupPtr object for the cleanup of the new managed pointer. If the LCleanedupPtr object already contains a managed pointer, then the cleanup strategy is invoked with the managed pointer before assigning the new managed pointer.
aPtr is a pointer of a type that is convertible to T* and can be cleaned up using the cleanup strategy.
Get() == aPtr
U * aPtr | A pointer of a type that is convertible to T* that can be cleaned up using the cleanup strategy. |
typedef LCleanedupPtrBase::BaseManagedType * | LCleanedupPtr< T, CleanupStrategy >TUnspecifiedBoolType |
typedef LCleanedupPtrBase< T, CleanupStrategyType > | LCleanedupPtrBase | [private] |