|
1 // Copyright (c) 1997-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 // |
|
15 |
|
16 #ifndef __BARSREAD_H__ |
|
17 #define __BARSREAD_H__ |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <badesca.h> |
|
21 |
|
22 class TResourceReaderImpl; |
|
23 |
|
24 /** |
|
25 Interprets resource data read from a resource file. |
|
26 |
|
27 To use an instance of this class, pass the buffer containing the resource |
|
28 data to it by calling SetBuffer(). |
|
29 |
|
30 The buffer containing the resource data is created by RResourceFile::AllocReadLC() or |
|
31 RResourceFile::AllocReadL() which reads the specified resource into it. |
|
32 |
|
33 The current position within the buffer is always maintained and any request |
|
34 for data is always supplied from the current position. The current position |
|
35 is always updated . |
|
36 |
|
37 @see TResourceReader::SetBuffer() |
|
38 @see RResourceFile::AllocReadL() |
|
39 @see RResourceFile::AllocReadLC() |
|
40 @publishedAll |
|
41 @released |
|
42 */ |
|
43 class TResourceReader |
|
44 { |
|
45 public: |
|
46 IMPORT_C void SetBuffer(const TDesC8* aBuffer); |
|
47 IMPORT_C const TAny* Ptr(); |
|
48 |
|
49 // Read counted strings into allocated buffer |
|
50 inline HBufC* ReadHBufCL(); |
|
51 IMPORT_C HBufC8* ReadHBufC8L(); |
|
52 IMPORT_C HBufC16* ReadHBufC16L(); |
|
53 |
|
54 // Build pointer from a counted string |
|
55 inline TPtrC ReadTPtrC(); |
|
56 IMPORT_C TPtrC8 ReadTPtrC8(); |
|
57 IMPORT_C TPtrC16 ReadTPtrC16(); |
|
58 |
|
59 // Build pointer from a counted string in an array of counted strings, |
|
60 // also setting the buffer to be used. |
|
61 inline TPtrC ReadTPtrC(TInt aIndex,const TDesC8* aBuffer); |
|
62 IMPORT_C TPtrC8 ReadTPtrC8(TInt aIndex,const TDesC8* aBuffer); |
|
63 IMPORT_C TPtrC16 ReadTPtrC16(TInt aIndex,const TDesC8* aBuffer); |
|
64 |
|
65 // Build an array of strings from a resource array |
|
66 inline CDesCArrayFlat* ReadDesCArrayL(); |
|
67 IMPORT_C CDesC8ArrayFlat* ReadDesC8ArrayL(); |
|
68 IMPORT_C CDesC16ArrayFlat* ReadDesC16ArrayL(); |
|
69 |
|
70 IMPORT_C TInt ReadInt8(); |
|
71 IMPORT_C TUint ReadUint8(); |
|
72 IMPORT_C TInt ReadInt16(); |
|
73 IMPORT_C TUint ReadUint16(); |
|
74 IMPORT_C TInt ReadInt32(); |
|
75 IMPORT_C TUint ReadUint32(); |
|
76 IMPORT_C TReal64 ReadReal64() __SOFTFP; |
|
77 |
|
78 IMPORT_C void Read(TAny* aPtr,TInt aLength); |
|
79 IMPORT_C void Rewind(TInt aLength); |
|
80 IMPORT_C void Advance(TInt aLength); |
|
81 |
|
82 private: |
|
83 void CreateImpl(); |
|
84 TResourceReaderImpl* Impl(); |
|
85 const TResourceReaderImpl* Impl() const; |
|
86 |
|
87 TPtrC8 ReadTPtrC8L(); |
|
88 TPtrC16 ReadTPtrC16L(); |
|
89 TPtrC8 ReadTPtrC8L(TInt aIndex,const TDesC8* aBuffer); |
|
90 TPtrC16 ReadTPtrC16L(TInt aIndex,const TDesC8* aBuffer); |
|
91 TInt ReadInt8L(); |
|
92 TUint ReadUint8L(); |
|
93 TInt ReadInt16L(); |
|
94 TUint ReadUint16L(); |
|
95 TInt ReadInt32L(); |
|
96 TUint ReadUint32L(); |
|
97 TReal64 ReadReal64L() __SOFTFP; |
|
98 |
|
99 private: |
|
100 enum |
|
101 { |
|
102 KRsReaderSize = 12 |
|
103 }; |
|
104 TUint8 iImpl[KRsReaderSize]; |
|
105 }; |
|
106 |
|
107 #if defined(_UNICODE) |
|
108 |
|
109 /** |
|
110 Interprets the data at the current buffer position as leading byte count data |
|
111 and constructs a build independent heap descriptor containing a copy of this |
|
112 data. |
|
113 |
|
114 The data is interpreted as: |
|
115 |
|
116 a byte value defining the number of text characters or the length of binary |
|
117 data |
|
118 |
|
119 followed by: |
|
120 |
|
121 the text characters or binary data. This resource data is interpreted as either |
|
122 8-bit or 16-bit, depending on the build. |
|
123 |
|
124 If the value of the leading byte is zero, the function assumes that no data |
|
125 follows the leading byte and returns a NULL pointer. |
|
126 |
|
127 The current position within the resource buffer is updated. If the resulting |
|
128 position lies beyond the end of the resource buffer, then the function raises |
|
129 a BAFL 4 panic. |
|
130 |
|
131 Use this build independent variant when the resource contains text. If the |
|
132 resource contains binary data, use the explicit 8-bit variant ReadHBufC8L(). |
|
133 |
|
134 @return A pointer to the heap descriptor containing a copy of the data following |
|
135 the leading byte count at the current position within the resource buffer. |
|
136 The pointer can be NULL. |
|
137 */ |
|
138 inline HBufC* TResourceReader::ReadHBufCL() |
|
139 { |
|
140 return ReadHBufC16L(); |
|
141 } |
|
142 |
|
143 /** |
|
144 Interprets the data at the current buffer position as leading byte count data |
|
145 and constructs a non modifiable pointer descriptor to represent this data. |
|
146 |
|
147 The data is interpreted as: |
|
148 |
|
149 a byte value defining the number of text characters or the length of binary |
|
150 data |
|
151 |
|
152 followed by: |
|
153 |
|
154 the text characters or binary data. This resource data is interpreted as either |
|
155 8-bit or 16-bit, depending on the build. |
|
156 |
|
157 If the value of the leading byte is zero, calling Length() on the returned |
|
158 TPtrC returns zero. |
|
159 |
|
160 The current position within the resource buffer is updated. If the resulting |
|
161 position lies beyond the end of the resource buffer, then the function raises |
|
162 a BAFL 4 panic. |
|
163 |
|
164 Use this build independent variant when the resource contains text. If the |
|
165 resource contains binary data, use the explicit 8-bit variant ReadTPtrC8(). |
|
166 |
|
167 @return A non modifiable pointer descriptor representing the data following |
|
168 the leading byte count at the current position within the resource buffer. |
|
169 */ |
|
170 inline TPtrC TResourceReader::ReadTPtrC() |
|
171 { |
|
172 return ReadTPtrC16(); |
|
173 } |
|
174 |
|
175 /** |
|
176 Interprets the data within the specified resource buffer as an array of leading |
|
177 byte count data and constructs a non modifiable pointer descriptor to represent |
|
178 an element within this array. |
|
179 |
|
180 The function sets the buffer containing the resource data and sets the current |
|
181 position to the start of this buffer. Any buffer set by a previous call to |
|
182 SetBuffer() etc, is lost. |
|
183 |
|
184 The buffer is expected to contain an array of data elements preceded by a |
|
185 TInt16 value defining the number of elements within that array. |
|
186 |
|
187 Each element of the array is interpreted as: |
|
188 |
|
189 a byte value defining the number of text characters or the length of binary |
|
190 data |
|
191 |
|
192 followed by: |
|
193 |
|
194 the text characters or binary data. This resource data is interpreted as either |
|
195 8-bit or 16-bit, depending on the build. |
|
196 |
|
197 If the value of the leading byte is zero, calling Length() on the returned |
|
198 TPtrC returns zero. |
|
199 |
|
200 The current position within the resource buffer is updated. If the resulting |
|
201 position lies beyond the end of the resource buffer, then the function raises |
|
202 a BAFL 4 panic. |
|
203 |
|
204 Use this build independent variant when the elements contain text. If the |
|
205 elements contain binary data, use the explicit 8-bit variant ReadTPtrC8(TInt,const TDesC8*). |
|
206 |
|
207 @param aIndex The position of the element within the array. This value is |
|
208 relative to zero. |
|
209 @param aBuffer The buffer containing the resource data. |
|
210 @return A non modifiable pointer descriptor representing the data following |
|
211 the leading byte count of the element at the specified position within the |
|
212 array. |
|
213 */ |
|
214 inline TPtrC TResourceReader::ReadTPtrC(TInt aIndex,const TDesC8* aBuffer) |
|
215 { |
|
216 return ReadTPtrC16(aIndex, aBuffer); |
|
217 } |
|
218 |
|
219 /** |
|
220 Interprets the data at the current buffer position as an array of leading byte |
|
221 count data and constructs a build independent flat array of descriptors. |
|
222 |
|
223 Each descriptor in the descriptor array corresponds to an element of the resource |
|
224 array. |
|
225 |
|
226 At the current buffer position, the buffer is expected to contain an array |
|
227 of data elements preceded by a TInt16 value defining the number of elements |
|
228 within that array. |
|
229 |
|
230 Each element of the array is interpreted as: |
|
231 |
|
232 a byte value defining the number of text characters or the length of binary |
|
233 data |
|
234 |
|
235 followed by: |
|
236 |
|
237 the text characters or binary data. This resource data is interpreted as either |
|
238 8-bit or 16-bit, depending on the build. |
|
239 |
|
240 The current position within the resource buffer is updated. If the resulting |
|
241 position lies beyond the end of the resource buffer, then the function raises |
|
242 a BAFL 4 panic. |
|
243 |
|
244 Use this build independent variant when the elements contain text. If the |
|
245 elements contain binary data, use the explicit 8-bit variant ReadDesC8ArrayL(). |
|
246 |
|
247 @return A pointer to a build independent flat descriptor array. |
|
248 */ |
|
249 inline CDesCArrayFlat* TResourceReader::ReadDesCArrayL() |
|
250 { |
|
251 return ReadDesC16ArrayL(); |
|
252 } |
|
253 |
|
254 #else // defined(_UNICODE) |
|
255 |
|
256 inline HBufC* TResourceReader::ReadHBufCL() |
|
257 { |
|
258 return ReadHBufC8L(); |
|
259 } |
|
260 |
|
261 inline TPtrC TResourceReader::ReadTPtrC() |
|
262 { |
|
263 return ReadTPtrC8(); |
|
264 } |
|
265 |
|
266 inline TPtrC TResourceReader::ReadTPtrC(TInt aIndex,const TDesC8* aBuffer) |
|
267 { |
|
268 return ReadTPtrC8(aIndex, aBuffer); |
|
269 } |
|
270 |
|
271 inline CDesCArrayFlat* TResourceReader::ReadDesCArrayL() |
|
272 { |
|
273 return ReadDesC8ArrayL(); |
|
274 } |
|
275 |
|
276 #endif// defined(_UNICODE) |
|
277 |
|
278 |
|
279 |
|
280 #endif//__BARSREAD_H__ |