00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "CommonStreamStore.h"
00020 #include <s32file.h>
00021
00022
00023
00024 LOCAL_C void doMakeAndExternalizeL(const TDesC& aName);
00025
00026
00027
00028 LOCAL_C void doInternalizeL(const TDesC& aName);
00029
00030
00031 class CCompound;
00032 LOCAL_C void doShow(const TDesC& aHeading,const CCompound& theSimple);
00033
00034
00035 class CClassA
00036 {
00037 public :
00038 void ExternalizeL(RWriteStream& aStream) const;
00039 void InternalizeL(RReadStream& aStream);
00040 public :
00041 TBuf<32> iBufferA;
00042 TInt iXA;
00043 TUint iYA;
00044 };
00045
00046
00047 class CClassB
00048 {
00049 public :
00050 void ExternalizeL(RWriteStream& aStream) const;
00051 void InternalizeL(RReadStream& aStream);
00052 public :
00053 TBuf<32> iBufferB;
00054 };
00055
00056
00057 class TClassC
00058 {
00059 public :
00060 void ExternalizeL(RWriteStream& aStream) const;
00061 void InternalizeL(RReadStream& aStream);
00062 public :
00063 TReal iZC;
00064 };
00065
00066
00067 class CCompound : public CBase
00068 {
00069 public :
00070 ~CCompound();
00071 static CCompound* NewLC();
00072 static CCompound* NewLC(CStreamStore& aStore,TStreamId anId);
00073 static CCompound* NewL(CStreamStore& aStore,TStreamId anId);
00074 TStreamId StoreL(CStreamStore& store);
00075 void RestoreL(CStreamStore& aStore,TStreamId anId);
00076 void InternalizeL(RReadStream& aStream);
00077 void ExternalizeL(RWriteStream& aStream) const;
00078 private:
00079 void ConstructL();
00080 void ConstructL(CStreamStore& aStore,TStreamId anId);
00081 public :
00082 CClassA* iCa;
00083 CClassB* iCb;
00084 TClassC iTc;
00085 };
00086
00087
00088 _LIT(KFullNameOfFileStore,"\\epoc32ex\\data\\stcompnd.dat");
00089
00090
00091
00092 LOCAL_C void doExampleL()
00093 {
00094
00095 fsSession.MkDirAll(KFullNameOfFileStore);
00096 doMakeAndExternalizeL(KFullNameOfFileStore);
00097 doInternalizeL(KFullNameOfFileStore);
00098 }
00099
00100 LOCAL_C void doMakeAndExternalizeL(const TDesC& aName)
00101 {
00102 TParse filestorename;
00103
00104 fsSession.Parse(aName,filestorename);
00105
00106
00107 CFileStore* store = CDirectFileStore::ReplaceLC(fsSession,filestorename.FullName(),EFileWrite);
00108
00109
00110 store->SetTypeL(KDirectFileStoreLayoutUid);
00111
00112
00113
00114 CCompound* thecompound = CCompound::NewLC();
00115
00116 _LIT(KTxtClassAText,"CClassA text");
00117 _LIT(KTxtClassBText,"CClassB text");
00118
00119 thecompound->iCa->iBufferA = KTxtClassAText;
00120 thecompound->iCa->iXA = -1;
00121 thecompound->iCa->iYA = 2;
00122 thecompound->iCb->iBufferB = KTxtClassBText;
00123 thecompound->iTc.iZC = 3.456;
00124
00125
00126
00127 _LIT(KTxtInitialContent,"... Initial content of CCompound");
00128 doShow(KTxtInitialContent,*thecompound);
00129
00130
00131
00132 TStreamId id = thecompound->StoreL(*store);
00133
00134
00135 store->SetRootL(id);
00136
00137
00138 store->CommitL();
00139
00140
00141
00142
00143
00144
00145 CleanupStack::PopAndDestroy(2);
00146 }
00147
00148 LOCAL_C void doInternalizeL(const TDesC& aName)
00149 {
00150 TParse filestorename;
00151
00152 fsSession.Parse(aName,filestorename);
00153
00154
00155 CFileStore* store = CDirectFileStore::OpenLC(fsSession,filestorename.FullName(),EFileRead);
00156
00157
00158
00159 CCompound* thecompound = CCompound::NewL(*store,store->Root());
00160
00161
00162
00163 _LIT(KTxtRestoredContent,"... Restored CCompound content.");
00164 doShow(KTxtRestoredContent,*thecompound);
00165
00166
00167
00168 CleanupStack::PopAndDestroy();
00169
00170
00171 delete thecompound;
00172 }
00173
00174 _LIT(KTxtNewLine,"\n");
00175 _LIT(KFormatType1,"\n%d");
00176 _LIT(KFormatType2,"\n%S");
00177 _LIT(KFormatType3,"\n%u");
00178 _LIT(KFormatType4,"\n%f");
00179
00180 LOCAL_C void doShow(const TDesC& aHeading,const CCompound& aCompound)
00181 {
00182 console->Printf(KTxtNewLine);
00183 console->Printf(aHeading);
00184 console->Printf(KFormatType2,&aCompound.iCa->iBufferA);
00185 console->Printf(KFormatType1,aCompound.iCa->iXA);
00186 console->Printf(KFormatType3,aCompound.iCa->iYA);
00187 console->Printf(KFormatType2,&aCompound.iCb->iBufferB);
00188 console->Printf(KFormatType4,aCompound.iTc.iZC);
00189 console->Printf(KTxtNewLine);
00190 }
00191
00192
00193
00194
00195
00196 CCompound::~CCompound()
00197 {
00198 delete iCa;
00199 delete iCb;
00200 }
00201
00202
00203
00204 CCompound* CCompound::NewLC()
00205 {
00206 CCompound* self=new (ELeave) CCompound;
00207 CleanupStack::PushL(self);
00208 self->ConstructL();
00209 return self;
00210 }
00211
00212
00213
00214 void CCompound::ConstructL()
00215 {
00216 iCa = new (ELeave) CClassA;
00217 iCb = new (ELeave) CClassB;
00218 }
00219
00220
00221
00222 CCompound* CCompound::NewL(CStreamStore& aStore,TStreamId anId)
00223 {
00224 CCompound* self=CCompound::NewLC(aStore,anId);
00225 CleanupStack::Pop();
00226 return self;
00227 }
00228
00229
00230
00231
00232 CCompound* CCompound::NewLC(CStreamStore& aStore,TStreamId anId)
00233 {
00234 CCompound* self=new (ELeave) CCompound;
00235 CleanupStack::PushL(self);
00236 self->ConstructL(aStore,anId);
00237 return self;
00238 }
00239
00240
00241
00242 void CCompound::ConstructL(CStreamStore& aStore,TStreamId anId)
00243 {
00244 iCa = new (ELeave) CClassA;
00245 iCb = new (ELeave) CClassB;
00246 RestoreL(aStore,anId);
00247 }
00248
00249 void CCompound::RestoreL(CStreamStore& aStore,TStreamId anId)
00250 {
00251 RStoreReadStream instream;
00252 instream.OpenLC(aStore,anId);
00253 InternalizeL(instream);
00254
00255 CleanupStack::PopAndDestroy();
00256 }
00257
00258
00259
00260 void CCompound::InternalizeL(RReadStream& aStream)
00261 {
00262 aStream >> *iCa;
00263 aStream >> *iCb;
00264 aStream >> iTc;
00265 }
00266
00267 TStreamId CCompound::StoreL(CStreamStore& aStore)
00268 {
00269 RStoreWriteStream outstream;
00270 TStreamId id = outstream.CreateLC(aStore);
00271
00272 ExternalizeL(outstream);
00273
00274 outstream.CommitL();
00275
00276 CleanupStack::PopAndDestroy();
00277 return id;
00278 }
00279
00280
00281 void CCompound::ExternalizeL(RWriteStream& aStream) const
00282 {
00283 aStream << *iCa;
00284 aStream << *iCb;
00285 aStream << iTc;
00286 }
00287
00288
00289
00290
00291
00292
00293 void CClassA::InternalizeL(RReadStream& aStream)
00294 {
00295 aStream >> iBufferA;
00296 iXA = aStream.ReadInt32L();
00297 iYA = aStream.ReadUint32L();
00298 }
00299
00300
00301 void CClassA::ExternalizeL(RWriteStream& aStream)const
00302 {
00303 aStream << iBufferA;
00304 aStream.WriteInt32L(iXA);
00305 aStream.WriteUint32L(iYA);
00306 }
00307
00308
00309
00310
00311
00312
00313 void CClassB::InternalizeL(RReadStream& aStream)
00314 {
00315 aStream >> iBufferB;
00316 }
00317
00318
00319 void CClassB::ExternalizeL(RWriteStream& aStream) const
00320 {
00321 aStream << iBufferB;
00322 }
00323
00324
00325
00326
00327
00328
00329 void TClassC::ExternalizeL(RWriteStream& aStream) const
00330 {
00331 aStream.WriteReal64L(iZC);
00332 }
00333
00334
00335 void TClassC::InternalizeL(RReadStream& aStream)
00336 {
00337 iZC = aStream.ReadReal64L();
00338 }
00339
00340
00341
00342
00343
00344