Week 23 contribution of PDK documentation content. See release notes for details. Fixes bugs Bug 2714, Bug 462.
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License
"Eclipse Public License v1.0" which accompanies this distribution,
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
Nokia Corporation - initial contribution.
Contributors:
-->
<!DOCTYPE concept
PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept xml:lang="en" id="GUID-96AB1D5A-932E-55BE-A025-F01608546B99"><title>RAII Idiom</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>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. </p> <section><title>Need for RAII Idiom</title> <p>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. </p> </section> <section><title>RAII APIs</title> <p>The LCleanedupX and LManagedX class templates share a common API as described below: </p> <ul><li id="GUID-73832E1B-FF2E-5779-AB4C-CAABAB564CE8"><p> <xref href="GUID-C945DFA5-819F-3EB4-8762-25AD191C8DCE.dita"><apiname> ReleaseResource()</apiname></xref> </p> <codeblock id="GUID-3410D6E2-2A5C-54D2-95A5-AE38AFEA682F" xml:space="preserve">void ReleaseResource()</codeblock> <p> <b>Description:</b> 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. </p> </li> <li id="GUID-77F69FF8-E61A-5B57-B887-D66EC29F4CF9"><p> <xref href="GUID-BDB6254A-B55E-3834-8187-1CD9DF3C5968.dita"><apiname> Unmanage()</apiname></xref> </p> <codeblock id="GUID-7D6FDC92-A0A6-5AB5-AD7E-69E9C9C52206" xml:space="preserve">T& Unmanage()</codeblock> <p> <b>Description:</b> This method disables automatic cleanup of a managed resource and returns a reference to the object of type T. </p> </li> <li id="GUID-E1CC7B50-A4C6-599E-9A4B-A78D650B8121"><p> <xref href="GUID-344DF799-7861-3E54-8B92-7F96956A5237.dita"><apiname>IsEnabled()</apiname></xref> </p> <codeblock id="GUID-36EED42A-0C9B-5BC3-B7B7-AFD2365DF2F8" xml:space="preserve">TBool IsEnabled()</codeblock> <p> <b>Description:</b> This method returns ETrue if automatic resource management is enabled, otherwise returns EFalse. </p> </li> <li id="GUID-4B6610DD-BD24-527E-A9C6-6E23391C789C"><p> <xref href="GUID-890C741F-EC69-30E3-AA89-CE35B3DE481F.dita"><apiname>Get()</apiname></xref> </p> <codeblock id="GUID-F473AB80-49AC-5355-8879-649A05034E03" xml:space="preserve">T& Get()</codeblock> <p> <b>Description:</b> This method returns a reference to the managed object of type T for Ref, Handle and Guard variants of LCleanedupX and LManagedX. </p> <codeblock id="GUID-F6F79274-1B93-5E05-8446-8C00E479F0AD" xml:space="preserve">T* Get()</codeblock> <p> <b>Description:</b> This method returns a pointer to the managed object of type T for Ptr and Array variants of LCleanedupX and LManagedX. </p> </li> <li id="GUID-96477A5F-5CB1-55DE-9924-7A4AB341AFBE"><p>Operators </p> <p>The <b>.</b> operator gives access to the public members of the managing class. </p> <p>The <b>-></b> operator gives access to the public members of the managed class. </p> <p>The <b>*</b> operator is used to get a reference or pointer to the underlying managed object. </p> <p> </p> <p> </p> </li> </ul> </section> <section><title>See Also</title> <p><xref href="GUID-B007634D-4D55-528A-8B85-6120C633AC8B.dita">EUser High Level Library Overview</xref> </p> <p><xref href="GUID-D33EB877-CCCB-527B-8AFC-4A8385C55E78.dita">EUser High Level Library Tutorials</xref> </p> </section> </conbody></concept>