|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept id="GUID-3B0BF8FF-88AB-5BF4-9F04-5F82A3998699" xml:lang="en"><title>How |
|
13 to store and restore a non-compound object</title><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
14 <section><title> Storing</title> <p>The basic protocol for storing is the <codeph>StoreL()</codeph> function |
|
15 and should be prototyped as:</p> <codeblock id="GUID-112220CB-F74B-59FA-8EF7-BA9D1C616860" xml:space="preserve">TStreamId StoreL(CStreamStore& aStore) const;</codeblock> <p>The function takes a reference to the store in which the stream is to |
|
16 be stored and returns the stream ID through which the object can be restored. </p> <p>In |
|
17 some cases, the design of a class may be such that it maintains a pointer |
|
18 or reference to the store. In this event, the <codeph>CStreamStore</codeph> argument |
|
19 would be redundant.</p> <p>To store an object that does not contain any other |
|
20 objects:</p> <ol id="GUID-1C25EAB3-DFBB-5486-B58D-45B4939A04FC"> |
|
21 <li id="GUID-18320343-D11D-59F4-A875-A7306E190864"><p>construct a write stream |
|
22 object, i.e. an instance of <codeph>RStoreWriteStream</codeph> </p> </li> |
|
23 <li id="GUID-DA4E34C4-CBC3-5C57-A329-CAA63053BC2D"><p>externalise the object</p> </li> |
|
24 <li id="GUID-C6137D35-5525-56FF-8906-C5B3E8AD28CE"><p>return the ID of the |
|
25 stream</p> </li> |
|
26 </ol> <p>The following code fragment shows the canonical form for some general |
|
27 class <codeph>CClassA</codeph>:</p> <codeblock id="GUID-3AA0A33A-940C-5315-813E-BC774D7F30A2" xml:space="preserve">TStreamId CClassA::StoreL(CStreamStore& aStore) const |
|
28 { |
|
29 RStoreWriteStream stream; |
|
30 TStreamId id=stream.CreateLC(aStore); |
|
31 ExternalizeL(stream); |
|
32 stream.CommitL(); |
|
33 CleanupStack::PopAndDestroy(); |
|
34 return id; |
|
35 }</codeblock> </section> |
|
36 <section><title>Restoring</title><p>The basic protocol for restoring is the |
|
37 <code>RestoreL()</code> function and should be prototyped as: |
|
38 </p><codeblock xml:space="preserve">void RestoreL(CStreamStore& aStore,TStreamId anId);</codeblock><p>The |
|
39 function takes a reference to the store in which the stream is stored and |
|
40 the ID that identifies that stream is stored.</p><p>To restore an object that |
|
41 does not contain any other objects:</p><ul> |
|
42 <li><p>construct a read stream object, i.e. an instance of</p><codeph>RStoreReadStream</codeph></li> |
|
43 <li><p>internalise the object.</p></li> |
|
44 </ul><p>The following code fragment shows an example for some general class</p><codeph>CClassA</codeph><codeblock xml:space="preserve"> void CClassA::RestoreL(CStreamStore& aStore, TStreamId anId) |
|
45 { |
|
46 RStoreReadStream stream; |
|
47 stream.OpenLC(aStore,anId); |
|
48 InternalizeL(stream); |
|
49 CleanupStack::PopAndDestroy(); |
|
50 }</codeblock><p/> </section> |
|
51 </conbody></concept> |