|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Resource reader |
|
15 // |
|
16 // |
|
17 |
|
18 #include "BaRsReadImpl.h" |
|
19 #include "BaCompileAssert.h" |
|
20 |
|
21 /** @internalComponent |
|
22 An error will be issued at compile time if the class size is not KRsReaderImplSize. */ |
|
23 TResourceReaderImpl::TResourceReaderImpl() : |
|
24 iBuffer(NULL), |
|
25 iCurrentPtr(NULL) |
|
26 { |
|
27 //TResourceReaderImpl size. It should be 12 because of the BC reasons. |
|
28 //12 is the size of TResourceReader class. |
|
29 enum |
|
30 { |
|
31 KRsReaderImplSize = 12 |
|
32 }; |
|
33 COMPILE_TIME_ASSERT(sizeof(TResourceReaderImpl) == KRsReaderImplSize); |
|
34 } |
|
35 |
|
36 /** Sets the buffer containing the resource data. |
|
37 |
|
38 The current position within the buffer is set to the start of the buffer so |
|
39 that subsequent calls to the interpreting functions, for example ReadInt8(), |
|
40 start at the beginning of this buffer. |
|
41 |
|
42 @internalComponent |
|
43 @param aBuffer Pointer to an 8 bit non-modifiable descriptor containing |
|
44 or representing resource data. |
|
45 @param aResourceId The numeric id of the resource to be read. |
|
46 @post Buffer pointer is initialized. |
|
47 @post Buffer current position pointer is initialized. */ |
|
48 void TResourceReaderImpl::SetBuffer(const TDesC8* aBuffer) |
|
49 { |
|
50 iBuffer=aBuffer; |
|
51 iCurrentPtr=iBuffer->Ptr(); |
|
52 } |
|
53 |
|
54 /** Sets the buffer and current position to NULL. |
|
55 @internalComponent |
|
56 @post Buffer pointer is set to NULL. |
|
57 @post Buffer current position pointer is set to NULL. */ |
|
58 void TResourceReaderImpl::ResetBuffer() |
|
59 { |
|
60 iBuffer=NULL; |
|
61 iCurrentPtr=NULL; |
|
62 } |
|
63 |
|
64 /** Returns the current position within the resource buffer. |
|
65 |
|
66 The function makes no assumption about the type of data in the buffer at the |
|
67 current position. |
|
68 |
|
69 @internalComponent |
|
70 @return A pointer to the current position within the resource buffer. */ |
|
71 const TAny* TResourceReaderImpl::Ptr() |
|
72 { |
|
73 return(iCurrentPtr); |
|
74 } |
|
75 |
|
76 /** Updates iCurrentPtr with a new value. |
|
77 |
|
78 @internalComponent |
|
79 @pre iBuffer is not NULL. |
|
80 @pre aPtr is not NULL. |
|
81 @param aPtr The new value of iCurrentPtr. |
|
82 @post iCurrentPtr is updated. |
|
83 @panic BAFL 4 The new iCurrentPtr points beyond the buffer end. |
|
84 @panic BAFL 70 iBuffer is NULL. DEBUG build only. |
|
85 @panic BAFL 71 aPtr is NULL. DEBUG build only. |
|
86 @leave KErrOff The new iCurrentPtr points beyond the buffer end. */ |
|
87 void TResourceReaderImpl::MovePtrL(const TUint8* aPtr) |
|
88 { |
|
89 __ASSERT_DEBUG(iBuffer != NULL, Panic(EBafPanicNullPtr1)); |
|
90 __ASSERT_DEBUG(aPtr != NULL, Panic(EBafPanicNullPtr2)); |
|
91 iAssertObj.AssertRelL(aPtr<=(iBuffer->Ptr()+iBuffer->Length()), EBafPanicResourceReaderEndExceeded); |
|
92 iCurrentPtr=aPtr; |
|
93 } |
|
94 |
|
95 /** Interprets the data at the current buffer position as leading byte count data |
|
96 and constructs an 8 bit heap descriptor containing a copy of this data. |
|
97 |
|
98 The data is interpreted as: |
|
99 |
|
100 a byte value defining the number of 8 bit text characters or the length of |
|
101 binary data (the resource string/binary data length is limited to 255 characters max) |
|
102 |
|
103 followed by: |
|
104 |
|
105 the 8 bit text characters or binary data. |
|
106 |
|
107 If the value of the leading byte is zero, the function assumes that no data |
|
108 follows the leading byte and returns a NULL pointer. |
|
109 |
|
110 The current position within the resource buffer is updated. |
|
111 |
|
112 Use this explicit 8 bit variant when the resource contains binary data. If |
|
113 the resource contains text, then use the build independent variant ReadHBufCL(). |
|
114 |
|
115 In general, this type of resource data corresponds to one of the following: |
|
116 |
|
117 a LTEXT type in a resource STRUCT declaration. |
|
118 |
|
119 a variable length array within a STRUCT declaration which includes the LEN |
|
120 BYTE keywords. |
|
121 |
|
122 @internalComponent |
|
123 @pre The same as for ReadTPtrC8L(). |
|
124 @return Pointer to the 8 bit heap descriptor containing a |
|
125 copy of the data following the leading byte count at |
|
126 the current position within the resource buffer. The |
|
127 pointer can be NULL. |
|
128 @post iCurrentPtr is updated. |
|
129 @panic The same as ReadTPtrC8L(). |
|
130 @leave The same as ReadTPtrC8L(). |
|
131 @see ReadTPtrC8L() */ |
|
132 HBufC8* TResourceReaderImpl::ReadHBufC8L() |
|
133 { |
|
134 const TPtrC8 data(ReadTPtrC8L()); |
|
135 return (data.Length()==0)? NULL: data.AllocL(); |
|
136 } |
|
137 |
|
138 /** Interprets the data at the current buffer position as leading byte count data |
|
139 and constructs a 16 bit heap descriptor containing a copy of this data. |
|
140 |
|
141 The data is interpreted as: |
|
142 |
|
143 a byte value defining the number of 16 bit text characters |
|
144 (the resource string/binary data length is limited to 255 characters max) |
|
145 |
|
146 followed by: |
|
147 |
|
148 the 16 bit text characters. |
|
149 |
|
150 If the value of the leading byte is zero, the function assumes that no data |
|
151 follows the leading byte and returns a NULL pointer. |
|
152 |
|
153 The current position within the resource buffer is updated. |
|
154 |
|
155 Do not use this explicit 16 bit variant when the resource contains binary |
|
156 data; use the explicit 8 bit variant instead. If the resource contains text, |
|
157 use the build independent variant ReadHBufCL(). |
|
158 |
|
159 @internalComponent |
|
160 @pre The same as for ReadTPtrC16L(). |
|
161 @return Pointer to the 16bit heap descriptor containing a |
|
162 copy of the data following the leading byte count at |
|
163 the current position within the resource buffer. The |
|
164 pointer can be NULL. |
|
165 @post iCurrentPtr is updated. |
|
166 @panic The same as ReadTPtrC16L(). |
|
167 @leave The same as ReadTPtrC16L(). |
|
168 @see ReadTPtrC16L() */ |
|
169 HBufC16* TResourceReaderImpl::ReadHBufC16L() |
|
170 { |
|
171 const TPtrC16 data(ReadTPtrC16L()); |
|
172 return (data.Length()==0)? NULL: data.AllocL(); |
|
173 } |
|
174 |
|
175 /** Interprets the data at the current buffer position as leading byte count data |
|
176 and constructs an 8 bit non modifiable pointer descriptor to represent this |
|
177 data. |
|
178 |
|
179 The data is interpreted as: |
|
180 |
|
181 a byte value defining the number of text characters or the length of binary |
|
182 data (the resource string/binary data length is limited to 255 characters max) |
|
183 |
|
184 followed by: |
|
185 |
|
186 the 8 bit text characters or binary data. |
|
187 |
|
188 If the value of the leading byte is zero, calling Length() on the returned |
|
189 TPtrC8 returns zero. |
|
190 |
|
191 The current position within the resource buffer is updated. |
|
192 |
|
193 Use this explicit 8 bit variant when the resource contains binary data. If |
|
194 the resource contains text, then use the build independent variant ReadTPtrC(). |
|
195 |
|
196 In general, this type of resource data corresponds to one of the following: |
|
197 |
|
198 a LTEXT type in a resource STRUCT declaration. |
|
199 |
|
200 a variable length array within a STRUCT declaration which includes the LEN |
|
201 BYTE keywords. |
|
202 |
|
203 @internalComponent |
|
204 @pre iCurrentPtr != NULL. |
|
205 @pre The same as MovePtrL(const TUint8* aPtr). |
|
206 @return 8bit non modifiable pointer descriptor representing |
|
207 the data following the leading byte count at the |
|
208 current position within the resource buffer. |
|
209 @post iCurrentPtr is updated. |
|
210 @panic BAFL 72 iCurrentPtr is NULL. DEBUG build only. |
|
211 @panic The same as MovePtrL(const TUint8* aPtr). |
|
212 @leave The same as MovePtrL(const TUint8* aPtr). |
|
213 @see MovePtrL(const TUint8* aPtr) */ |
|
214 TPtrC8 TResourceReaderImpl::ReadTPtrC8L() |
|
215 { |
|
216 __ASSERT_DEBUG(iCurrentPtr != NULL, Panic(EBafPanicNullPtr3)); |
|
217 const TUint8* currentPtr=iCurrentPtr;//TUint8 pointer is used, which means that the |
|
218 //resource string length is limited to 255 characters max. |
|
219 const TInt strLen=*currentPtr; |
|
220 ++currentPtr; |
|
221 MovePtrL(currentPtr+strLen); |
|
222 return TPtrC8(currentPtr,strLen); |
|
223 } |
|
224 |
|
225 /** Interprets the data at the current buffer position as leading byte count data |
|
226 and constructs a 16 bit non modifiable pointer descriptor to represent this |
|
227 data. |
|
228 |
|
229 The data is interpreted as: |
|
230 |
|
231 a byte value defining the number of 16 bit text characters |
|
232 (the resource string/binary data length is limited to 255 characters max) |
|
233 |
|
234 followed by: |
|
235 |
|
236 the 16 bit text characters. |
|
237 |
|
238 If the value of the leading byte is zero, calling Length() on the returned |
|
239 TPtrC16 returns zero. |
|
240 |
|
241 The current position within the resource buffer is updated. |
|
242 |
|
243 Do not use this explicit 16 bit variant when the resource contains binary |
|
244 data; use the explicit 8 bit variant instead. If the resource contains text, |
|
245 use the build independent variant ReadTPtrC(). |
|
246 |
|
247 @internalComponent |
|
248 @pre iCurrentPtr != NULL. |
|
249 @pre The same as MovePtrL(const TUint8* aPtr). |
|
250 @return Pointer to an 8bit variant flat descriptor array. |
|
251 @post iCurrentPtr is updated. |
|
252 @panic BAFL 73 iCurrentPtr is NULL. DEBUG build only. |
|
253 @panic BAFL 15 The resource is a unicode string and it is not properly aligned. DEBUG build only. |
|
254 @panic The same as MovePtrL(const TUint8* aPtr). |
|
255 @leave KErrCorrupt The resource is a unicode string and it is not properly aligned. |
|
256 @leave The same as MovePtrL(const TUint8* aPtr). |
|
257 @see MovePtrL(const TUint8* aPtr) */ |
|
258 TPtrC16 TResourceReaderImpl::ReadTPtrC16L() |
|
259 { |
|
260 __ASSERT_DEBUG(iCurrentPtr != NULL, Panic(EBafPanicNullPtr4)); |
|
261 const TUint8* currentPtr=iCurrentPtr;//TUint8 pointer is used, which means that the |
|
262 //resource string length is limited to 255 characters max. |
|
263 const TInt unicodeLength=*currentPtr; |
|
264 ++currentPtr; |
|
265 if (unicodeLength!=0) |
|
266 { |
|
267 if (REINTERPRET_CAST(TUint,currentPtr)&0x1) |
|
268 { |
|
269 // The resource compiler puts out a padding byte (arbitrarily 0xab) |
|
270 // to ensure the alignment of Unicode strings within each resource. |
|
271 iAssertObj.AssertDebL(*currentPtr==0xab, EBafPanicUnicodeTextPaddingError); |
|
272 ++currentPtr; |
|
273 } |
|
274 } |
|
275 const TPtrC16 unicode(REINTERPRET_CAST(const TText16*,(unicodeLength==0)? NULL: currentPtr),unicodeLength); |
|
276 currentPtr+=unicodeLength*sizeof(TText16); |
|
277 MovePtrL(currentPtr); |
|
278 return unicode; |
|
279 } |
|
280 |
|
281 /** Interprets the data within the specified resource buffer as an array of leading |
|
282 byte count data and constructs an 8 bit non modifiable pointer descriptor |
|
283 to represent an element within this array. |
|
284 |
|
285 The function sets the buffer containing the resource data and sets the current |
|
286 position to the start of this buffer. Any buffer set by a previous call to |
|
287 SetBuffer() etc, is lost. |
|
288 |
|
289 The buffer is expected to contain an array of data elements preceded by a |
|
290 TInt16 value defining the number of elements within that array. |
|
291 |
|
292 Each element of the array is interpreted as: |
|
293 |
|
294 a byte value defining the number of 8 bit text characters or the length of |
|
295 binary data (the resource string/binary data length is limited to 255 characters max) |
|
296 |
|
297 followed by: |
|
298 |
|
299 the 8 bit text characters or binary data. |
|
300 |
|
301 If the value of the leading byte is zero, calling Length() on the returned |
|
302 TPtrC8 returns zero. |
|
303 |
|
304 The current position within the resource buffer is updated. |
|
305 |
|
306 Use this explicit 8 bit variant when the resource contains binary data, If |
|
307 the resource contains text, then use the build independent variant ReadTPtrC(TInt,const TDesC8*). |
|
308 |
|
309 @internalComponent |
|
310 @pre aBuffer != NULL. |
|
311 @pre The same as MovePtrL(const TUint8* aPtr). |
|
312 @param aIndex Position of the element within the array. This |
|
313 value is relative to zero. |
|
314 @param aBuffer Buffer containing the resource data. |
|
315 @return 8bit non modifiable pointer descriptor representing |
|
316 the data following the leading byte count at the |
|
317 current position within the resource buffer. |
|
318 @post iBuffer is initialized with aBuffer. |
|
319 @post The same as MovePtrL(const TUint8* aPtr). |
|
320 @panic BAFL 4 aIndex is greater or equal than the string length. DEBUG build only. |
|
321 @panic The same as MovePtrL(const TUint8* aPtr). |
|
322 @leave The same as MovePtrL(const TUint8* aPtr). |
|
323 @see MovePtrL(const TUint8* aPtr) */ |
|
324 TPtrC8 TResourceReaderImpl::ReadTPtrC8L(TInt aIndex,const TDesC8* aBuffer) |
|
325 { // implementation could be made more efficient if desired |
|
326 SetBuffer(aBuffer); |
|
327 TInt count=ReadInt16L(); |
|
328 // |
|
329 __ASSERT_DEBUG(aIndex<count,Panic(EBafPanicResourceReaderEndExceeded)); |
|
330 if (aIndex>=count) |
|
331 return TPtrC8(); |
|
332 // |
|
333 const TUint8* ptr=iCurrentPtr; |
|
334 while (--aIndex>=0) |
|
335 ptr+=1+*ptr; |
|
336 MovePtrL(ptr); |
|
337 return ReadTPtrC8L(); |
|
338 } |
|
339 |
|
340 /** Interprets the data within the specified resource buffer as an array of leading |
|
341 byte count data and constructs a 16 bit non modifiable pointer descriptor |
|
342 to represent an element within this array. |
|
343 |
|
344 The function sets the buffer containing the resource data and sets the current |
|
345 position to the start of this buffer. Any buffer set by a previous call to |
|
346 SetBuffer() etc., is lost. |
|
347 |
|
348 The buffer is expected to contain an array of data elements preceded by a |
|
349 TInt16 value defining the number of elements within that array. |
|
350 |
|
351 Each element of the array is interpreted as: |
|
352 |
|
353 a byte value defining the number of 8 bit text characters or the length of |
|
354 binary data (the resource string/binary data length is limited to 255 characters max) |
|
355 |
|
356 followed by: |
|
357 |
|
358 the 16 bit text characters. |
|
359 |
|
360 If the value of the leading byte is zero, calling Length() on the returned |
|
361 TPtrC16 returns zero. |
|
362 |
|
363 The current position within the resource buffer is updated. |
|
364 |
|
365 Do not use this explicit 16 bit variant when the resource contains binary |
|
366 data; use the explicit 8 bit variant instead. If the resource contains text, |
|
367 use the build independent variant ReadTPtrC(TInt,const TDesC8*). |
|
368 |
|
369 @internalComponent |
|
370 @pre aBuffer != NULL. |
|
371 @pre The same as ReadTPtrC16L(). |
|
372 @param aIndex The position of the element within the array. This |
|
373 value is relative to zero. |
|
374 @param aBuffer The buffer containing the resource data. |
|
375 @return 16bit non modifiable pointer descriptor representing |
|
376 the data following the leading byte count of the |
|
377 element at position within the array |
|
378 @post iBuffer is initialized with aBuffer. |
|
379 @post The same as ReadTPtrC16L(). |
|
380 @panic BAFL 4 aIndex is greater or equal than the string length. |
|
381 @panic The same as ReadTPtrC16L(). |
|
382 @leave KErrOff aIndex is grater or equal than the string length. |
|
383 @leave The same as ReadTPtrC16L(). |
|
384 @see ReadTPtrC16L()*/ |
|
385 TPtrC16 TResourceReaderImpl::ReadTPtrC16L(TInt aIndex,const TDesC8* aBuffer) |
|
386 { // implementation could be made more efficient if desired |
|
387 SetBuffer(aBuffer); |
|
388 const TInt count=ReadInt16L(); |
|
389 iAssertObj.AssertRelL(aIndex<count,EBafPanicResourceReaderEndExceeded); |
|
390 for (TInt i=0; i<aIndex; ++i) |
|
391 { |
|
392 ReadTPtrC16L(); |
|
393 } |
|
394 return ReadTPtrC16L(); |
|
395 } |
|
396 |
|
397 /** Interprets the data at the current buffer position as an array of leading byte |
|
398 count data and constructs a flat array of 8 bit descriptors. |
|
399 |
|
400 Each descriptor in the descriptor array corresponds to an element of the resource |
|
401 array. |
|
402 |
|
403 At the current buffer position, the buffer is expected to contain an array |
|
404 of data elements preceded by a TInt16 value defining the number of elements |
|
405 within that array. |
|
406 |
|
407 Each element of the array is interpreted as: |
|
408 |
|
409 a byte value defining the number of 8 bit text characters or the length of |
|
410 binary data (the resource string/binary data length is limited to 255 characters max) |
|
411 |
|
412 followed by: |
|
413 |
|
414 the text characters or binary data. |
|
415 |
|
416 The current position within the resource buffer is updated. |
|
417 |
|
418 Use this explicit 8 bit variant when the resource contains binary data. If |
|
419 the elements of the resource array contain text, use the build independent |
|
420 variant of ReadDesCArrayL(). |
|
421 |
|
422 @internalComponent |
|
423 @pre The same as ReadTPtrC8L(). |
|
424 @return Pointer to an 8bit variant flat descriptor array. |
|
425 @post The same as ReadTPtrC8L(). |
|
426 @panic The same as ReadTPtrC8L(). |
|
427 @leave The same as ReadTPtrC8L(). |
|
428 @leave KErrNoMemory There is not enough memory |
|
429 for the resulting buffer. |
|
430 @see ReadTPtrC8L() */ |
|
431 CDesC8ArrayFlat* TResourceReaderImpl::ReadDesC8ArrayL() |
|
432 { |
|
433 TInt count=ReadInt16L(); |
|
434 CDesC8ArrayFlat* array=new(ELeave) CDesC8ArrayFlat(count); |
|
435 CleanupStack::PushL(array); |
|
436 while (--count>=0) |
|
437 array->AppendL(ReadTPtrC8L()); |
|
438 CleanupStack::Pop(); |
|
439 return(array); |
|
440 } |
|
441 |
|
442 /** Interprets the data at the current buffer position as an array of leading byte |
|
443 count data and constructs a flat array of 16 bit descriptors. |
|
444 |
|
445 Each descriptor in the descriptor array corresponds to an element of the resource |
|
446 array. |
|
447 |
|
448 At the current buffer position, the buffer is expected to contain an array |
|
449 of data elements preceded by a TInt16 value defining the number of elements |
|
450 within that array. |
|
451 |
|
452 Each element of the array is interpreted as: |
|
453 |
|
454 a byte value defining the number of 8 bit text characters or the length of |
|
455 binary data (the resource string/binary data length is limited to 255 characters max) |
|
456 |
|
457 followed by: |
|
458 |
|
459 the 16 bit text characters. |
|
460 |
|
461 The current position within the resource buffer is updated. |
|
462 |
|
463 Do not use this explicit 16 bit variant when the resource contains binary |
|
464 data; use the explicit 8 bit variant instead. If the resource contains text, |
|
465 use the build independent variant ReadDesCArrayL(). |
|
466 |
|
467 @internalComponent |
|
468 @pre The same as ReadTPtrC16L(). |
|
469 @return Pointer to a 16bit variant flat descriptor array. |
|
470 @post The same as ReadTPtrC16L(). |
|
471 @panic The same as ReadTPtrC16L(). |
|
472 @leave The same as ReadTPtrC16L(). |
|
473 @leave KErrNoMemory There is not enough memory |
|
474 for the resulting buffer. |
|
475 @see ReadTPtrC16L() */ |
|
476 CDesC16ArrayFlat* TResourceReaderImpl::ReadDesC16ArrayL() |
|
477 { |
|
478 TInt count=ReadInt16L(); |
|
479 CDesC16ArrayFlat* array=new(ELeave) CDesC16ArrayFlat(count); |
|
480 CleanupStack::PushL(array); |
|
481 while (--count>=0) |
|
482 array->AppendL(ReadTPtrC16L()); |
|
483 CleanupStack::Pop(); |
|
484 return(array); |
|
485 } |
|
486 |
|
487 /** Interprets the data at the current buffer position as a TInt8 type and returns |
|
488 the value as a TInt. |
|
489 |
|
490 The current position within the resource buffer is updated. |
|
491 |
|
492 In general, a TInt8 corresponds to a BYTE type in a resource STRUCT declaration. |
|
493 |
|
494 Note that in Symbian OS, a TInt is at least as big as a TInt8. |
|
495 |
|
496 @internalComponent |
|
497 @pre iCurrentPtr != NULL. |
|
498 @pre The same as MovePtrL(const TUint8* aPtr). |
|
499 @return The TInt8 value taken from the resource buffer. |
|
500 @post The same as MovePtrL(const TUint8* aPtr). |
|
501 @leave The same as MovePtrL(const TUint8* aPtr). |
|
502 @panic The same as MovePtrL(const TUint8* aPtr). |
|
503 @panic BAFL 74 iCurrentPtr is NULL. DEBUG build only. |
|
504 @see MovePtrL(const TUint8* aPtr) */ |
|
505 TInt TResourceReaderImpl::ReadInt8L() |
|
506 { |
|
507 __ASSERT_DEBUG(iCurrentPtr != NULL, Panic(EBafPanicNullPtr5)); |
|
508 const TUint8* currentPtr=iCurrentPtr; |
|
509 MovePtrL(currentPtr+sizeof(TInt8)); |
|
510 return(*(TInt8*)currentPtr); |
|
511 } |
|
512 |
|
513 /** Interprets the data at the current buffer position as a TUint8 type and returns |
|
514 the value as a TUint. |
|
515 |
|
516 The current position within the resource buffer is updated. |
|
517 |
|
518 In general, a TUint8 corresponds to a BYTE type in a resource STRUCT declaration. |
|
519 |
|
520 Note that in Symbian OS, a TUint is at least as big as a TUint8. |
|
521 |
|
522 @internalComponent |
|
523 @pre iCurrentPtr != NULL. |
|
524 @pre The same as MovePtrL(const TUint8* aPtr). |
|
525 @return The TUint8 value taken from the resource buffer. |
|
526 @post The same as MovePtrL(const TUint8* aPtr). |
|
527 @leave The same as MovePtrL(const TUint8* aPtr). |
|
528 @panic The same as MovePtrL(const TUint8* aPtr). |
|
529 @panic BAFL 75 iCurrentPtr is NULL. DEBUG build only. |
|
530 @see MovePtrL(const TUint8* aPtr) */ |
|
531 TUint TResourceReaderImpl::ReadUint8L() |
|
532 { |
|
533 __ASSERT_DEBUG(iCurrentPtr != NULL, Panic(EBafPanicNullPtr6)); |
|
534 const TUint8* currentPtr=iCurrentPtr; |
|
535 MovePtrL(currentPtr+sizeof(TUint8)); |
|
536 return(*(TUint8*)currentPtr); |
|
537 } |
|
538 |
|
539 /** Interprets the data at the current buffer position as a TInt16 type and returns |
|
540 the value as a TInt. |
|
541 |
|
542 The current position within the resource buffer is updated. |
|
543 |
|
544 In general, a TInt16 corresponds to a WORD type in a resource STRUCT declaration. |
|
545 |
|
546 Note that in Symbian OS, a TInt is at least as big as a TInt16. |
|
547 |
|
548 @internalComponent |
|
549 @pre iCurrentPtr != NULL. |
|
550 @pre The same as MovePtrL(const TUint8* aPtr). |
|
551 @return The TInt16 value taken from the resource buffer. |
|
552 @post The same as MovePtrL(const TUint8* aPtr). |
|
553 @leave The same as MovePtrL(const TUint8* aPtr). |
|
554 @panic The same as MovePtrL(const TUint8* aPtr). |
|
555 @panic BAFL 76 iCurrentPtr is NULL. DEBUG build only. |
|
556 @see MovePtrL(const TUint8* aPtr) */ |
|
557 TInt TResourceReaderImpl::ReadInt16L() |
|
558 { |
|
559 __ASSERT_DEBUG(iCurrentPtr != NULL, Panic(EBafPanicNullPtr7)); |
|
560 if (((TUint)iCurrentPtr)%2) |
|
561 { |
|
562 TInt16 ret; |
|
563 ReadL(&ret,sizeof(ret)); |
|
564 return(ret); |
|
565 } |
|
566 const TUint8* currentPtr=iCurrentPtr; |
|
567 MovePtrL(currentPtr+sizeof(TInt16)); |
|
568 return(*(TInt16*)currentPtr); |
|
569 } |
|
570 |
|
571 /** Interprets the data at the current buffer position as a TUint16 type and returns |
|
572 the value as a TUint. |
|
573 |
|
574 The current position within the resource buffer is updated. |
|
575 |
|
576 In general, a TUint16 corresponds to a WORD type in a resource STRUCT declaration. |
|
577 |
|
578 Note that in Symbian OS, a TUint is at least as big as a TUint16. |
|
579 |
|
580 @internalComponent |
|
581 @pre iCurrentPtr != NULL. |
|
582 @pre The same as MovePtrL(const TUint8* aPtr). |
|
583 @return The TUint16 value taken from the resource buffer. |
|
584 @post The same as MovePtrL(const TUint8* aPtr). |
|
585 @leave The same as MovePtrL(const TUint8* aPtr). |
|
586 @panic The same as MovePtrL(const TUint8* aPtr). |
|
587 @panic BAFL 77 iCurrentPtr is NULL. DEBUG build only. |
|
588 @see MovePtrL(const TUint8* aPtr) */ |
|
589 TUint TResourceReaderImpl::ReadUint16L() |
|
590 { |
|
591 __ASSERT_DEBUG(iCurrentPtr != NULL, Panic(EBafPanicNullPtr8)); |
|
592 if (((TUint)iCurrentPtr)%2) |
|
593 { |
|
594 TUint16 ret; |
|
595 ReadL(&ret,sizeof(ret)); |
|
596 return(ret); |
|
597 } |
|
598 const TUint8* currentPtr=iCurrentPtr; |
|
599 MovePtrL(currentPtr+sizeof(TUint16)); |
|
600 return(*(TUint16*)currentPtr); |
|
601 } |
|
602 |
|
603 /** Interprets the data at the current buffer position as a TInt32 type and returns |
|
604 the value as a TInt. |
|
605 |
|
606 The current position within the resource buffer is updated. |
|
607 |
|
608 In general, a TInt32 corresponds to a LONG type in a resource STRUCT declaration. |
|
609 |
|
610 Note that in Symbian OS, TInt and TInt32 are the same size. |
|
611 |
|
612 @internalComponent |
|
613 @pre iCurrentPtr != NULL. |
|
614 @pre The same as MovePtrL(const TUint8* aPtr). |
|
615 @return The TInt32 value taken from the resource buffer. |
|
616 @post The same as MovePtrL(const TUint8* aPtr). |
|
617 @leave The same as MovePtrL(const TUint8* aPtr). |
|
618 @panic The same as MovePtrL(const TUint8* aPtr). |
|
619 @panic BAFL 78 iCurrentPtr is NULL. DEBUG build only. |
|
620 @see MovePtrL(const TUint8* aPtr) */ |
|
621 TInt TResourceReaderImpl::ReadInt32L() |
|
622 { |
|
623 __ASSERT_DEBUG(iCurrentPtr != NULL, Panic(EBafPanicNullPtr9)); |
|
624 if (((TUint)iCurrentPtr)%4) |
|
625 { |
|
626 TInt32 ret; |
|
627 ReadL(&ret,sizeof(ret)); |
|
628 return(ret); |
|
629 } |
|
630 const TUint8* currentPtr=iCurrentPtr; |
|
631 MovePtrL(currentPtr+sizeof(TInt32)); |
|
632 return(*(TInt32*)currentPtr); |
|
633 } |
|
634 |
|
635 /** Interprets the data at the current buffer position as a TUint32 type and returns |
|
636 the value as a TUint. |
|
637 |
|
638 The current position within the resource buffer is updated. |
|
639 |
|
640 In general, a TUint32 corresponds to a LONG type in a resource STRUCT declaration. |
|
641 |
|
642 Note that in Symbian OS a TUint is the same size as a TUint32. |
|
643 |
|
644 @internalComponent |
|
645 @pre iCurrentPtr != NULL. |
|
646 @pre The same as MovePtrL(const TUint8* aPtr). |
|
647 @return The TUint32 value taken from the resource buffer. |
|
648 @post The same as MovePtrL(const TUint8* aPtr). |
|
649 @leave The same as MovePtrL(const TUint8* aPtr). |
|
650 @panic The same as MovePtrL(const TUint8* aPtr). |
|
651 @panic BAFL 79 iCurrentPtr is NULL. DEBUG build only. |
|
652 @see MovePtrL(const TUint8* aPtr) */ |
|
653 TUint TResourceReaderImpl::ReadUint32L() |
|
654 { |
|
655 __ASSERT_DEBUG(iCurrentPtr != NULL, Panic(EBafPanicNullPtr10)); |
|
656 if (((TUint)iCurrentPtr)%4) |
|
657 { |
|
658 TUint32 ret; |
|
659 ReadL(&ret,sizeof(ret)); |
|
660 return(ret); |
|
661 } |
|
662 const TUint8* currentPtr=iCurrentPtr; |
|
663 MovePtrL(currentPtr+sizeof(TUint32)); |
|
664 return(*(TUint32*)currentPtr); |
|
665 } |
|
666 |
|
667 /** Interprets the data at the current buffer position as a TReal64 type and returns |
|
668 the value as a TReal64. |
|
669 |
|
670 The current position within the resource buffer is updated. |
|
671 |
|
672 In general, a TReal64 corresponds to a DOUBLE type in a resource STRUCT declaration. |
|
673 |
|
674 @internalComponent |
|
675 @pre The same as ReadUint32L(). |
|
676 @return The TReal64 value taken from the resource buffer. |
|
677 @post The same as ReadUint32L(). |
|
678 @leave The same as ReadUint32L(). |
|
679 @panic The same as ReadUint32L(). |
|
680 @see ReadUint32L() */ |
|
681 TReal64 TResourceReaderImpl::ReadReal64L() __SOFTFP |
|
682 { |
|
683 union |
|
684 { |
|
685 TReal64 ret; |
|
686 TUint32 tmp[2]; |
|
687 }; |
|
688 #if defined(__DOUBLE_WORDS_SWAPPED__) |
|
689 tmp[1]=ReadUint32L(); |
|
690 tmp[0]=ReadUint32L(); |
|
691 #else |
|
692 tmp[0]=ReadUint32L(); |
|
693 tmp[1]=ReadUint32L(); |
|
694 #endif |
|
695 return(ret); |
|
696 } |
|
697 |
|
698 /** Copies a specified length of data from the resource buffer, starting at the |
|
699 current position within the buffer, into the location pointed to by a specified |
|
700 pointer. No assumption is made about the type of data at being read. |
|
701 |
|
702 The current position within the resource buffer is updated. |
|
703 |
|
704 @internalComponent |
|
705 @pre iCurrentPtr != NULL. |
|
706 @pre The same as MovePtrL(const TUint8* aPtr). |
|
707 @param aPtr Pointer to the target location for data copied from the resource buffer. |
|
708 @param aLength The length of data to be copied from the resource buffer. |
|
709 @post The same as MovePtrL(const TUint8* aPtr). |
|
710 @leave The same as MovePtrL(const TUint8* aPtr). |
|
711 @panic The same as MovePtrL(const TUint8* aPtr). |
|
712 @panic BAFL 80 iCurrentPtr is NULL. DEBUG build only. |
|
713 @see MovePtrL(const TUint8* aPtr) */ |
|
714 void TResourceReaderImpl::ReadL(TAny* aPtr,TInt aLength) |
|
715 { |
|
716 __ASSERT_DEBUG(iCurrentPtr != NULL, Panic(EBafPanicNullPtr11)); |
|
717 const TUint8* currentPtr=iCurrentPtr; |
|
718 MovePtrL(currentPtr+aLength); |
|
719 Mem::Copy(aPtr,currentPtr,aLength); |
|
720 } |
|
721 |
|
722 /** Moves the current buffer position backwards by the specified amount. |
|
723 |
|
724 @internalComponent |
|
725 @pre iCurrentPtr != NULL. |
|
726 @param aLength The length by which the current position is to be moved backward. |
|
727 @post iCurrentPtr is updated. |
|
728 @leave @see MovePtrL(const TUint8* aPtr). |
|
729 @panic BAFL 5 If the resulting position lies before the start of the resource. |
|
730 @panic BAFL 81 iCurrentPtr is NULL. DEBUG build only. |
|
731 @leave KErrArgument The resulting position lies before the start of the resource. */ |
|
732 void TResourceReaderImpl::RewindL(TInt aLength) |
|
733 { |
|
734 __ASSERT_DEBUG(iCurrentPtr != NULL, Panic(EBafPanicNullPtr12)); |
|
735 iAssertObj.AssertRelL(!(aLength>iCurrentPtr-iBuffer->Ptr()),EBafPanicResourceReaderStartExceeded); |
|
736 iCurrentPtr-=aLength; |
|
737 } |
|
738 |
|
739 /** Moves the current buffer position forwards by the specified amount. |
|
740 |
|
741 @internalComponent |
|
742 @pre The same as MovePtrL(const TUint8* aPtr). |
|
743 @param aLength The length by which the current position is to be advanced. |
|
744 @post The same as MovePtrL(const TUint8* aPtr). |
|
745 @leave The same as MovePtrL(const TUint8* aPtr). |
|
746 @panic The same as MovePtrL(const TUint8* aPtr). |
|
747 @panic BAFL 82 iCurrentPtr is NULL. DEBUG build only. |
|
748 @see MovePtrL(const TUint8* aPtr) */ |
|
749 void TResourceReaderImpl::AdvanceL(TInt aLength) |
|
750 { |
|
751 __ASSERT_DEBUG(iCurrentPtr != NULL, Panic(EBafPanicNullPtr13)); |
|
752 MovePtrL(iCurrentPtr+aLength); |
|
753 } |
|
754 |
|
755 /** The method sets a new iAssertObj. |
|
756 If some method is called and something goes wrong - the method either |
|
757 will panics or asserts depending on iAssertObj state. |
|
758 |
|
759 @internalComponent |
|
760 @param aAssertObj The assert object. |
|
761 @post iAssertObj is updated. */ |
|
762 void TResourceReaderImpl::SetAssertObj(const TBaAssert& aAssertObj) |
|
763 { |
|
764 iAssertObj = aAssertObj; |
|
765 } |
|
766 |