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