00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "CommonStreamStore.h"
00035 #include <s32file.h>
00036
00037
00038
00039 LOCAL_C void doMakeAndExternalizeL(const TDesC& aName);
00040
00041
00042
00043 LOCAL_C void doInternalizeL(const TDesC& aName);
00044
00045
00046 class CCompound;
00047 LOCAL_C void doShow(const TDesC& aHeading,const CCompound& theSimple);
00048
00049
00050 class CClassA
00051 {
00052 public :
00053 void ExternalizeL(RWriteStream& aStream) const;
00054 void InternalizeL(RReadStream& aStream);
00055 public :
00056 TBuf<32> iBufferA;
00057 TInt iXA;
00058 TUint iYA;
00059 };
00060
00061
00062 class CClassB
00063 {
00064 public :
00065 void ExternalizeL(RWriteStream& aStream) const;
00066 void InternalizeL(RReadStream& aStream);
00067 public :
00068 TBuf<32> iBufferB;
00069 };
00070
00071
00072 class TClassC
00073 {
00074 public :
00075 void ExternalizeL(RWriteStream& aStream) const;
00076 void InternalizeL(RReadStream& aStream);
00077 public :
00078 TReal iZC;
00079 };
00080
00081
00082 class CCompound : public CBase
00083 {
00084 public :
00085 ~CCompound();
00086 static CCompound* NewLC();
00087 static CCompound* NewLC(CStreamStore& aStore,TStreamId anId);
00088 static CCompound* NewL(CStreamStore& aStore,TStreamId anId);
00089 TStreamId StoreL(CStreamStore& store);
00090 void RestoreL(CStreamStore& aStore,TStreamId anId);
00091 void InternalizeL(RReadStream& aStream);
00092 void ExternalizeL(RWriteStream& aStream) const;
00093 private:
00094 void ConstructL();
00095 void ConstructL(CStreamStore& aStore,TStreamId anId);
00096 public :
00097 CClassA* iCa;
00098 CClassB* iCb;
00099 TClassC iTc;
00100 };
00101
00102
00103 _LIT(KFullNameOfFileStore,"\\epoc32ex\\data\\stcompnd.dat");
00104
00105
00106
00107 LOCAL_C void doExampleL()
00108 {
00109
00110 fsSession.MkDirAll(KFullNameOfFileStore);
00111 doMakeAndExternalizeL(KFullNameOfFileStore);
00112 doInternalizeL(KFullNameOfFileStore);
00113 }
00114
00115 LOCAL_C void doMakeAndExternalizeL(const TDesC& aName)
00116 {
00117 TParse filestorename;
00118
00119 fsSession.Parse(aName,filestorename);
00120
00121
00122 CFileStore* store = CDirectFileStore::ReplaceLC(fsSession,filestorename.FullName(),EFileWrite);
00123
00124
00125 store->SetTypeL(KDirectFileStoreLayoutUid);
00126
00127
00128
00129 CCompound* thecompound = CCompound::NewLC();
00130
00131 _LIT(KTxtClassAText,"CClassA text");
00132 _LIT(KTxtClassBText,"CClassB text");
00133
00134 thecompound->iCa->iBufferA = KTxtClassAText;
00135 thecompound->iCa->iXA = -1;
00136 thecompound->iCa->iYA = 2;
00137 thecompound->iCb->iBufferB = KTxtClassBText;
00138 thecompound->iTc.iZC = 3.456;
00139
00140
00141
00142 _LIT(KTxtInitialContent,"... Initial content of CCompound");
00143 doShow(KTxtInitialContent,*thecompound);
00144
00145
00146
00147 TStreamId id = thecompound->StoreL(*store);
00148
00149
00150 store->SetRootL(id);
00151
00152
00153 store->CommitL();
00154
00155
00156
00157
00158
00159
00160 CleanupStack::PopAndDestroy(2);
00161 }
00162
00163 LOCAL_C void doInternalizeL(const TDesC& aName)
00164 {
00165 TParse filestorename;
00166
00167 fsSession.Parse(aName,filestorename);
00168
00169
00170 CFileStore* store = CDirectFileStore::OpenLC(fsSession,filestorename.FullName(),EFileRead);
00171
00172
00173
00174 CCompound* thecompound = CCompound::NewL(*store,store->Root());
00175
00176
00177
00178 _LIT(KTxtRestoredContent,"... Restored CCompound content.");
00179 doShow(KTxtRestoredContent,*thecompound);
00180
00181
00182
00183 CleanupStack::PopAndDestroy();
00184
00185
00186 delete thecompound;
00187 }
00188
00189 _LIT(KTxtNewLine,"\n");
00190 _LIT(KFormatType1,"\n%d");
00191 _LIT(KFormatType2,"\n%S");
00192 _LIT(KFormatType3,"\n%u");
00193 _LIT(KFormatType4,"\n%f");
00194
00195 LOCAL_C void doShow(const TDesC& aHeading,const CCompound& aCompound)
00196 {
00197 console->Printf(KTxtNewLine);
00198 console->Printf(aHeading);
00199 console->Printf(KFormatType2,&aCompound.iCa->iBufferA);
00200 console->Printf(KFormatType1,aCompound.iCa->iXA);
00201 console->Printf(KFormatType3,aCompound.iCa->iYA);
00202 console->Printf(KFormatType2,&aCompound.iCb->iBufferB);
00203 console->Printf(KFormatType4,aCompound.iTc.iZC);
00204 console->Printf(KTxtNewLine);
00205 }
00206
00207
00208
00209
00210
00211 CCompound::~CCompound()
00212 {
00213 delete iCa;
00214 delete iCb;
00215 }
00216
00217
00218
00219 CCompound* CCompound::NewLC()
00220 {
00221 CCompound* self=new (ELeave) CCompound;
00222 CleanupStack::PushL(self);
00223 self->ConstructL();
00224 return self;
00225 }
00226
00227
00228
00229 void CCompound::ConstructL()
00230 {
00231 iCa = new (ELeave) CClassA;
00232 iCb = new (ELeave) CClassB;
00233 }
00234
00235
00236
00237 CCompound* CCompound::NewL(CStreamStore& aStore,TStreamId anId)
00238 {
00239 CCompound* self=CCompound::NewLC(aStore,anId);
00240 CleanupStack::Pop();
00241 return self;
00242 }
00243
00244
00245
00246
00247 CCompound* CCompound::NewLC(CStreamStore& aStore,TStreamId anId)
00248 {
00249 CCompound* self=new (ELeave) CCompound;
00250 CleanupStack::PushL(self);
00251 self->ConstructL(aStore,anId);
00252 return self;
00253 }
00254
00255
00256
00257 void CCompound::ConstructL(CStreamStore& aStore,TStreamId anId)
00258 {
00259 iCa = new (ELeave) CClassA;
00260 iCb = new (ELeave) CClassB;
00261 RestoreL(aStore,anId);
00262 }
00263
00264 void CCompound::RestoreL(CStreamStore& aStore,TStreamId anId)
00265 {
00266 RStoreReadStream instream;
00267 instream.OpenLC(aStore,anId);
00268 InternalizeL(instream);
00269
00270 CleanupStack::PopAndDestroy();
00271 }
00272
00273
00274
00275 void CCompound::InternalizeL(RReadStream& aStream)
00276 {
00277 aStream >> *iCa;
00278 aStream >> *iCb;
00279 aStream >> iTc;
00280 }
00281
00282 TStreamId CCompound::StoreL(CStreamStore& aStore)
00283 {
00284 RStoreWriteStream outstream;
00285 TStreamId id = outstream.CreateLC(aStore);
00286
00287 ExternalizeL(outstream);
00288
00289 outstream.CommitL();
00290
00291 CleanupStack::PopAndDestroy();
00292 return id;
00293 }
00294
00295
00296 void CCompound::ExternalizeL(RWriteStream& aStream) const
00297 {
00298 aStream << *iCa;
00299 aStream << *iCb;
00300 aStream << iTc;
00301 }
00302
00303
00304
00305
00306
00307
00308 void CClassA::InternalizeL(RReadStream& aStream)
00309 {
00310 aStream >> iBufferA;
00311 iXA = aStream.ReadInt32L();
00312 iYA = aStream.ReadUint32L();
00313 }
00314
00315
00316 void CClassA::ExternalizeL(RWriteStream& aStream)const
00317 {
00318 aStream << iBufferA;
00319 aStream.WriteInt32L(iXA);
00320 aStream.WriteUint32L(iYA);
00321 }
00322
00323
00324
00325
00326
00327
00328 void CClassB::InternalizeL(RReadStream& aStream)
00329 {
00330 aStream >> iBufferB;
00331 }
00332
00333
00334 void CClassB::ExternalizeL(RWriteStream& aStream) const
00335 {
00336 aStream << iBufferB;
00337 }
00338
00339
00340
00341
00342
00343
00344 void TClassC::ExternalizeL(RWriteStream& aStream) const
00345 {
00346 aStream.WriteReal64L(iZC);
00347 }
00348
00349
00350 void TClassC::InternalizeL(RReadStream& aStream)
00351 {
00352 iZC = aStream.ReadReal64L();
00353 }
00354
00355
00356
00357
00358
00359