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 #include "CommonStreamStore.h"
00034 #include <s32file.h>
00035
00036
00037
00038 static void doMakeAndExternalizeL(const TDesC& aName);
00039
00040
00041
00042 static void doInternalizeL(const TDesC& aName);
00043
00044
00045 class TSimple;
00046 static void doShow(const TDesC& aHeading,const TSimple& theSimple);
00047
00048
00049 enum TXxx {EX1,EX2,EX3};
00050
00051
00052 class TSimple
00053 {
00054 public :
00055 void ExternalizeL(RWriteStream& aStream) const;
00056 void InternalizeL(RReadStream& aStream);
00057 public :
00058 TXxx iTheEnum;
00059 TBuf<32> iBuffer;
00060 TInt iIntValue;
00061 TUint iUintValue;
00062 TReal iRealValue;
00063 };
00064
00065
00066
00067 _LIT(KFullNameOfFileStore,"\\epoc32ex\\data\\SimpleClassToSimpleStream.dat");
00068
00069
00070
00071 static void doExampleL()
00072 {
00073
00074 fsSession.MkDirAll(KFullNameOfFileStore);
00075 doMakeAndExternalizeL(KFullNameOfFileStore);
00076 doInternalizeL(KFullNameOfFileStore);
00077 }
00078
00079 static void doMakeAndExternalizeL(const TDesC& aName)
00080 {
00081 TParse filestorename;
00082 fsSession.Parse(aName,filestorename);
00083
00084
00085 CFileStore* store = CDirectFileStore::ReplaceLC(fsSession,filestorename.FullName(),EFileWrite);
00086
00087
00088 store->SetTypeL(KDirectFileStoreLayoutUid);
00089
00090
00091
00092 _LIT(KTxtSomeText,"Some text");
00093 TSimple thesimple;
00094 thesimple.iTheEnum = EX3;
00095 thesimple.iBuffer = KTxtSomeText;
00096 thesimple.iIntValue = -1;
00097 thesimple.iUintValue = 2;
00098 thesimple.iRealValue = 3.4;
00099
00100
00101 _LIT(KTxtTSimpleContent,"TSimple content ...");
00102 doShow(KTxtTSimpleContent,thesimple);
00103
00104
00105
00106
00107
00108
00109 RStoreWriteStream outstream;
00110 TStreamId id = outstream.CreateLC(*store);
00111
00112
00113 outstream << thesimple;
00114
00115
00116 outstream.CommitL();
00117
00118
00119 CleanupStack::PopAndDestroy();
00120
00121
00122 store->SetRootL(id);
00123
00124
00125 store->CommitL();
00126
00127
00128
00129 CleanupStack::PopAndDestroy();
00130 }
00131
00132 static void doInternalizeL(const TDesC& aName)
00133 {
00134 TParse filestorename;
00135 fsSession.Parse(aName,filestorename);
00136
00137
00138 CFileStore* store = CDirectFileStore::OpenLC(fsSession,filestorename.FullName(),EFileRead);
00139
00140
00141
00142
00143 RStoreReadStream instream;
00144 instream.OpenLC(*store,store->Root());
00145
00146
00147 TSimple thesimple;
00148 instream >> thesimple;
00149
00150
00151 CleanupStack::PopAndDestroy();
00152
00153
00154
00155 CleanupStack::PopAndDestroy();
00156
00157
00158 _LIT(KTxtRestoredTSimpleContent,"Restored TSimple content ...");
00159 doShow(KTxtRestoredTSimpleContent,thesimple);
00160 }
00161
00162 _LIT(KTxtNewLine,"\n");
00163 _LIT(KFormatType1,"\n%d");
00164 _LIT(KFormatType2,"\n%S");
00165 _LIT(KFormatType3,"\n%u");
00166 _LIT(KFormatType4,"\n%f");
00167
00168 static void doShow(const TDesC& aHeading,const TSimple& aSimple)
00169 {
00170 console->Printf(KTxtNewLine);
00171 console->Printf(aHeading);
00172 console->Printf(KFormatType1,aSimple.iTheEnum);
00173 console->Printf(KFormatType2,&aSimple.iBuffer);
00174 console->Printf(KFormatType1,aSimple.iIntValue);
00175 console->Printf(KFormatType3,aSimple.iUintValue);
00176 console->Printf(KFormatType4,aSimple.iRealValue);
00177 console->Printf(KTxtNewLine);
00178 }
00179
00180
00181
00182
00183
00184
00185
00186 RWriteStream& operator<<(RWriteStream& aStream, const TXxx& anXxx)
00187 {
00188 aStream.WriteInt8L(anXxx);
00189 return aStream;
00190 }
00191
00192 RReadStream& operator>>(RReadStream& aStream, TXxx& anXxx)
00193 {
00194 anXxx = TXxx(aStream.ReadInt8L());
00195 return aStream;
00196 }
00197
00198
00199
00200
00201 void TSimple::ExternalizeL(RWriteStream& aStream) const
00202 {
00203 aStream << iTheEnum;
00204 aStream << iBuffer;
00205 aStream.WriteInt32L(iIntValue);
00206 aStream.WriteUint32L(iUintValue);
00207 aStream.WriteReal64L(iRealValue);
00208 }
00209
00210 void TSimple::InternalizeL(RReadStream& aStream)
00211 {
00212 aStream >> iTheEnum;
00213 aStream >> iBuffer;
00214 iIntValue = aStream.ReadInt32L();
00215 iUintValue = aStream.ReadUint32L();
00216 iRealValue = aStream.ReadReal64L();
00217 }
00218
00219
00220
00221
00222
00223