00001 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). 00002 // All rights reserved. 00003 // This component and the accompanying materials are made available 00004 // under the terms of "Eclipse Public License v1.0" 00005 // which accompanies this distribution, and is available 00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html". 00007 // 00008 // Initial Contributors: 00009 // Nokia Corporation - initial contribution. 00010 // 00011 // Contributors: 00012 // 00013 // Description: 00014 // Example constructs and writes a network of objects to a permanent file store. 00015 // Each object is then loaded back in, one at a time, its content displayed at the 00016 // console and then destroyed. 00017 // The CClassR object is changed and stored back before it is destroyed 00018 // The order in which the objects are loaded from the store is different from the order 00019 // in which they were initially created. 00020 // The example creates an index of "top level" stream ids. The index is stored in its 00021 // own stream and forms the root stream of the store. 00022 // The example: 00023 // creates a permanent file store (replacing any existing permanent 00024 // file store of the same name) 00025 // constructs a TExampleIndex object 00026 // constructs a CClassP object, externalizes it in its own stream, 00027 // saves the stream id in the index and then destroys the 00028 // CClassP object 00029 // constructs a CClassR object, externalizes it in its own stream, 00030 // saves the stream id in the index and then destroys the 00031 // CClassR object 00032 // constructs a CClassABC container object containing a CClassA, 00033 // a CClassB and a CClassC object and then completes the construction 00034 // of these contained objects. 00035 // The CClassB object is externalized in its own stream. The CClassA, the streamid of the 00036 // CClassB object and the CClassC object are externalized in a single 00037 // stream and this streamid is saved into the index 00038 // externalizes the TExampleIndex object in its own stream and makes 00039 // this stream the root stream of the file store. 00040 // closes the permanent file store. 00041 // re-opens the permanent file store 00042 // restores the TExampleIndex object from the root stream 00043 // restores the CClassR object from its stream, displays the content, 00044 // changes the content, replaces the stream and then destroys the object from 00045 // memory 00046 // restores the CClassR object for a second time from its stream, displays 00047 // the (updated) content and then destroys the object from memory again 00048 // restores the CClassABC container object; in effect, this restores 00049 // its contained CClassA and CClassC objects and the stream id of its 00050 // CClassB object. The CClassB object is not restored into memory until 00051 // it is needed. 00052 // displays the content of the CClassA, CClassB and CClassC objects; it is 00053 // at this time that the CClassB object is restored into memory. 00054 // restores the CClassP object from its stream and displays its contents 00055 // and then destroys it 00056 // (NB that the order in which the objects are restored is different to 00057 // the order in which their corresponding streams were created) 00058 // closes the permanent file store. 00059 // Notes: 00060 // The file name and extension of the permanent file store is 00061 // "WritePermFS.dat"and will be created in "\epoc32ex\data\" on the system drive. 00062 // 00063 00064 #include "WritePermFS1.h" 00065 00066 //*************************************************************** 00067 // 00068 // Implementations 00069 // 00070 //*************************************************************** 00071 00072 00073 // The file name, extension and path for the file store 00074 _LIT(KFullNameOfFileStore,"\\epoc32ex\\data\\WritePermFS.dat"); 00075 00076 // Do the example 00077 LOCAL_C void doExampleL() 00078 { 00079 // make sure directory exists 00080 fsSession.MkDirAll(KFullNameOfFileStore); 00081 doMakeL(KFullNameOfFileStore); 00082 doUseL(KFullNameOfFileStore); 00083 } 00084 00085 00086 LOCAL_C void doMakeL(const TDesC& aName) 00087 { 00088 // Create (replace, if it exists) the permanent file store 00089 TParse filestorename; 00090 fsSession.Parse(aName,filestorename); 00091 CFileStore* store = CPermanentFileStore::ReplaceLC(fsSession,filestorename.FullName(),EFileWrite); 00092 00093 // Must say what kind of file store. 00094 store->SetTypeL(KPermanentFileStoreLayoutUid); 00095 00096 // Create a TExampleIndex object to hold the stream ids of all 00097 // the component streams 00098 TExampleIndex theIndex; 00099 00100 // Construct the CClassP object, putting some data into it, 00101 // write it to its own stream and save the stream id in 00102 // the index. 00103 // Destroy the CClassP object after stream creation 00104 _LIT(KTxtDataForClassP,"Data for CClassP - PPPPP"); 00105 CClassP* theP = CClassP::NewLC(KTxtDataForClassP,*store); 00106 theIndex.iPid = theP->StoreL(); 00107 CleanupStack::PopAndDestroy(); 00108 00109 // Construct the CClassR object, put some data into it, 00110 // write it to its own stream and save the stream id in 00111 // the index. 00112 // Destroy the CClassR object after stream creation 00113 _LIT(KTxtDataForClassR,"Data for the CClassR - RRRRR"); 00114 CClassR* theR = CClassR::NewLC(KTxtDataForClassR,*store); 00115 theIndex.iRid = theR->StoreL(); 00116 CleanupStack::PopAndDestroy(); 00117 00118 // Construct the container object for CClassA,CClassB and CClassC. 00119 // Complete the construction of the contained CClassA, CClassB 00120 // and CClassC objects. 00121 // 00122 // Write out this object network and save the top level stream id 00123 // in the index. 00124 // Destroy this object network after stream creation 00125 _LIT(KTxtDataForClassA,"Data for the CClassA - AAAAA"); 00126 _LIT(KTxtDataForClassB,"Data for the CClassB - BBBBB"); 00127 _LIT(KTxtDataForClassC,"Data for the CClassC - CCCCC"); 00128 00129 CClassABC* theABC = CClassABC::NewLC(*store); 00130 theABC->ConstructAL(KTxtDataForClassA,-1,2); 00131 theABC->ConstructB(KTxtDataForClassB,-3,4,5.6); 00132 theABC->ConstructC(KTxtDataForClassC); 00133 theIndex.iABCid = theABC->StoreL(); 00134 CleanupStack::PopAndDestroy(); 00135 00136 // Now write the index itself to its own stream ... 00137 TStreamId id = theIndex.StoreL(*store); 00138 00139 // ... and make this stream the root stream 00140 store->SetRootL(id); 00141 00142 // Now commit all changes to the store 00143 store->CommitL(); 00144 00145 // Destroy the permanent file store object (closes the file) 00146 CleanupStack::PopAndDestroy(); 00147 } 00148 00149 00150 LOCAL_C void doUseL(const TDesC& aName) 00151 { 00152 // Open the permanent file store 00153 TParse filestorename; 00154 fsSession.Parse(aName,filestorename); 00155 CFileStore* store = CPermanentFileStore::OpenLC(fsSession,filestorename.FullName(),EFileRead|EFileWrite); 00156 00157 // Restore the index of streamids so that we can access (restore) 00158 // all the other objects. The index is found in the root stream 00159 TExampleIndex theIndex; 00160 theIndex.RestoreL(*store,store->Root()); 00161 00162 // Restore the CClassR object, display the content, make a change and 00163 // update the stream to reflect the changed content. 00164 // If updating the stream succeeds, commit the changes to the store 00165 // otherwise attempt to revert the store to its state at the last 00166 // commit point. 00167 // Destroy the CClassR object. 00168 CClassR* theR; 00169 00170 _LIT(KTxtClassRContent,"CClassR content ..."); 00171 _LIT(KTxtNewForClassR,"New data for the CClassR +++++++"); 00172 00173 theR = CClassR::NewLC(*store,theIndex.iRid); 00174 doShow(KTxtClassRContent,*theR); 00175 theR->ChangeDataL(KTxtNewForClassR); 00176 CleanupStack::PopAndDestroy(); 00177 00178 // Restore the CClassR object again, display the content and 00179 // then destroy it 00180 _LIT(KTxtUpadtedClassR,"Updated CClassR content ..."); 00181 00182 theR = CClassR::NewLC(*store,theIndex.iRid); 00183 doShow(KTxtUpadtedClassR,*theR); 00184 CleanupStack::PopAndDestroy(); 00185 00186 // Restore the CClassABC and display content of all contained objects. 00187 // Note that the loading of the CClassB object is deferred until it 00188 // is needed. 00189 // Destroy the CClassABC 00190 _LIT(KTxtShowClassA,"CClassA content ..."); 00191 _LIT(KTxtShowClassB,"CClassB content ..."); 00192 _LIT(KTxtShowClassC,"CClassC content ..."); 00193 00194 CClassABC* theABC = CClassABC::NewLC(*store,theIndex.iABCid); 00195 doShow(KTxtShowClassA,*theABC->PtrA()); 00196 doShow(KTxtShowClassB,*theABC->PtrBL());// CClassB object is loaded at this point 00197 doShow(KTxtShowClassC,*theABC->PtrC()); 00198 CleanupStack::PopAndDestroy(); 00199 00200 // Restore the CClassP object, display the content and 00201 // then destroy it; 00202 _LIT(KTxtShowClassP,"CClassP content ..."); 00203 00204 CClassP* theP = CClassP::NewLC(*store,theIndex.iPid); 00205 doShow(KTxtShowClassP,*theP); 00206 CleanupStack::PopAndDestroy(); 00207 00208 // Destroy the permanent file store object (closes the file) 00209 CleanupStack::PopAndDestroy(); 00210 } 00211 00212 _LIT(KTxtNewLine,"\n"); 00213 _LIT(KFormatType1,"\n%S, "); 00214 _LIT(KFormatType2,"%d, "); 00215 _LIT(KFormatType3,"%u "); 00216 _LIT(KFormatType4,"%u, "); 00217 _LIT(KFormatType5,"%f "); 00218 00219 LOCAL_C void doShow(const TDesC& aHeading,const CClassA& anA) 00220 { 00221 console->Printf(KTxtNewLine); 00222 console->Printf(aHeading); 00223 console->Printf(KFormatType1,anA.iVarBuf); 00224 console->Printf(KFormatType2,anA.iIntValue); 00225 console->Printf(KFormatType3,anA.iUintValue); 00226 console->Printf(KTxtNewLine); 00227 } 00228 00229 00230 LOCAL_C void doShow(const TDesC& aHeading,const CClassB& aB) 00231 { 00232 console->Printf(KTxtNewLine); 00233 console->Printf(aHeading); 00234 console->Printf(KFormatType1,&aB.iFixBuf); 00235 console->Printf(KFormatType2,aB.iIntValue); 00236 console->Printf(KFormatType4,aB.iUintValue); 00237 console->Printf(KFormatType5,aB.iRealValue); 00238 console->Printf(KTxtNewLine); 00239 } 00240 00241 00242 LOCAL_C void doShow(const TDesC& aHeading,const CClassC& aC) 00243 { 00244 console->Printf(KTxtNewLine); 00245 console->Printf(aHeading); 00246 console->Printf(KFormatType1,&aC.iFixBuf); 00247 console->Printf(KTxtNewLine); 00248 } 00249 00250 LOCAL_C void doShow(const TDesC& aHeading,const CClassP& aP) 00251 { 00252 console->Printf(KTxtNewLine); 00253 console->Printf(aHeading); 00254 console->Printf(KFormatType1,&aP.iFixBuf); 00255 console->Printf(KTxtNewLine); 00256 } 00257 00258 LOCAL_C void doShow(const TDesC& aHeading,const CClassR& aR) 00259 { 00260 console->Printf(KTxtNewLine); 00261 console->Printf(aHeading); 00262 console->Printf(KFormatType1,&aR.iFixBuf); 00263 console->Printf(KTxtNewLine); 00264 } 00265 00266 //*************************************************************** 00267 // 00268 // CClassABC Implementation 00269 // 00270 //*************************************************************** 00271 CClassABC::CClassABC(CStreamStore& aStore) 00272 : iStore(aStore) 00273 {} 00274 00275 CClassABC::CClassABC(CStreamStore& aStore,TStreamId anId) 00276 : iStore(aStore), iId(anId) 00277 {} 00278 00279 CClassABC* CClassABC::NewLC(CStreamStore& aStore) 00280 { 00281 CClassABC* self = new (ELeave) CClassABC(aStore); 00282 CleanupStack::PushL(self); 00283 self->ConstructL(); 00284 return self; 00285 } 00286 00287 CClassABC* CClassABC::NewLC(CStreamStore& aStore, TStreamId anId) 00288 { 00289 CClassABC* self = new (ELeave) CClassABC(aStore,anId); 00290 CleanupStack::PushL(self); 00291 self->RestoreL(); 00292 return self; 00293 } 00294 00295 void CClassABC::ConstructL() 00296 { 00297 iA = CClassA::NewL(); 00298 iB = CClassB::NewL();// assigns CClassB* to TSwizzle<CClassB>. Uses TSwizzle operator=(T*) 00299 iC = CClassC::NewL(); 00300 } 00301 00302 void CClassABC::ConstructAL(const TDesC& aData,TInt anInt,TUint aUint) 00303 { 00304 iA->iVarBuf = aData.AllocL(); 00305 iA->iIntValue = anInt; 00306 iA->iUintValue = aUint; 00307 } 00308 00309 void CClassABC::ConstructB(const TDesC& aData,TInt anInt,TUint aUint,TReal aReal) 00310 { 00311 iB->iFixBuf = aData; 00312 iB->iIntValue = anInt; 00313 iB->iUintValue = aUint; 00314 iB->iRealValue = aReal; 00315 } 00316 00317 void CClassABC::ConstructC(const TDesC& aData) 00318 { 00319 iC->iFixBuf = aData; 00320 } 00321 00322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00323 // Destructor deletes the CClassB object only if it is in memory. 00324 // The IsPtr() function can be used to determine whether the 00325 // CClassB object is memory. 00326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00327 CClassABC::~CClassABC() 00328 { 00329 delete iA; 00330 delete iC; 00331 if (iB.IsPtr()) 00332 delete iB.AsPtr(); // can also "delete iB;" makes implicit call to "operator T*()" 00333 } 00334 00335 00336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00337 // Stores the CClassB object in its own stream and 00338 // then stores: 00339 // the CClassA object, 00340 // the streamid of the CClassB object, 00341 // the CClassC object 00342 // in a separate stream. 00343 // Returns the streamid of this last stream 00344 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00345 TStreamId CClassABC::StoreL() 00346 { 00347 // Construct the output stream which is intended 00348 // to hold the CClassB object only. 00349 RStoreWriteStream outstream; 00350 TStreamId idForB = outstream.CreateLC(iStore); 00351 // Stream out the CClassB object. 00352 // Note that the right hand side returns a reference 00353 // to CClassB 00354 outstream << *iB; 00355 // Commit changes to the stream 00356 outstream.CommitL(); 00357 // Cleanup the stream object 00358 CleanupStack::PopAndDestroy(); 00359 // Now construct the output stream which is intended 00360 // to hold: 00361 // the CClassA object, 00362 // the streamid of the CClassB object, 00363 // the CClassC object 00364 TStreamId id = outstream.CreateLC(iStore); 00365 // Write out the CClassA object. 00366 outstream << *iA; 00367 // Write out the stream id of the CClassB object 00368 outstream << idForB; 00369 // Write out the CClassC object. 00370 outstream << *iC; 00371 // Commit changes to the stream 00372 outstream.CommitL(); 00373 // Cleanup the stream object, 00374 CleanupStack::PopAndDestroy(); 00375 // Return this stream id 00376 return id; 00377 } 00378 00379 00380 const CClassA* CClassABC::PtrA() 00381 { 00382 return iA; // Return a pointer to the contained CClassA object 00383 } 00384 00385 00386 const CClassB* CClassABC::PtrBL() 00387 { 00388 if (iB.IsId()) // If the contained CClassB object is not in memory, it must 00389 RestoreBL(); // be loaded in before a pointer can be returned to the caller 00390 return iB.AsPtr(); 00391 } 00392 00393 00394 const CClassC* CClassABC::PtrC() 00395 { 00396 return iC; //Returns a pointer to the contained CClassC object 00397 } 00398 00399 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00400 // Restores the CClassA and CClassC objects and the streamid for the 00401 // CClassB object. 00402 // The swizzle for the CClassB object is constructed from the 00403 // streamid but the CClassB object itself is NOT restored at 00404 // this time. 00405 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00406 void CClassABC::RestoreL() 00407 { 00408 // Construct the input stream. 00409 RStoreReadStream instream; 00410 instream.OpenLC(iStore,iId); 00411 // Construct a CClassA object and restore from the stream 00412 iA = CClassA::NewL(); 00413 instream >> *iA; 00414 // Construct the swizzle for the CClassB object. This 00415 // stream contains the id of the stream which 00416 // actually contains the full CClassB object. The loading of 00417 // the CClassB object into memory is deferred until later. 00418 // The resulting swizzle represents the CClassB object as 00419 // a streamid 00420 instream >> iB; 00421 // Construct a CClassC object and restrore from the stream 00422 iC = CClassC::NewL(); 00423 instream >> *iC; 00424 // Cleanup the stream object 00425 CleanupStack::PopAndDestroy(); 00426 } 00427 00428 00429 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00430 // Loads the CClassB object into memory and changes the swizzle's 00431 // representation from "streamid" to "pointer". 00432 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00433 void CClassABC::RestoreBL() 00434 { 00435 // Construct the input stream. Assumes we have the correct store (this 00436 // emphasizes the need to ensure that the store remain open) 00437 RStoreReadStream instream; 00438 instream.OpenLC(iStore,iB.AsId()); 00439 // Construct a CClassB object and restore from the stream. The 00440 // assignment: CClassB* to TSwizzle<CClassB> changes the 00441 // swizzle's representation of the CClassB object 00442 // from "streamid" to "pointer" 00443 CClassB* ptrB = CClassB::NewLC(); 00444 instream >> *ptrB; 00445 CleanupStack::Pop(); 00446 iB = ptrB; 00447 // Cleanup the stream object 00448 CleanupStack::PopAndDestroy(); 00449 } 00450 00451 00452 //*************************************************************** 00453 // 00454 // CClassA Implementation 00455 // 00456 //*************************************************************** 00457 CClassA* CClassA::NewL() 00458 { 00459 CClassA* self = CClassA::NewLC(); 00460 CleanupStack::Pop(); 00461 return self; 00462 } 00463 00464 CClassA* CClassA::NewLC() 00465 { 00466 CClassA* self = new (ELeave) CClassA; 00467 CleanupStack::PushL(self); 00468 return self; 00469 } 00470 00471 CClassA::~CClassA() 00472 { 00473 delete iVarBuf; 00474 } 00475 00476 void CClassA::ExternalizeL(RWriteStream& aStream) const 00477 { 00478 aStream.WriteInt32L(iVarBuf->Des().MaxLength()); 00479 aStream << *iVarBuf; 00480 aStream.WriteInt32L(iIntValue); 00481 aStream.WriteUint32L(iUintValue); 00482 } 00483 00484 void CClassA::InternalizeL(RReadStream& aStream) 00485 { 00486 TInt maxlen; 00487 maxlen = aStream.ReadInt32L(); 00488 iVarBuf = HBufC::NewL(aStream,maxlen); 00489 iIntValue = aStream.ReadInt32L(); 00490 iUintValue = aStream.ReadUint32L(); 00491 } 00492 00493 00494 //*************************************************************** 00495 // 00496 // CClassB Implementation 00497 // 00498 //*************************************************************** 00499 CClassB* CClassB::NewLC() 00500 { 00501 CClassB* self = new (ELeave) CClassB; 00502 CleanupStack::PushL(self); 00503 return self; 00504 } 00505 00506 CClassB* CClassB::NewL() 00507 { 00508 CClassB* self = CClassB::NewLC(); 00509 CleanupStack::Pop(); 00510 return self; 00511 } 00512 00513 void CClassB::ExternalizeL(RWriteStream& aStream) const 00514 { 00515 aStream << iFixBuf; 00516 aStream.WriteInt32L(iIntValue); 00517 aStream.WriteUint32L(iUintValue); 00518 aStream.WriteReal64L(iRealValue); 00519 } 00520 00521 void CClassB::InternalizeL(RReadStream& aStream) 00522 { 00523 aStream >> iFixBuf; 00524 iIntValue = aStream.ReadInt32L(); 00525 iUintValue = aStream.ReadUint32L(); 00526 iRealValue = aStream.ReadReal64L(); 00527 } 00528 00529 //*************************************************************** 00530 // 00531 // CClassC Implementation 00532 // 00533 //*************************************************************** 00534 CClassC* CClassC::NewL() 00535 { 00536 CClassC* self = CClassC::NewLC(); 00537 CleanupStack::Pop(); 00538 return self; 00539 } 00540 00541 CClassC* CClassC::NewLC() 00542 { 00543 CClassC* self = new (ELeave) CClassC; 00544 CleanupStack::PushL(self); 00545 return self; 00546 } 00547 00548 void CClassC::ExternalizeL(RWriteStream& aStream) const 00549 { 00550 aStream << iFixBuf; 00551 } 00552 00553 void CClassC::InternalizeL(RReadStream& aStream) 00554 { 00555 aStream >> iFixBuf; 00556 } 00557 00558 //*************************************************************** 00559 // 00560 // CClassP Implementation 00561 // 00562 //*************************************************************** 00563 CClassP::CClassP(CStreamStore& aStore) 00564 : iStore(aStore) 00565 {} 00566 00567 CClassP::CClassP(CStreamStore& aStore,TStreamId anId) 00568 : iStore(aStore), iId(anId) 00569 {} 00570 00571 CClassP* CClassP::NewLC(const TDesC& aData,CStreamStore& aStore) 00572 { 00573 CClassP* self = new (ELeave) CClassP(aStore); 00574 CleanupStack::PushL(self); 00575 self->Construct(aData); 00576 return self; 00577 } 00578 00579 CClassP* CClassP::NewLC(CStreamStore& aStore, TStreamId anId) 00580 { 00581 CClassP* self = new (ELeave) CClassP(aStore,anId); 00582 CleanupStack::PushL(self); 00583 self->RestoreL(); 00584 return self; 00585 } 00586 00587 void CClassP::Construct(const TDesC& aData) 00588 { 00589 iFixBuf = aData; 00590 } 00591 00592 void CClassP::RestoreL() 00593 { 00594 RStoreReadStream instream; 00595 instream.OpenLC(iStore,iId); 00596 InternalizeL(instream); // or we can say instream >> *this; 00597 CleanupStack::PopAndDestroy(); 00598 } 00599 00600 TStreamId CClassP::StoreL() 00601 { 00602 RStoreWriteStream outstream; 00603 TStreamId id = outstream.CreateLC(iStore); 00604 ExternalizeL(outstream); // or we can say outstream << *this; 00605 outstream.CommitL(); 00606 CleanupStack::PopAndDestroy(); 00607 return id; 00608 } 00609 00610 void CClassP::ExternalizeL(RWriteStream& aStream) const 00611 { 00612 aStream << iFixBuf; 00613 } 00614 00615 void CClassP::InternalizeL(RReadStream& aStream) 00616 { 00617 aStream >> iFixBuf; 00618 } 00619 00620 00621 //*************************************************************** 00622 // 00623 // CClassR Implementation 00624 // 00625 //*************************************************************** 00626 CClassR::CClassR(CStreamStore& aStore) 00627 : iStore(aStore) 00628 {} 00629 00630 CClassR::CClassR(CStreamStore& aStore,TStreamId anId) 00631 : iStore(aStore), iId(anId) 00632 {} 00633 00634 CClassR* CClassR::NewLC(const TDesC& aData,CStreamStore& aStore) 00635 { 00636 CClassR* self = new (ELeave) CClassR(aStore); 00637 CleanupStack::PushL(self); 00638 self->Construct(aData); 00639 return self; 00640 } 00641 00642 CClassR* CClassR::NewLC(CStreamStore& aStore, TStreamId anId) 00643 { 00644 CClassR* self = new (ELeave) CClassR(aStore,anId); 00645 CleanupStack::PushL(self); 00646 self->RestoreL(); 00647 return self; 00648 } 00649 00650 void CClassR::Construct(const TDesC& aData) 00651 { 00652 iFixBuf = aData; 00653 } 00654 00655 _LIT(KTxtFailedMsg,"Failed to update CClassR stream\n"); 00656 00657 void CClassR::ChangeDataL(const TDesC& aData) 00658 { 00659 iFixBuf = aData; 00660 TRAPD(error,UpdateStoreL()); 00661 if (error!=KErrNone) 00662 { 00663 iStore.Revert(); 00664 console->Printf(KTxtFailedMsg); 00665 User::Leave(error); 00666 } 00667 } 00668 00669 void CClassR::RestoreL() 00670 { 00671 RStoreReadStream instream; 00672 instream.OpenLC(iStore,iId); 00673 InternalizeL(instream); // or we can say instream >> *this; 00674 CleanupStack::PopAndDestroy(); 00675 } 00676 00677 TStreamId CClassR::StoreL() 00678 { 00679 RStoreWriteStream outstream; 00680 TStreamId id = outstream.CreateLC(iStore); 00681 ExternalizeL(outstream); // or we can say outstream << *this; 00682 outstream.CommitL(); 00683 CleanupStack::PopAndDestroy(); 00684 return id; 00685 } 00686 00687 void CClassR::UpdateStoreL() 00688 { 00689 RStoreWriteStream outstream; 00690 outstream.ReplaceLC(iStore,iId); 00691 ExternalizeL(outstream); // or we can say outstream << *this; 00692 outstream.CommitL(); 00693 CleanupStack::PopAndDestroy(); 00694 iStore.CommitL();// commit the changes to the store 00695 } 00696 00697 void CClassR::ExternalizeL(RWriteStream& aStream) const 00698 { 00699 aStream << iFixBuf; 00700 } 00701 00702 void CClassR::InternalizeL(RReadStream& aStream) 00703 { 00704 aStream >> iFixBuf; 00705 } 00706 00707 //*************************************************************** 00708 // 00709 // TExampleIndex Implementation 00710 // 00711 //*************************************************************** 00712 00713 TStreamId TExampleIndex::StoreL(CStreamStore& aStore) 00714 { 00715 RStoreWriteStream outstream; 00716 TStreamId id = outstream.CreateLC(aStore); 00717 ExternalizeL(outstream); // or we can say outstream << *this; 00718 outstream.CommitL(); 00719 CleanupStack::PopAndDestroy(); 00720 return id; 00721 } 00722 00723 void TExampleIndex::RestoreL(CStreamStore& aStore, TStreamId anId) 00724 { 00725 RStoreReadStream instream; 00726 instream.OpenLC(aStore,anId); 00727 InternalizeL(instream); 00728 CleanupStack::PopAndDestroy(); 00729 } 00730 00731 void TExampleIndex::ExternalizeL(RWriteStream& aStream) const 00732 { 00733 aStream << iPid; 00734 aStream << iRid; 00735 aStream << iABCid; 00736 } 00737 00738 void TExampleIndex::InternalizeL(RReadStream& aStream) 00739 { 00740 aStream >> iPid; 00741 aStream >> iRid; 00742 aStream >> iABCid; 00743 }
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.