Symbian3/SDK/Source/GUID-5592E9C1-D490-538F-9B11-5EFB72DEDBE2.dita
changeset 0 89d6a7a84779
equal deleted inserted replaced
-1:000000000000 0:89d6a7a84779
       
     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-5592E9C1-D490-538F-9B11-5EFB72DEDBE2" xml:lang="en"><title>File
       
    13 based dictionary store</title><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    14 <p><codeph>CDictionaryFileStore</codeph> is a concrete implementation of a
       
    15 dictionary store and uses a file store in its implementation.</p>
       
    16 <p>Although the need for a file based dictionary store is driven by the application
       
    17 architecture, the following code fragments illustrate the way this store can
       
    18 be used.</p>
       
    19 <p>The code fragments shown here create and read a file based dictionary store.
       
    20 This dictionary store is differentiated from other dictionary stores by the
       
    21 UID whose value is <codeph>0x0001</codeph>.</p>
       
    22 <p>It should be noted that the values assigned to the UIDs are purely <i>arbitrary</i> and
       
    23 are used for <i>illustrative purposes only</i>.</p>
       
    24 <section><title>Creating the dictionary store</title> <p>This code fragment
       
    25 constructs an object of type <codeph>TClass</codeph> and stores it in the
       
    26 dictionary store, associating the stream with the UID whose value is 0x0002.</p> <p>Note
       
    27 that a dictionary write stream is needed to write streams to a dictionary
       
    28 store.</p> <codeblock id="GUID-AF74B440-E5A9-5A47-84E1-09E2243BB911" xml:space="preserve">_LIT(KFileName,"C:\\data\\stdict.dat");
       
    29 _LIT(KTxtData,"Text type data"):
       
    30 TParse dictionaryname;
       
    31 ...
       
    32 fsSession.Parse(KFileName,dictionaryname);
       
    33 ... 
       
    34            // Open the dictionary store (create if it doesn't exist)
       
    35 CDictionaryStore* dictstore = CDictionaryFileStore::OpenLC (fsSession, dictionaryname.FullName(),TUid::Uid(0x0001) );
       
    36 
       
    37            // Construct a TClass and put some data into it
       
    38 TClass thedata;
       
    39 thedata.iFixBuf    = KTxtData;
       
    40 thedata.iUintValue = 1;
       
    41 thedata.iIntValue  = -2; 
       
    42 thedata.iRealValue = 3.4;
       
    43 
       
    44            // construct the dictionary write stream and
       
    45            // associate the stream with the UID
       
    46            // whose value is 0x0002
       
    47 RDictionaryWriteStream out;
       
    48 out.AssignLC(*dictstore,TUid::Uid(0x0002));
       
    49 
       
    50            // write the TClass data to the stream
       
    51 out &lt;&lt; thedata;
       
    52  
       
    53            // Commit changes to the stream
       
    54 out.CommitL(); 
       
    55 
       
    56            // Cleanup the dictionary stream object
       
    57 CleanupStack::PopAndDestroy();
       
    58 
       
    59            // Now commit all changes to the store
       
    60 dictstore-&gt;CommitL();
       
    61 
       
    62            // Close the dictionary store (closes the
       
    63            // associated file and destroys the 
       
    64            // dictionary store object)
       
    65 CleanupStack::PopAndDestroy(); </codeblock> </section>
       
    66 <section><title>Reopening the dictionary store</title><p>This code fragment
       
    67 re-opens the dictionary store and restores the
       
    68 &lt;code&gt;TClass&lt;/code&gt; object from the stream associated with the UID whose
       
    69 value  is &lt;code&gt;0x0002&lt;/code&gt;
       
    70 </p><codeph>0x0002</codeph><codeblock xml:space="preserve">_LIT(KFileName,"C:\\data\\stdict.dat");
       
    71 TParse dictionaryname;
       
    72 ...
       
    73 fsSession.Parse(KFileName,dictionaryname);
       
    74 ...
       
    75            // Open the dictionary store 
       
    76 CDictionaryStore* dictstore=CDictionaryFileStore::OpenLC(fsSession, dictionaryname.FullName(), TUid::Uid(0x0001) );
       
    77 
       
    78            // construct the dictionary read stream.
       
    79            // Prepare to read the stream associated with
       
    80            // the unique identifier whose value is 0x0002
       
    81 RDictionaryReadStream in;
       
    82 in.OpenLC(*dictstore,TUid::Uid(0x0002));
       
    83 
       
    84             // Construct a TClass object ...
       
    85 TClass thedata;
       
    86 
       
    87             // ... and read data from the stream
       
    88 in &gt;&gt; thedata;
       
    89 
       
    90             // Cleanup the dictionary stream object
       
    91             // and ...
       
    92             // Close the dictionary store
       
    93             // (closes the associated file and destroys the
       
    94             // dictionary store object)
       
    95 CleanupStack::PopAndDestroy(2);
       
    96 </codeblock> </section>
       
    97 <section><title>See also</title> <p><xref href="GUID-79F39C97-75E8-5DB1-B976-8FE76E6E60C9.dita">Dictionary
       
    98 stores</xref> </p> </section>
       
    99 </conbody></concept>