8 Contributors: |
8 Contributors: |
9 --> |
9 --> |
10 <!DOCTYPE task |
10 <!DOCTYPE task |
11 PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd"> |
11 PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd"> |
12 <task id="GUID-B9F07057-4B31-5FE8-BE4C-98CC8151CD29" xml:lang="en"><title>Single |
12 <task id="GUID-B9F07057-4B31-5FE8-BE4C-98CC8151CD29" xml:lang="en"><title>Single |
13 Phase Constructor Tutorial</title><shortdesc>Single phase construction is enabled by defining the <apiname>CONSTRUCTORS_MAY_LEAVE()</apiname> macro |
13 Phase Constructor Tutorial</title><shortdesc>Single phase construction is enabled by defining the <codeph>CONSTRUCTORS_MAY_LEAVE()</codeph> macro |
14 in a public section of a class definition if the single phase construction |
14 in a public section of a class definition if the single phase construction |
15 is part of the public interface of the class. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody> |
15 is part of the public interface of the class. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody> |
16 <prereq><p><b>Required background</b></p><p>Before beginning you must know |
16 <prereq id="GUID-0FCC96BD-B7C4-4604-96C1-D6E5D574AB53"><p><b>Required background</b></p><p>Before |
17 the following: </p> <ul> |
17 beginning you must know the following: </p> <ul> |
18 <li id="GUID-DC57A39F-122C-545C-A2A1-D26F71209C10"><p> <b>RAII:</b> The Resource |
18 <li id="GUID-DC57A39F-122C-545C-A2A1-D26F71209C10"><p> <b>RAII:</b> The Resource |
19 Acquisition Is Initialization (RAII) idiom is the basis of the implementation |
19 Acquisition Is Initialization (RAII) idiom is the basis of the implementation |
20 of the smart pointer class templates. </p> </li> |
20 of the smart pointer class templates. </p> </li> |
21 <li id="GUID-C0228985-A32D-5652-8CCC-4BF401998FCC"><p> <xref href="GUID-764C2888-7EA7-3F58-B519-878A82E879CA.dita"><apiname>CONSTRUCTORS_MAY_LEAVE()</apiname></xref>: |
21 <li id="GUID-C0228985-A32D-5652-8CCC-4BF401998FCC"><p> <xref href="GUID-764C2888-7EA7-3F58-B519-878A82E879CA.dita"><apiname>CONSTRUCTORS_MAY_LEAVE()</apiname></xref>: |
22 This macro is used for enabling single phase construction, particularly for |
22 This macro is used for enabling single phase construction, particularly for |
23 CBase-derived classes. </p> </li> |
23 CBase-derived classes. </p> </li> |
24 </ul> </prereq> |
24 </ul> </prereq> |
25 <context><p>Single phase constructor provides a means to use the RAII concepts |
25 <context id="GUID-D82AD7F2-633E-4A5B-9B82-4026A8F91B41"><p>Single phase constructor |
26 for Symbian Developers who are familiar with C++ standards. It is provided |
26 provides a means to use the RAII concepts for Symbian Developers who are familiar |
27 as a tool and needs to be used after careful consideration. </p> </context> |
27 with C++ standards. It is provided as a tool and needs to be used after careful |
|
28 consideration. </p> </context> |
28 <steps id="GUID-DF51DCE9-ACA3-4376-B4B3-4A31728670D2"> |
29 <steps id="GUID-DF51DCE9-ACA3-4376-B4B3-4A31728670D2"> |
29 <step id="GUID-FA70E487-145A-4502-BB58-B09A42F69183"><cmd>Enabling single |
30 <step id="GUID-FA70E487-145A-4502-BB58-B09A42F69183"><cmd>Enabling single |
30 phase constructor</cmd> |
31 phase constructor</cmd> |
31 <stepxmp><p>Single phase construction is enabled by defining the CONSTRUCTORS_MAY_LEAVE() |
32 <stepxmp><p>Single phase construction is enabled by defining the CONSTRUCTORS_MAY_LEAVE() |
32 macro in a public section of a class definition if the single phase construction |
33 macro in a public section of a class definition if the single phase construction |
62 ~CStringUserSinglePhase() |
63 ~CStringUserSinglePhase() |
63 { |
64 { |
64 |
65 |
65 }</codeblock></stepxmp> |
66 }</codeblock></stepxmp> |
66 </step> |
67 </step> |
67 <step id="GUID-D41D3443-FBFA-44DA-8E35-E82C12829F3D"><cmd>Need to declare the CONSTRUCTORS_MAY_LEAVE macro</cmd> |
68 <step id="GUID-D41D3443-FBFA-44DA-8E35-E82C12829F3D"><cmd>Need to declare |
68 <stepxmp><p>This is necessary because Symbian platform currently lacks the |
69 the CONSTRUCTORS_MAY_LEAVE macro</cmd> |
69 placement delete operator counterparts corresponding to the CBase placement |
70 <stepxmp><p>This is necessary because the Symbian platform currently lacks |
|
71 the placement delete operator counterparts corresponding to the CBase placement |
70 new operators that take a TLeave parameter (new(ELeave)). The macro defines |
72 new operators that take a TLeave parameter (new(ELeave)). The macro defines |
71 these missing placement delete operators and ensures that all allocated memory |
73 these missing placement delete operators and ensures that all allocated memory |
72 can be freed if a constructor leaves.</p></stepxmp> |
74 can be freed if a constructor leaves.</p></stepxmp> |
73 </step> |
75 </step> |
74 </steps> |
76 </steps> |