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 #include "CommonStreamStore.h"
00044 #include <s32file.h>
00045 #include <s32mem.h>
00046
00047
00048
00049
00050 _LIT(KTxtNewLine,"\n");
00051 _LIT(KFormatType1,"\n%S, ");
00052 _LIT(KFormatType2,"%d, ");
00053 _LIT(KFormatType3,"%u, ");
00054 _LIT(KFormatType4,"%u ");
00055 _LIT(KFormatType5,"%f ");
00056
00057
00058
00059
00060
00061 static void doMakeAndStoreL(CStreamStore& aStore,TStreamId& anId);
00062
00063
00064
00065 static void doRestoreL(CStreamStore& aStore,const TStreamId& anId);
00066
00067
00068 class CClassA;
00069 static void doShow(const TDesC& aHeading,const CClassA& anA);
00070
00071
00072 class CClassB;
00073 static void doShow(const TDesC& aHeading,const CClassB& aB);
00074
00075
00076 class CClassA : public CBase
00077 {
00078 public :
00079 static CClassA* NewLC();
00080 ~CClassA();
00081 void SetTextL(const TDesC& aData);
00082 void ExternalizeL(RWriteStream& aStream) const;
00083 void InternalizeL(RReadStream& aStream);
00084 public :
00085 HBufC* iVarBuffer;
00086 TInt iIntValue;
00087 TUint iUintValue;
00088 };
00089
00090
00091 class CClassB : public CBase
00092 {
00093 public :
00094 static CClassB* NewLC();
00095 void ExternalizeL(RWriteStream& aStream) const;
00096 void InternalizeL(RReadStream& aStream);
00097 public :
00098 TBuf<32> iFixBuffer;
00099 TUint iUintValue;
00100 TInt iIntValue;
00101 TReal iRealValue;
00102 };
00103
00104
00105 static void doExampleL()
00106 {
00107
00108
00109
00110 TStreamId theId;
00111
00112
00113
00114 CStreamStore* store = CBufStore::NewLC(2 );
00115
00116 doMakeAndStoreL(*store,theId);
00117 doRestoreL(*store,theId);
00118
00119
00120 CleanupStack::PopAndDestroy();
00121 }
00122
00123 static void doMakeAndStoreL(CStreamStore& aStore,TStreamId& anId)
00124 {
00125
00126
00127 _LIT(KTxtForClassA,"Text for CClassA");
00128 CClassA* theA = CClassA::NewLC();
00129 theA->SetTextL(KTxtForClassA);
00130 theA->iIntValue = -1;
00131 theA->iUintValue = 2;
00132
00133
00134
00135 _LIT(KTxtForClassB,"Text for CClassB");
00136 CClassB* theB = CClassB::NewLC();
00137 theB->iFixBuffer = KTxtForClassB;
00138 theB->iIntValue = -3;
00139 theB->iUintValue = 4;
00140 theB->iRealValue = 5.6;
00141
00142
00143 _LIT(KTxtClassAContent,"CClassA content ...");
00144 doShow(KTxtClassAContent,*theA);
00145
00146
00147 _LIT(KTxtClassBContent,"CClassB content ...");
00148 doShow(KTxtClassBContent,*theB);
00149
00150
00151
00152
00153 RStoreWriteStream outstream;
00154 anId = outstream.CreateLC(aStore);
00155
00156
00157 outstream << *theA;
00158
00159
00160 outstream << *theB;
00161
00162
00163
00164
00165
00166
00167 outstream.CommitL();
00168
00169
00170
00171
00172 CleanupStack::PopAndDestroy(3);
00173 }
00174
00175 static void doRestoreL(CStreamStore& aStore,const TStreamId& anId)
00176 {
00177
00178 CClassA* theA = CClassA::NewLC();
00179 CClassB* theB = CClassB::NewLC();
00180
00181
00182
00183
00184 RStoreReadStream instream;
00185 instream.OpenLC(aStore,anId);
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 instream >> *theA;
00198 instream >> *theB;
00199
00200
00201
00202
00203
00204
00205 CleanupStack::PopAndDestroy();
00206
00207
00208 _LIT(KTxtRestoredClassA,"Restored CClassA content ...");
00209 doShow(KTxtRestoredClassA,*theA);
00210
00211
00212 _LIT(KTxtRestoredClassB,"Restored CClassB content ...");
00213 doShow(KTxtRestoredClassB,*theB);
00214
00215
00216
00217 CleanupStack::PopAndDestroy(2);
00218 }
00219
00220 static void doShow(const TDesC& aHeading,const CClassA& anA)
00221 {
00222 console->Printf(KTxtNewLine);
00223 console->Printf(aHeading);
00224 console->Printf(KFormatType1,anA.iVarBuffer);
00225 console->Printf(KFormatType2,anA.iIntValue);
00226 console->Printf(KFormatType4,anA.iUintValue);
00227 console->Printf(KTxtNewLine);
00228 }
00229
00230 static void doShow(const TDesC& aHeading,const CClassB& aB)
00231 {
00232 console->Printf(KTxtNewLine);
00233 console->Printf(aHeading);
00234 console->Printf(KFormatType1,&aB.iFixBuffer);
00235 console->Printf(KFormatType2,aB.iIntValue);
00236 console->Printf(KFormatType3,aB.iUintValue);
00237 console->Printf(KFormatType5,aB.iRealValue);
00238 console->Printf(KTxtNewLine);
00239 }
00240
00241
00242
00243
00244 CClassA* CClassA::NewLC()
00245 {
00246 CClassA* self = new (ELeave) CClassA;
00247 CleanupStack::PushL(self);
00248 return self;
00249 }
00250
00251 CClassA::~CClassA()
00252 {
00253 delete iVarBuffer;
00254 }
00255
00256 void CClassA::SetTextL(const TDesC& aData)
00257 {
00258 iVarBuffer = aData.AllocL();
00259 }
00260
00261 void CClassA::ExternalizeL(RWriteStream& aStream) const
00262 {
00263 aStream.WriteInt32L(iVarBuffer->Des().MaxLength());
00264 aStream << *iVarBuffer;
00265 aStream.WriteInt32L(iIntValue);
00266 aStream.WriteUint32L(iUintValue);
00267 }
00268
00269 void CClassA::InternalizeL(RReadStream& aStream)
00270 {
00271 TInt maxlen;
00272 maxlen = aStream.ReadInt32L();
00273 iVarBuffer = HBufC::NewL(aStream,maxlen);
00274 iIntValue = aStream.ReadInt32L();
00275 iUintValue = aStream.ReadUint32L();
00276 }
00277
00278
00279
00280
00281 CClassB* CClassB::NewLC()
00282 {
00283 CClassB* self = new (ELeave) CClassB;
00284 CleanupStack::PushL(self);
00285 return self;
00286 }
00287
00288 void CClassB::ExternalizeL(RWriteStream& aStream) const
00289 {
00290 aStream << iFixBuffer;
00291 aStream.WriteInt32L(iIntValue);
00292 aStream.WriteUint32L(iUintValue);
00293 aStream.WriteReal64L(iRealValue);
00294 }
00295
00296 void CClassB::InternalizeL(RReadStream& aStream)
00297 {
00298 aStream >> iFixBuffer;
00299 iIntValue = aStream.ReadInt32L();
00300 iUintValue = aStream.ReadUint32L();
00301 iRealValue = aStream.ReadReal64L();
00302 }
00303
00304
00305
00306
00307
00308