#include <emanaged.h>
class LCleanedupPtr : protected LCleanedupPtrBase |
Public Member Type Definitions | |
---|---|
typedef | CleanupStrategyType CleanupStrategy |
typedef | LCleanedupPtrBase::BaseManagedType * LCleanedupPtr< T, CleanupStrategy >TUnspecifiedBoolType |
typedef | T ManagedType |
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 *) |
Inherited Attributes | |
---|---|
LAutoPtrBase< TPtrCleanupTraits< T, CleanupStrategyType >::BaseManagedType >::iPtr |
Inherited Type Definitions | |
---|---|
LCleanedupPtrBase::BaseManagedType |
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).
See also: 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
typedef LCleanedupPtrBase::BaseManagedType * | LCleanedupPtr< T, CleanupStrategy >TUnspecifiedBoolType |
LCleanedupPtr | ( | ) | [inline] |
Default constructor. Constructs an empty LCleanedupPtr object.
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.
Parameter | Description |
---|---|
aPtr | A pointer of a type that is convertible to T* that can be cleaned up using the cleanup strategy. |
T * | Get | ( | ) | const [inline] |
Reimplemented from LAutoPtrBase< TPtrCleanupTraits< T, CleanupStrategyType >::BaseManagedType >::Get()const
Returns a pointer to the managed object of type T.
Returns: A pointer to the managed object of type T.
T * | Unmanage | ( | ) | [inline] |
Reimplemented from LAutoPtrBase< TPtrCleanupTraits< T, CleanupStrategyType >::BaseManagedType >::Unmanage()
Disables the automatic resource management for this object and returns a pointer to the object of type T.
Returns: A pointer to the object of type T.
operator TUnspecifiedBoolType | ( | ) | [inline] |
Conversion operator that enables LCleanedupPtr objects to be used in boolean contexts.
Returns: 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.
Returns: A reference to the managed object of type T.
T * | operator-> | ( | ) | const [inline] |
Reimplemented from LAutoPtrBase< TPtrCleanupTraits< T, CleanupStrategyType >::BaseManagedType >::operator->()const
Overloaded class member access operator function.
Returns: 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.
Parameter | Description |
---|---|
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] |
Reimplemented from LCleanedupPtrBase::operator=(U *)
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.
Parameter | Description |
---|---|
aPtr | A pointer of a type that is convertible to T* that can be cleaned up using the cleanup strategy. |