|
||
CDictionaryFileStore
is a concrete implementation of a
dictionary store and uses a file store in its implementation.
Although the need for a file based dictionary store is driven by the application architecture, the following code fragments illustrate the way this store can be used.
The code fragments shown here create and read a file based dictionary
store. This dictionary store is differentiated from other dictionary stores by
the UID whose value is 0x0001
.
It should be noted that the values assigned to the UIDs are purely arbitrary and are used for illustrative purposes only.
This code fragment constructs an object of type TClass
and stores it in the dictionary store, associating the stream with the UID
whose value is 0x0002.
Note that a dictionary write stream is needed to write streams to a dictionary store.
_LIT(KFileName,"C:\\data\\stdict.dat");
_LIT(KTxtData,"Text type data"):
TParse dictionaryname;
...
fsSession.Parse(KFileName,dictionaryname);
...
// Open the dictionary store (create if it doesn't exist)
CDictionaryStore* dictstore = CDictionaryFileStore::OpenLC (fsSession, dictionaryname.FullName(),TUid::Uid(0x0001) );
// Construct a TClass and put some data into it
TClass thedata;
thedata.iFixBuf = KTxtData;
thedata.iUintValue = 1;
thedata.iIntValue = -2;
thedata.iRealValue = 3.4;
// construct the dictionary write stream and
// associate the stream with the UID
// whose value is 0x0002
RDictionaryWriteStream out;
out.AssignLC(*dictstore,TUid::Uid(0x0002));
// write the TClass data to the stream
out << thedata;
// Commit changes to the stream
out.CommitL();
// Cleanup the dictionary stream object
CleanupStack::PopAndDestroy();
// Now commit all changes to the store
dictstore->CommitL();
// Close the dictionary store (closes the
// associated file and destroys the
// dictionary store object)
CleanupStack::PopAndDestroy();
This code fragment re-opens the dictionary store and restores the
TClass
object from the stream associated with the UID whose value
is 0x0002
.
_LIT(KFileName,"C:\\data\\stdict.dat");
TParse dictionaryname;
...
fsSession.Parse(KFileName,dictionaryname);
...
// Open the dictionary store
CDictionaryStore* dictstore=CDictionaryFileStore::OpenLC(fsSession, dictionaryname.FullName(), TUid::Uid(0x0001) );
// construct the dictionary read stream.
// Prepare to read the stream associated with
// the unique identifier whose value is 0x0002
RDictionaryReadStream in;
in.OpenLC(*dictstore,TUid::Uid(0x0002));
// Construct a TClass object ...
TClass thedata;
// ... and read data from the stream
in >> thedata;
// Cleanup the dictionary stream object
// and ...
// Close the dictionary store
// (closes the associated file and destroys the
// dictionary store object)
CleanupStack::PopAndDestroy(2);