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
00052
00053
00054
00055
00056
00057
00058
00059
00060 #include "WriteToMany.h"
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 _LIT(KFullNameOfFileStore,"\\epoc32ex\\data\\WriteToMany.dat");
00072
00073
00074
00075 static void doExampleL()
00076 {
00077
00078 fsSession.MkDirAll(KFullNameOfFileStore);
00079 doMakeAndStoreL(KFullNameOfFileStore);
00080 doRestoreL(KFullNameOfFileStore);
00081 }
00082
00083
00084 static void doMakeAndStoreL(const TDesC& aName)
00085 {
00086
00087 TParse filestorename;
00088 fsSession.Parse(aName,filestorename);
00089 CFileStore* store = CDirectFileStore::ReplaceLC(fsSession,filestorename.FullName(),EFileWrite);
00090
00091
00092 store->SetTypeL(KDirectFileStoreLayoutUid);
00093
00094
00095
00096
00097 _LIT(KTxtDataForClassA,"Data for the CClassA - AAAAA");
00098 _LIT(KTxtDataForClassB,"Data for the CClassB - BBBBB");
00099 _LIT(KTxtDataForClassC,"Data for the CClassC - CCCCC");
00100
00101 CClassABC* theABC = CClassABC::NewLC(*store);
00102 theABC->ConstructAL(KTxtDataForClassA,-1,2);
00103 theABC->ConstructB(KTxtDataForClassB,-3,4,5.6);
00104 theABC->ConstructC(KTxtDataForClassC);
00105
00106
00107 _LIT(KTxtClassAContent,"CClassA content ...");
00108 _LIT(KTxtClassBContent,"CClassB content ...");
00109 _LIT(KTxtClassCContent,"CClassC content ...");
00110
00111 doShow(KTxtClassAContent,*theABC->PtrA());
00112 doShow(KTxtClassBContent,*theABC->PtrBL());
00113 doShow(KTxtClassCContent,*theABC->PtrC());
00114
00115
00116
00117
00118
00119
00120
00121
00122 TStreamId id = theABC->StoreL();
00123
00124
00125 store->SetRootL(id);
00126
00127
00128
00129
00130
00131 CleanupStack::PopAndDestroy(2);
00132 }
00133
00134
00135 static void doRestoreL(const TDesC& aName)
00136 {
00137
00138 TParse filestorename;
00139 fsSession.Parse(aName,filestorename);
00140 CFileStore* store = CDirectFileStore::OpenLC(fsSession,filestorename.FullName(),EFileRead);
00141
00142
00143
00144
00145
00146
00147
00148
00149 CClassABC* theABC = CClassABC::NewLC(*store,store->Root());
00150
00151
00152
00153
00154 _LIT(KTxtRestoredClassA,"Restored CClassA content ...");
00155 _LIT(KTxtRestoredClassB,"Restored CClassB content ...");
00156 _LIT(KTxtRestoredClassC,"Restored CClassC content ...");
00157
00158 doShow(KTxtRestoredClassA,*theABC->PtrA());
00159 doShow(KTxtRestoredClassB,*theABC->PtrBL());
00160 doShow(KTxtRestoredClassC,*theABC->PtrC());
00161
00162
00163
00164
00165 CleanupStack::PopAndDestroy(2);
00166 }
00167
00168 _LIT(KTxtNewLine,"\n");
00169 _LIT(KFormatType1,"\n%S, ");
00170 _LIT(KFormatType2,"%d, ");
00171 _LIT(KFormatType3,"%u ");
00172 _LIT(KFormatType4,"%u, ");
00173 _LIT(KFormatType5,"%f ");
00174
00175 static void doShow(const TDesC& aHeading,const CClassA& anA)
00176 {
00177 console->Printf(KTxtNewLine);
00178 console->Printf(aHeading);
00179 console->Printf(KFormatType1,anA.iVarBuf);
00180 console->Printf(KFormatType2,anA.iIntValue);
00181 console->Printf(KFormatType3,anA.iUintValue);
00182 console->Printf(KTxtNewLine);
00183 }
00184
00185
00186
00187 static void doShow(const TDesC& aHeading,const CClassB& aB)
00188 {
00189 console->Printf(KTxtNewLine);
00190 console->Printf(aHeading);
00191 console->Printf(KFormatType1,&aB.iFixBuf);
00192 console->Printf(KFormatType2,aB.iIntValue);
00193 console->Printf(KFormatType4,aB.iUintValue);
00194 console->Printf(KFormatType5,aB.iRealValue);
00195 console->Printf(KTxtNewLine);
00196 }
00197
00198 static void doShow(const TDesC& aHeading,const CClassC& aC)
00199 {
00200 console->Printf(KTxtNewLine);
00201 console->Printf(aHeading);
00202 console->Printf(KFormatType1,&aC.iFixBuf);
00203 console->Printf(KTxtNewLine);
00204 }
00205
00206
00207
00208
00209
00210
00211
00212 CClassABC::CClassABC(CStreamStore& aStore)
00213 : iStore(aStore)
00214 {}
00215
00216 CClassABC::CClassABC(CStreamStore& aStore,TStreamId anId)
00217 : iStore(aStore), iId(anId)
00218 {}
00219
00220 CClassABC* CClassABC::NewLC(CStreamStore& aStore)
00221 {
00222 CClassABC* self = new (ELeave) CClassABC(aStore);
00223 CleanupStack::PushL(self);
00224 self->ConstructL();
00225 return self;
00226 }
00227
00228 CClassABC* CClassABC::NewLC(CStreamStore& aStore, TStreamId anId)
00229 {
00230 CClassABC* self = new (ELeave) CClassABC(aStore,anId);
00231 CleanupStack::PushL(self);
00232 self->RestoreL();
00233 return self;
00234 }
00235
00236 void CClassABC::ConstructL()
00237 {
00238 iA = CClassA::NewL();
00239 iB = CClassB::NewL();
00240 iC = CClassC::NewL();
00241 }
00242
00243 void CClassABC::ConstructAL(const TDesC& aData,TInt anInt,TUint aUint)
00244 {
00245 iA->iVarBuf = aData.AllocL();
00246 iA->iIntValue = anInt;
00247 iA->iUintValue = aUint;
00248 }
00249
00250 void CClassABC::ConstructB(const TDesC& aData,TInt anInt,TUint aUint,TReal aReal)
00251 {
00252 iB->iFixBuf = aData;
00253 iB->iIntValue = anInt;
00254 iB->iUintValue = aUint;
00255 iB->iRealValue = aReal;
00256 }
00257
00258 void CClassABC::ConstructC(const TDesC& aData)
00259 {
00260 iC->iFixBuf = aData;
00261 }
00262
00263
00264
00265
00266
00267
00268
00269 CClassABC::~CClassABC()
00270 {
00271 delete iA;
00272 delete iC;
00273 if (iB.IsPtr())
00274 delete iB.AsPtr();
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 TStreamId CClassABC::StoreL()
00288 {
00289
00290
00291 RStoreWriteStream outstream;
00292 TStreamId idForB = outstream.CreateLC(iStore);
00293
00294
00295
00296 outstream << *iB;
00297
00298 outstream.CommitL();
00299
00300 CleanupStack::PopAndDestroy();
00301
00302
00303
00304
00305
00306 TStreamId id = outstream.CreateLC(iStore);
00307
00308 outstream << *iA;
00309
00310 outstream << idForB;
00311
00312 outstream << *iC;
00313
00314 outstream.CommitL();
00315
00316 CleanupStack::PopAndDestroy();
00317
00318 return id;
00319 }
00320
00321
00322 const CClassA* CClassABC::PtrA()
00323 {
00324 return iA;
00325 }
00326
00327
00328 const CClassB* CClassABC::PtrBL()
00329 {
00330 if (iB.IsId())
00331 RestoreBL();
00332 return iB.AsPtr();
00333 }
00334
00335
00336 const CClassC* CClassABC::PtrC()
00337 {
00338 return iC;
00339 }
00340
00341
00342
00343
00344
00345
00346
00347
00348 void CClassABC::RestoreL()
00349 {
00350
00351 RStoreReadStream instream;
00352 instream.OpenLC(iStore,iId);
00353
00354 iA = CClassA::NewL();
00355 instream >> *iA;
00356
00357
00358
00359
00360
00361
00362 instream >> iB;
00363
00364 iC = CClassC::NewL();
00365 instream >> *iC;
00366
00367 CleanupStack::PopAndDestroy();
00368 }
00369
00370
00371
00372
00373
00374
00375 void CClassABC::RestoreBL()
00376 {
00377
00378
00379 RStoreReadStream instream;
00380 instream.OpenLC(iStore,iB.AsId());
00381
00382
00383
00384
00385 CClassB* ptrB = CClassB::NewLC();
00386 instream >> *ptrB;
00387 CleanupStack::Pop();
00388 iB = ptrB;
00389
00390 CleanupStack::PopAndDestroy();
00391 }
00392
00393
00394
00395
00396
00397
00398 CClassA* CClassA::NewL()
00399 {
00400 CClassA* self = CClassA::NewLC();
00401 CleanupStack::Pop();
00402 return self;
00403 }
00404
00405 CClassA* CClassA::NewLC()
00406 {
00407 CClassA* self = new (ELeave) CClassA;
00408 CleanupStack::PushL(self);
00409 return self;
00410 }
00411
00412 CClassA::~CClassA()
00413 {
00414 delete iVarBuf;
00415 }
00416
00417 void CClassA::ExternalizeL(RWriteStream& aStream) const
00418 {
00419 aStream.WriteInt32L(iVarBuf->Des().MaxLength());
00420 aStream << *iVarBuf;
00421 aStream.WriteInt32L(iIntValue);
00422 aStream.WriteUint32L(iUintValue);
00423 }
00424
00425 void CClassA::InternalizeL(RReadStream& aStream)
00426 {
00427 TInt maxlen;
00428 maxlen = aStream.ReadInt32L();
00429 iVarBuf = HBufC::NewL(aStream,maxlen);
00430 iIntValue = aStream.ReadInt32L();
00431 iUintValue = aStream.ReadUint32L();
00432 }
00433
00434
00435
00436
00437
00438
00439
00440 CClassB* CClassB::NewLC()
00441 {
00442 CClassB* self = new (ELeave) CClassB;
00443 CleanupStack::PushL(self);
00444 return self;
00445 }
00446
00447 CClassB* CClassB::NewL()
00448 {
00449 CClassB* self = CClassB::NewLC();
00450 CleanupStack::Pop();
00451 return self;
00452 }
00453
00454 void CClassB::ExternalizeL(RWriteStream& aStream) const
00455 {
00456 aStream << iFixBuf;
00457 aStream.WriteInt32L(iIntValue);
00458 aStream.WriteUint32L(iUintValue);
00459 aStream.WriteReal64L(iRealValue);
00460 }
00461
00462 void CClassB::InternalizeL(RReadStream& aStream)
00463 {
00464 aStream >> iFixBuf;
00465 iIntValue = aStream.ReadInt32L();
00466 iUintValue = aStream.ReadUint32L();
00467 iRealValue = aStream.ReadReal64L();
00468 }
00469
00470
00471
00472
00473
00474
00475 CClassC* CClassC::NewL()
00476 {
00477 CClassC* self = CClassC::NewLC();
00478 CleanupStack::Pop();
00479 return self;
00480 }
00481
00482 CClassC* CClassC::NewLC()
00483 {
00484 CClassC* self = new (ELeave) CClassC;
00485 CleanupStack::PushL(self);
00486 return self;
00487 }
00488
00489 void CClassC::ExternalizeL(RWriteStream& aStream) const
00490 {
00491 aStream << iFixBuf;
00492 }
00493
00494 void CClassC::InternalizeL(RReadStream& aStream)
00495 {
00496 aStream >> iFixBuf;
00497 }