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