The Resource Acquisition Is Initialization (RAII) idiom is the basis of implementation of the smart pointer class template. It is also used by the implementation of the file stream classes provided by C++ Standard Library and by many others. The Symbian C++ class templates for automatic resource management are based on the C++ RAII idiom, in order to provide exception-safe automatic cleanup on normal or exceptional exit from a scope.
The current Symbian C++ resource management mechanism is the Symbian Cleanup Stack. The CleanupStack class and the associated functions provides Symbian C++ exception-safe (leave safe) cleanup when used in conjunction with the Symbian Leave mechanism. The RAII idiom can free resources automatically. The idiom consists of a class with a constructor that allocates a resource and a destructor that frees the resource. When a local variable of that class type is declared, it will automatically call the destructor to free the resource when leaving the scope. This also protects against leaks caused by thrown exceptions.
The LCleanedupX and LManagedX class templates share a common API as described below:
void ReleaseResource()
Description: This method forces cleanup of a managed resource. If automatic resource management is enabled, the specified cleanup strategy is invoked for the managed reference and the automatic resource management is then disabled.
T& Unmanage()
Description: This method disables automatic cleanup of a managed resource and returns a reference to the object of type T.
TBool IsEnabled()
Description: This method returns ETrue if automatic resource management is enabled, otherwise returns EFalse.
T& Get()
Description: This method returns a reference to the managed object of type T for Ref, Handle and Guard variants of LCleanedupX and LManagedX.
T* Get()
Description: This method returns a pointer to the managed object of type T for Ptr and Array variants of LCleanedupX and LManagedX.
Operators
The . operator gives access to the public members of the managing class.
The -> operator gives access to the public members of the managed class.
The * operator is used to get a reference or pointer to the underlying managed object.
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.