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 #include "CommonToResourceFilesEx.h"
00031 #include "ReadArray.h"
00032 #include <readarray.rsg>
00033
00034
00035
00036 CResDataArray* CResDataArray::NewLC(TResourceReader& aReader)
00037 {
00038 CResDataArray* self=new (ELeave) CResDataArray;
00039 CleanupStack::PushL(self);
00040 self->ConstructL(aReader);
00041 return self;
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 void CResDataArray::ConstructL(TResourceReader& aReader)
00053 {
00054 iDataArray = new (ELeave) CArrayPtrFlat<CResData> (3);
00055 TRAPD(error,AddDataL(aReader));
00056 if (error)
00057 {
00058 iDataArray->ResetAndDestroy();
00059 delete iDataArray;
00060 User::Leave(error);
00061 }
00062 }
00063
00064
00065
00066
00067
00068 CResDataArray::~CResDataArray()
00069 {
00070 if (iDataArray)
00071 {
00072 iDataArray->ResetAndDestroy();
00073 delete iDataArray;
00074 }
00075 }
00076
00077
00078
00079
00080
00081 void CResDataArray::AddDataL(TResourceReader& aReader)
00082 {
00083 TInt index;
00084 TInt number;
00085
00086
00087
00088 number = aReader.ReadInt16();
00089
00090
00091
00092
00093 for (index = 0; index < number ; index++)
00094 {
00095 CResData* resData = CResData::NewLC(aReader);
00096 iDataArray->AppendL(resData);
00097 CleanupStack::Pop();
00098 }
00099 }
00100
00101
00102
00103
00104 void CResDataArray::ShowAllData()
00105 {
00106 _LIT(KPressAnyKeyToContinue," -->press any key to continue\n\n");
00107 TInt count;
00108
00109 count = (iDataArray? iDataArray->Count() : 0);
00110
00111 for (TInt index = 0; index < count; index++)
00112 {
00113 (*iDataArray)[index]->ShowData(index+1);
00114 console->Printf(KPressAnyKeyToContinue);
00115 console->Getch();
00116 }
00117 }
00118
00119
00120
00121
00122 CResData* CResData::NewLC(TResourceReader& aReader)
00123 {
00124 CResData* self=new (ELeave) CResData;
00125 CleanupStack::PushL(self);
00126 self->ConstructL(aReader);
00127 return self;
00128 }
00129
00130
00131
00132
00133
00134
00135
00136 void CResData::ConstructL(TResourceReader& aReader)
00137 {
00138
00139 iWrd = aReader.ReadInt16();
00140
00141
00142 iFlags = aReader.ReadInt16();
00143
00144
00145 iLng = aReader.ReadInt32();
00146
00147
00148
00149
00150
00151 TPtrC temp = aReader.ReadTPtrC();
00152 (iTxt.Des()).Copy(temp);
00153
00154
00155 iLtxt = aReader.ReadHBufCL();
00156
00157
00158 iByt = aReader.ReadUint8();
00159
00160
00161 iDbl = aReader.ReadReal64();
00162 }
00163
00164
00165
00166
00167 CResData::~CResData()
00168 {
00169 delete iLtxt;
00170 }
00171
00172
00173
00174
00175 void CResData::ShowData(const TInt aStructNum)
00176 {
00177 _LIT(KResourceItems,"Resource items (struct #%d):\n");
00178 _LIT(KResourceItems2,"Resource items:\n");
00179 _LIT(KWrdFormat,"wrd = %d\n");
00180 _LIT(KFlags,"flags = ");
00181 _LIT(KEFlagItem,"EFlagItem");
00182 _LIT(KNewline,"\n");
00183 _LIT(KLngFormat,"lng = %d\n");
00184 _LIT(KBytFormat,"byt = %d\n");
00185 _LIT(KDblFormat,"dbl = %S\n");
00186 _LIT(KTxtFormat,"txt = %S\n");
00187 _LIT(KLtxtFormat,"ltxt = %S\n");
00188 _LIT(KLtxt,"ltxt = \n");
00189
00190 TBuf<16> temp;
00191 TRealFormat format(16,2);
00192
00193 if (aStructNum)
00194 console->Printf(KResourceItems,aStructNum);
00195 else
00196 console->Printf(KResourceItems2);
00197
00198
00199 console->Printf(KWrdFormat,iWrd);
00200
00201
00202 console->Printf(KFlags);
00203 TUint mask = 1;
00204 TBuf<256> temp2;
00205 for (TInt ii = 0 ; ii < 16; ii++)
00206 {
00207 if (iFlags & mask)
00208 {
00209 temp2.Append(KEFlagItem);
00210 temp2.AppendNum(ii+1);
00211 temp2.Append('+');
00212 }
00213 mask <<= 1;
00214 }
00215 if (temp2.Length())
00216 temp2.SetLength(temp2.Length()-1);
00217 console->Printf(temp2);
00218 console->Printf(KNewline);
00219
00220
00221 console->Printf(KLngFormat,iLng);
00222
00223
00224 console->Printf(KBytFormat,iByt);
00225
00226
00227 temp.Num(iDbl,format);
00228 console->Printf(KDblFormat,&temp);
00229
00230
00231 console->Printf(KTxtFormat,&iTxt);
00232
00233
00234 if (iLtxt)
00235 console->Printf(KLtxtFormat,iLtxt);
00236 else
00237 console->Printf(KLtxt);
00238 }
00241
00242
00243
00244 LOCAL_C void doExampleL()
00245 {
00246
00247 RResourceFile resourceFile;
00248
00249
00250
00251 #if defined(__WINS__)
00252 _LIT(KZSystemDataArrayRsc,"Z:\\Resource\\apps\\ReadArray.rsc");
00253 resourceFile.OpenL(fsSession, KZSystemDataArrayRsc);
00254 #endif
00255
00256
00257
00258 #if defined(__EPOC32__)
00259 _LIT(KCSystemDataArrayRsc,"Z:\\Resource\\Apps\\ReadArray.rsc");
00260 resourceFile.OpenL(fsSession, KCSystemDataArrayRsc);
00261 #endif
00262
00263
00264 HBufC8* res = resourceFile.AllocReadLC(SECOND);
00265
00266 TResourceReader theReader;
00267 theReader.SetBuffer(res);
00268
00269
00270
00271 CResDataArray* resDataArray = CResDataArray::NewLC(theReader);
00272
00273
00274 CleanupStack::Pop();
00275
00276
00277 CleanupStack::PopAndDestroy();
00278
00279
00280 resDataArray->ShowAllData();
00281
00282
00283 delete resDataArray;
00284
00285
00286 resourceFile.Close();
00287 }
00288