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