epoc32/include/barsread.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
     1.1 --- a/epoc32/include/barsread.h	Tue Nov 24 13:55:44 2009 +0000
     1.2 +++ b/epoc32/include/barsread.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -1,1 +1,280 @@
     1.4 -barsread.h
     1.5 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +// All rights reserved.
     1.7 +// This component and the accompanying materials are made available
     1.8 +// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
     1.9 +// which accompanies this distribution, and is available
    1.10 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
    1.11 +//
    1.12 +// Initial Contributors:
    1.13 +// Nokia Corporation - initial contribution.
    1.14 +//
    1.15 +// Contributors:
    1.16 +//
    1.17 +// Description:
    1.18 +//
    1.19 +
    1.20 +#ifndef __BARSREAD_H__
    1.21 +#define __BARSREAD_H__
    1.22 +
    1.23 +#include <e32std.h>
    1.24 +#include <badesca.h>
    1.25 +
    1.26 +class TResourceReaderImpl;
    1.27 +
    1.28 +/** 
    1.29 +Interprets resource data read from a resource file.
    1.30 +
    1.31 +To use an instance of this class, pass the buffer containing the resource 
    1.32 +data to it by calling SetBuffer().
    1.33 +
    1.34 +The buffer containing the resource data is created by RResourceFile::AllocReadLC() or 
    1.35 +RResourceFile::AllocReadL() which reads the specified resource into it.
    1.36 +
    1.37 +The current position within the buffer is always maintained and any request 
    1.38 +for data is always supplied from the current position. The current position 
    1.39 +is always updated .
    1.40 +
    1.41 +@see TResourceReader::SetBuffer()
    1.42 +@see RResourceFile::AllocReadL()
    1.43 +@see RResourceFile::AllocReadLC() 
    1.44 +@publishedAll
    1.45 +@released
    1.46 +*/
    1.47 +class TResourceReader
    1.48 +    {
    1.49 +public:
    1.50 +    IMPORT_C void SetBuffer(const TDesC8* aBuffer);
    1.51 +    IMPORT_C const TAny* Ptr();
    1.52 +
    1.53 +    // Read counted strings into allocated buffer
    1.54 +    inline HBufC*   ReadHBufCL();
    1.55 +    IMPORT_C HBufC8*  ReadHBufC8L();
    1.56 +    IMPORT_C HBufC16* ReadHBufC16L();
    1.57 +
    1.58 +    // Build pointer from a counted string
    1.59 +    inline TPtrC   ReadTPtrC();
    1.60 +    IMPORT_C TPtrC8  ReadTPtrC8();
    1.61 +	IMPORT_C TPtrC16 ReadTPtrC16();
    1.62 +
    1.63 +    // Build pointer from a counted string in an array of counted strings,
    1.64 +    // also setting the buffer to be used.
    1.65 +    inline TPtrC ReadTPtrC(TInt aIndex,const TDesC8* aBuffer);
    1.66 +    IMPORT_C TPtrC8 ReadTPtrC8(TInt aIndex,const TDesC8* aBuffer);
    1.67 +    IMPORT_C TPtrC16 ReadTPtrC16(TInt aIndex,const TDesC8* aBuffer);
    1.68 +
    1.69 +    // Build an array of strings from a resource array
    1.70 +    inline CDesCArrayFlat*   ReadDesCArrayL();
    1.71 +    IMPORT_C CDesC8ArrayFlat*  ReadDesC8ArrayL();
    1.72 +    IMPORT_C CDesC16ArrayFlat* ReadDesC16ArrayL();
    1.73 +
    1.74 +    IMPORT_C TInt ReadInt8();
    1.75 +    IMPORT_C TUint ReadUint8();
    1.76 +    IMPORT_C TInt ReadInt16();
    1.77 +    IMPORT_C TUint ReadUint16();
    1.78 +    IMPORT_C TInt ReadInt32();
    1.79 +    IMPORT_C TUint ReadUint32();
    1.80 +    IMPORT_C TReal64 ReadReal64() __SOFTFP;
    1.81 +
    1.82 +    IMPORT_C void Read(TAny* aPtr,TInt aLength);
    1.83 +    IMPORT_C void Rewind(TInt aLength);
    1.84 +    IMPORT_C void Advance(TInt aLength);
    1.85 +
    1.86 +private:
    1.87 +	void CreateImpl();
    1.88 +	TResourceReaderImpl* Impl();
    1.89 +	const TResourceReaderImpl* Impl() const;
    1.90 +
    1.91 +	TPtrC8 ReadTPtrC8L();
    1.92 +	TPtrC16 ReadTPtrC16L();
    1.93 +	TPtrC8 ReadTPtrC8L(TInt aIndex,const TDesC8* aBuffer);
    1.94 +	TPtrC16 ReadTPtrC16L(TInt aIndex,const TDesC8* aBuffer);
    1.95 +	TInt ReadInt8L();
    1.96 +	TUint ReadUint8L();
    1.97 +	TInt ReadInt16L();
    1.98 +	TUint ReadUint16L();
    1.99 +	TInt ReadInt32L();
   1.100 +	TUint ReadUint32L();
   1.101 +	TReal64 ReadReal64L() __SOFTFP;
   1.102 +
   1.103 +private:
   1.104 +	enum
   1.105 +		{
   1.106 +		KRsReaderSize = 12
   1.107 +		};
   1.108 +	TUint8 iImpl[KRsReaderSize];
   1.109 +    };
   1.110 +
   1.111 +#if defined(_UNICODE)
   1.112 +
   1.113 +/** 
   1.114 +Interprets the data at the current buffer position as leading byte count data 
   1.115 +and constructs a build independent heap descriptor containing a copy of this 
   1.116 +data.
   1.117 +
   1.118 +The data is interpreted as:
   1.119 +
   1.120 +a byte value defining the number of text characters or the length of binary 
   1.121 +data
   1.122 +
   1.123 +followed by:
   1.124 +
   1.125 +the text characters or binary data. This resource data is interpreted as either 
   1.126 +8-bit or 16-bit, depending on the build.
   1.127 +
   1.128 +If the value of the leading byte is zero, the function assumes that no data 
   1.129 +follows the leading byte and returns a NULL pointer.
   1.130 +
   1.131 +The current position within the resource buffer is updated. If the resulting 
   1.132 +position lies beyond the end of the resource buffer, then the function raises 
   1.133 +a BAFL 4 panic.
   1.134 +
   1.135 +Use this build independent variant when the resource contains text. If the 
   1.136 +resource contains binary data, use the explicit 8-bit variant ReadHBufC8L().
   1.137 +
   1.138 +@return A pointer to the heap descriptor containing a copy of the data following 
   1.139 +the leading byte count at the current position within the resource buffer. 
   1.140 +The pointer can be NULL. 
   1.141 +*/
   1.142 +inline HBufC* TResourceReader::ReadHBufCL()
   1.143 +    {
   1.144 +	return ReadHBufC16L();
   1.145 +	}
   1.146 +
   1.147 +/** 
   1.148 +Interprets the data at the current buffer position as leading byte count data 
   1.149 +and constructs a non modifiable pointer descriptor to represent this data.
   1.150 +
   1.151 +The data is interpreted as:
   1.152 +
   1.153 +a byte value defining the number of text characters or the length of binary 
   1.154 +data
   1.155 +
   1.156 +followed by:
   1.157 +
   1.158 +the text characters or binary data. This resource data is interpreted as either 
   1.159 +8-bit or 16-bit, depending on the build.
   1.160 +
   1.161 +If the value of the leading byte is zero, calling Length() on the returned 
   1.162 +TPtrC returns zero.
   1.163 +
   1.164 +The current position within the resource buffer is updated. If the resulting 
   1.165 +position lies beyond the end of the resource buffer, then the function raises 
   1.166 +a BAFL 4 panic.
   1.167 +
   1.168 +Use this build independent variant when the resource contains text. If the 
   1.169 +resource contains binary data, use the explicit 8-bit variant ReadTPtrC8().
   1.170 +
   1.171 +@return A non modifiable pointer descriptor representing the data following 
   1.172 +the leading byte count at the current position within the resource buffer. 
   1.173 +*/
   1.174 +inline TPtrC TResourceReader::ReadTPtrC()
   1.175 +    {
   1.176 +	return ReadTPtrC16();
   1.177 +	}
   1.178 +
   1.179 +/** 
   1.180 +Interprets the data within the specified resource buffer as an array of leading 
   1.181 +byte count data and constructs a non modifiable pointer descriptor to represent 
   1.182 +an element within this array.
   1.183 +
   1.184 +The function sets the buffer containing the resource data and sets the current 
   1.185 +position to the start of this buffer. Any buffer set by a previous call to 
   1.186 +SetBuffer() etc, is lost.
   1.187 +
   1.188 +The buffer is expected to contain an array of data elements preceded by a 
   1.189 +TInt16 value defining the number of elements within that array.
   1.190 +
   1.191 +Each element of the array is interpreted as:
   1.192 +
   1.193 +a byte value defining the number of text characters or the length of binary 
   1.194 +data
   1.195 +
   1.196 +followed by:
   1.197 +
   1.198 +the text characters or binary data. This resource data is interpreted as either 
   1.199 +8-bit or 16-bit, depending on the build.
   1.200 +
   1.201 +If the value of the leading byte is zero, calling Length() on the returned 
   1.202 +TPtrC returns zero.
   1.203 +
   1.204 +The current position within the resource buffer is updated. If the resulting 
   1.205 +position lies beyond the end of the resource buffer, then the function raises 
   1.206 +a BAFL 4 panic.
   1.207 +
   1.208 +Use this build independent variant when the elements contain text. If the 
   1.209 +elements contain binary data, use the explicit 8-bit variant ReadTPtrC8(TInt,const TDesC8*).
   1.210 +
   1.211 +@param aIndex The position of the element within the array. This value is 
   1.212 +relative to zero.
   1.213 +@param aBuffer The buffer containing the resource data.
   1.214 +@return A non modifiable pointer descriptor representing the data following 
   1.215 +the leading byte count of the element at the specified position within the 
   1.216 +array. 
   1.217 +*/
   1.218 +inline TPtrC TResourceReader::ReadTPtrC(TInt aIndex,const TDesC8* aBuffer)
   1.219 +    {
   1.220 +	return ReadTPtrC16(aIndex, aBuffer);
   1.221 +	}
   1.222 +
   1.223 +/** 
   1.224 +Interprets the data at the current buffer position as an array of leading byte 
   1.225 +count data and constructs a build independent flat array of descriptors.
   1.226 +
   1.227 +Each descriptor in the descriptor array corresponds to an element of the resource 
   1.228 +array.
   1.229 +
   1.230 +At the current buffer position, the buffer is expected to contain an array 
   1.231 +of data elements preceded by a TInt16 value defining the number of elements 
   1.232 +within that array.
   1.233 +
   1.234 +Each element of the array is interpreted as:
   1.235 +
   1.236 +a byte value defining the number of text characters or the length of binary 
   1.237 +data
   1.238 +
   1.239 +followed by:
   1.240 +
   1.241 +the text characters or binary data. This resource data is interpreted as either 
   1.242 +8-bit or 16-bit, depending on the build.
   1.243 +
   1.244 +The current position within the resource buffer is updated. If the resulting 
   1.245 +position lies beyond the end of the resource buffer, then the function raises 
   1.246 +a BAFL 4 panic.
   1.247 +
   1.248 +Use this build independent variant when the elements contain text. If the 
   1.249 +elements contain binary data, use the explicit 8-bit variant ReadDesC8ArrayL().
   1.250 +
   1.251 +@return A pointer to a build independent flat descriptor array. 
   1.252 +*/
   1.253 +inline CDesCArrayFlat* TResourceReader::ReadDesCArrayL()
   1.254 +    {
   1.255 +	return ReadDesC16ArrayL();
   1.256 +	}
   1.257 +
   1.258 +#else // defined(_UNICODE)
   1.259 +
   1.260 +inline HBufC* TResourceReader::ReadHBufCL()
   1.261 +    {
   1.262 +	return ReadHBufC8L();
   1.263 +	}
   1.264 +
   1.265 +inline TPtrC TResourceReader::ReadTPtrC()
   1.266 +    {
   1.267 +	return ReadTPtrC8();
   1.268 +	}
   1.269 +
   1.270 +inline TPtrC TResourceReader::ReadTPtrC(TInt aIndex,const TDesC8* aBuffer)
   1.271 +    {
   1.272 +	return ReadTPtrC8(aIndex, aBuffer);
   1.273 +	}
   1.274 +
   1.275 +inline CDesCArrayFlat* TResourceReader::ReadDesCArrayL()
   1.276 +    {
   1.277 +	return ReadDesC8ArrayL();
   1.278 +	}
   1.279 +
   1.280 +#endif// defined(_UNICODE)
   1.281 +
   1.282 +
   1.283 +
   1.284 +#endif//__BARSREAD_H__