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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #include "CommonStreamStore.h"
00052 #include <s32file.h>
00053
00054
00055
00056
00057
00058 LOCAL_C void doMakeAndStoreL(const TDesC& aName);
00059
00060
00061
00062 LOCAL_C void doRestoreL(const TDesC& aName);
00063
00064
00065 class CClassA;
00066 LOCAL_C void doShow(const TDesC& aHeading,const CClassA& anA);
00067
00068
00069 class CClassB;
00070 LOCAL_C void doShow(const TDesC& aHeading,const CClassB& aB);
00071
00072
00073 class CClassC;
00074 LOCAL_C void doShow(const TDesC& aHeading,const CClassC& aC);
00075
00076
00077 class CClassA : public CBase
00078 {
00079 public :
00080 static CClassA* NewLC();
00081 ~CClassA();
00082 void SetTextL(const TDesC& aData);
00083 void ExternalizeL(RWriteStream& aStream) const;
00084 void InternalizeL(RReadStream& aStream);
00085 public :
00086 HBufC* iVarBuffer;
00087 TInt iIntValue;
00088 TUint iUintValue;
00089 };
00090
00091
00092 class CClassB : public CBase
00093 {
00094 public :
00095 static CClassB* NewLC();
00096 void ExternalizeL(RWriteStream& aStream) const;
00097 void InternalizeL(RReadStream& aStream);
00098 public :
00099 TBuf<32> iFixBuffer;
00100 TUint iUintValue;
00101 TInt iIntValue;
00102 TReal iRealValue;
00103 };
00104
00105
00106
00107 #define KStdirectClassCGranularity 4
00108
00109 class CClassC : public CBase
00110 {
00111 public :
00112 static CClassC* NewLC();
00113 ~CClassC();
00114 void ConstructL();
00115 void AddNumberToArrayL(TInt aValue);
00116 void ExternalizeL(RWriteStream& aStream) const;
00117 void InternalizeL(RReadStream& aStream);
00118 public :
00119 TBuf<32> iFixBuffer;
00120 CArrayFixFlat<TInt>* iArray;
00121 };
00122
00123
00124
00125
00126 _LIT(KFullNameOfFileStore,"\\epoc32ex\\data\\WriteDirectFS.dat");
00127
00128
00129 LOCAL_C void doExampleL()
00130 {
00131
00132 fsSession.MkDirAll(KFullNameOfFileStore);
00133 doMakeAndStoreL(KFullNameOfFileStore);
00134 doRestoreL(KFullNameOfFileStore);
00135 }
00136
00137 LOCAL_C void doMakeAndStoreL(const TDesC& aName)
00138 {
00139
00140
00141 _LIT(KTxtForClassA,"Text for CClassA");
00142 CClassA* theA = CClassA::NewLC();
00143 theA->SetTextL(KTxtForClassA);
00144 theA->iIntValue = -1;
00145 theA->iUintValue = 2;
00146
00147
00148
00149 _LIT(KTxtForClassB,"Text for CClassB");
00150 CClassB* theB = CClassB::NewLC();
00151 theB->iFixBuffer = KTxtForClassB;
00152 theB->iIntValue = -3;
00153 theB->iUintValue = 4;
00154 theB->iRealValue = 5.6;
00155
00156
00157
00158 _LIT(KTxtForClassC,"Text for CClassC");
00159 CClassC* theC = CClassC::NewLC();
00160 theC->iFixBuffer = KTxtForClassC;
00161 theC->AddNumberToArrayL(21);
00162 theC->AddNumberToArrayL(42);
00163 theC->AddNumberToArrayL(101);
00164
00165
00166 _LIT(KTxtClassAContent,"CClassA content ...");
00167 doShow(KTxtClassAContent,*theA);
00168
00169
00170 _LIT(KTxtClassBContent,"CClassB content ...");
00171 doShow(KTxtClassBContent,*theB);
00172
00173
00174 _LIT(KTxtClassCContent,"CClassC content ...");
00175 doShow(KTxtClassCContent,*theC);
00176
00177
00178 TParse filestorename;
00179 fsSession.Parse(aName,filestorename);
00180 CFileStore* store = CDirectFileStore::ReplaceLC(fsSession,filestorename.FullName(),EFileWrite);
00181
00182
00183 store->SetTypeL(KDirectFileStoreLayoutUid);
00184
00185
00186 RStoreWriteStream outstream;
00187 TStreamId id = outstream.CreateLC(*store);
00188
00189
00190
00191 outstream << *theA << *theB << *theC;
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 outstream.CommitL();
00206
00207
00208 CleanupStack::PopAndDestroy();
00209
00210
00211 store->SetRootL(id);
00212
00213
00214 store->CommitL();
00215
00216
00217
00218
00219
00220 CleanupStack::PopAndDestroy(4);
00221 }
00222
00223 LOCAL_C void doRestoreL(const TDesC& aName)
00224 {
00225
00226 CClassA* theA = CClassA::NewLC();
00227 CClassB* theB = CClassB::NewLC();
00228 CClassC* theC = CClassC::NewLC();
00229
00230
00231 TParse filestorename;
00232 fsSession.Parse(aName,filestorename);
00233 CFileStore* store = CDirectFileStore::OpenLC(fsSession,filestorename.FullName(),EFileRead);
00234
00235
00236
00237 RStoreReadStream instream;
00238 instream.OpenLC(*store,store->Root());
00239
00240
00241
00242 instream >> *theA >> *theB >> *theC;
00243
00244
00245
00246
00247
00248
00249
00250
00251 CleanupStack::PopAndDestroy();
00252
00253
00254 _LIT(KTxtRestoredCClassA,"Restored CClassA content ...");
00255 doShow(KTxtRestoredCClassA,*theA);
00256
00257
00258 _LIT(KTxtRestoredCClassB,"Restored CClassB content ...");
00259 doShow(KTxtRestoredCClassB,*theB);
00260
00261
00262 _LIT(KTxtRestoredCClassC,"Restored CClassC content ...");
00263 doShow(KTxtRestoredCClassC,*theC);
00264
00265
00266
00267
00268
00269 CleanupStack::PopAndDestroy(4);
00270 }
00271
00272
00273 _LIT(KTxtNewLine,"\n");
00274 _LIT(KFormatType1,"\n%S, ");
00275 _LIT(KFormatType2,"%d, ");
00276 _LIT(KFormatType3,"%u ");
00277 _LIT(KFormatType4,"%u, ");
00278 _LIT(KFormatType5,"%f ");
00279
00280 LOCAL_C void doShow(const TDesC& aHeading,const CClassA& anA)
00281 {
00282 console->Printf(KTxtNewLine);
00283 console->Printf(aHeading);
00284 console->Printf(KFormatType1,anA.iVarBuffer);
00285 console->Printf(KFormatType2,anA.iIntValue);
00286 console->Printf(KFormatType3,anA.iUintValue);
00287 console->Printf(KTxtNewLine);
00288 }
00289
00290 LOCAL_C void doShow(const TDesC& aHeading,const CClassB& aB)
00291 {
00292 console->Printf(KTxtNewLine);
00293 console->Printf(aHeading);
00294 console->Printf(KFormatType1,&aB.iFixBuffer);
00295 console->Printf(KFormatType2,aB.iIntValue);
00296 console->Printf(KFormatType4,aB.iUintValue);
00297 console->Printf(KFormatType5,aB.iRealValue);
00298 console->Printf(KTxtNewLine);
00299 }
00300
00301 _LIT(KTxtNoArrayItems,"<No array items>");
00302 _LIT(KTxtColonsep,": ");
00303 _LIT(KTxtCommasep,", ");
00304 _LIT(KFormatType6,"%d array item(s)");
00305 _LIT(KFormatType7,"%S%d");
00306
00307 LOCAL_C void doShow(const TDesC& aHeading,const CClassC& aC)
00308 {
00309 console->Printf(KTxtNewLine);
00310 console->Printf(aHeading);
00311 console->Printf(KFormatType1,&aC.iFixBuffer);
00312
00313 TInt count = aC.iArray->Count();
00314 if (!count)
00315 console->Printf(KTxtNoArrayItems);
00316 else
00317 {
00318 TPtrC ptr;
00319 ptr.Set(KTxtColonsep);
00320 console->Printf(KFormatType6,count);
00321 for (TInt index = 0; index < count; index++)
00322 {
00323 console->Printf(KFormatType7,&ptr,(*aC.iArray)[index]);
00324 ptr.Set(KTxtCommasep);
00325 }
00326 }
00327 console->Printf(KTxtNewLine);
00328 }
00329
00330
00331
00332 CClassA* CClassA::NewLC()
00333 {
00334 CClassA* self = new (ELeave) CClassA;
00335 CleanupStack::PushL(self);
00336 return self;
00337 }
00338
00339 CClassA::~CClassA()
00340 {
00341 delete iVarBuffer;
00342 }
00343
00344 void CClassA::SetTextL(const TDesC& aData)
00345 {
00346 iVarBuffer = aData.AllocL();
00347 }
00348
00349 void CClassA::ExternalizeL(RWriteStream& aStream) const
00350 {
00351 aStream.WriteInt32L(iVarBuffer->Des().MaxLength());
00352 aStream << *iVarBuffer;
00353 aStream.WriteInt32L(iIntValue);
00354 aStream.WriteUint32L(iUintValue);
00355 }
00356
00357 void CClassA::InternalizeL(RReadStream& aStream)
00358 {
00359 TInt maxlen;
00360 maxlen = aStream.ReadInt32L();
00361 iVarBuffer = HBufC::NewL(aStream,maxlen);
00362 iIntValue = aStream.ReadInt32L();
00363 iUintValue = aStream.ReadUint32L();
00364 }
00365
00366
00367
00368
00369 CClassB* CClassB::NewLC()
00370 {
00371 CClassB* self = new (ELeave) CClassB;
00372 CleanupStack::PushL(self);
00373 return self;
00374 }
00375
00376 void CClassB::ExternalizeL(RWriteStream& aStream) const
00377 {
00378 aStream << iFixBuffer;
00379 aStream.WriteInt32L(iIntValue);
00380 aStream.WriteUint32L(iUintValue);
00381 aStream.WriteReal64L(iRealValue);
00382 }
00383
00384 void CClassB::InternalizeL(RReadStream& aStream)
00385 {
00386 aStream >> iFixBuffer;
00387 iIntValue = aStream.ReadInt32L();
00388 iUintValue = aStream.ReadUint32L();
00389 iRealValue = aStream.ReadReal64L();
00390 }
00391
00392
00393
00394
00395 CClassC* CClassC::NewLC()
00396 {
00397 CClassC* self = new (ELeave) CClassC;
00398 CleanupStack::PushL(self);
00399 self->ConstructL();
00400 return self;
00401 }
00402
00403 void CClassC::ConstructL()
00404 {
00405 iArray = new (ELeave) CArrayFixFlat<TInt>(KStdirectClassCGranularity);
00406 }
00407
00408 void CClassC::AddNumberToArrayL(TInt aValue)
00409 {
00410 iArray->AppendL(aValue);
00411 }
00412
00413 CClassC::~CClassC()
00414 {
00415 delete iArray;
00416 }
00417
00418 void CClassC::ExternalizeL(RWriteStream& aStream) const
00419 {
00420 aStream << iFixBuffer;
00421
00422 TInt count;
00423 count = iArray->Count();
00424 aStream.WriteInt32L(count);
00425 for (TInt index = 0; index < count; index++)
00426 aStream.WriteInt32L((*iArray)[index]);
00427 }
00428
00429 void CClassC::InternalizeL(RReadStream& aStream)
00430 {
00431 aStream >> iFixBuffer;
00432
00433 TInt count;
00434 count = aStream.ReadInt32L();
00435
00436 for (TInt index = 0; index < count; index++)
00437 iArray->AppendL(aStream.ReadInt32L());
00438 }
00439
00440
00441
00442
00443
00444
00445
00446