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