examples/SysLibs/FileStores/WritePermFS1/WritePermFS1.cpp

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

Generated by  doxygen 1.6.2