williamr@2: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@2: // 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 williamr@2: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // williamr@2: williamr@2: #ifndef __BARSREAD_H__ williamr@2: #define __BARSREAD_H__ williamr@2: williamr@2: #include williamr@2: #include williamr@2: williamr@2: class TResourceReaderImpl; williamr@2: williamr@2: /** williamr@2: Interprets resource data read from a resource file. williamr@2: williamr@2: To use an instance of this class, pass the buffer containing the resource williamr@2: data to it by calling SetBuffer(). williamr@2: williamr@2: The buffer containing the resource data is created by RResourceFile::AllocReadLC() or williamr@2: RResourceFile::AllocReadL() which reads the specified resource into it. williamr@2: williamr@2: The current position within the buffer is always maintained and any request williamr@2: for data is always supplied from the current position. The current position williamr@2: is always updated . williamr@2: williamr@2: @see TResourceReader::SetBuffer() williamr@2: @see RResourceFile::AllocReadL() williamr@2: @see RResourceFile::AllocReadLC() williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class TResourceReader williamr@2: { williamr@2: public: williamr@2: IMPORT_C void SetBuffer(const TDesC8* aBuffer); williamr@2: IMPORT_C const TAny* Ptr(); williamr@2: williamr@2: // Read counted strings into allocated buffer williamr@2: inline HBufC* ReadHBufCL(); williamr@2: IMPORT_C HBufC8* ReadHBufC8L(); williamr@2: IMPORT_C HBufC16* ReadHBufC16L(); williamr@2: williamr@2: // Build pointer from a counted string williamr@2: inline TPtrC ReadTPtrC(); williamr@2: IMPORT_C TPtrC8 ReadTPtrC8(); williamr@2: IMPORT_C TPtrC16 ReadTPtrC16(); williamr@2: williamr@2: // Build pointer from a counted string in an array of counted strings, williamr@2: // also setting the buffer to be used. williamr@2: inline TPtrC ReadTPtrC(TInt aIndex,const TDesC8* aBuffer); williamr@2: IMPORT_C TPtrC8 ReadTPtrC8(TInt aIndex,const TDesC8* aBuffer); williamr@2: IMPORT_C TPtrC16 ReadTPtrC16(TInt aIndex,const TDesC8* aBuffer); williamr@2: williamr@2: // Build an array of strings from a resource array williamr@2: inline CDesCArrayFlat* ReadDesCArrayL(); williamr@2: IMPORT_C CDesC8ArrayFlat* ReadDesC8ArrayL(); williamr@2: IMPORT_C CDesC16ArrayFlat* ReadDesC16ArrayL(); williamr@2: williamr@2: IMPORT_C TInt ReadInt8(); williamr@2: IMPORT_C TUint ReadUint8(); williamr@2: IMPORT_C TInt ReadInt16(); williamr@2: IMPORT_C TUint ReadUint16(); williamr@2: IMPORT_C TInt ReadInt32(); williamr@2: IMPORT_C TUint ReadUint32(); williamr@2: IMPORT_C TReal64 ReadReal64() __SOFTFP; williamr@2: williamr@2: IMPORT_C void Read(TAny* aPtr,TInt aLength); williamr@2: IMPORT_C void Rewind(TInt aLength); williamr@2: IMPORT_C void Advance(TInt aLength); williamr@2: williamr@2: private: williamr@2: void CreateImpl(); williamr@2: TResourceReaderImpl* Impl(); williamr@2: const TResourceReaderImpl* Impl() const; williamr@2: williamr@2: TPtrC8 ReadTPtrC8L(); williamr@2: TPtrC16 ReadTPtrC16L(); williamr@2: TPtrC8 ReadTPtrC8L(TInt aIndex,const TDesC8* aBuffer); williamr@2: TPtrC16 ReadTPtrC16L(TInt aIndex,const TDesC8* aBuffer); williamr@2: TInt ReadInt8L(); williamr@2: TUint ReadUint8L(); williamr@2: TInt ReadInt16L(); williamr@2: TUint ReadUint16L(); williamr@2: TInt ReadInt32L(); williamr@2: TUint ReadUint32L(); williamr@2: TReal64 ReadReal64L() __SOFTFP; williamr@2: williamr@2: private: williamr@2: enum williamr@2: { williamr@2: KRsReaderSize = 12 williamr@2: }; williamr@2: TUint8 iImpl[KRsReaderSize]; williamr@2: }; williamr@2: williamr@2: #if defined(_UNICODE) williamr@2: williamr@2: /** williamr@2: Interprets the data at the current buffer position as leading byte count data williamr@2: and constructs a build independent heap descriptor containing a copy of this williamr@2: data. williamr@2: williamr@2: The data is interpreted as: williamr@2: williamr@2: a byte value defining the number of text characters or the length of binary williamr@2: data williamr@2: williamr@2: followed by: williamr@2: williamr@2: the text characters or binary data. This resource data is interpreted as either williamr@2: 8-bit or 16-bit, depending on the build. williamr@2: williamr@2: If the value of the leading byte is zero, the function assumes that no data williamr@2: follows the leading byte and returns a NULL pointer. williamr@2: williamr@2: The current position within the resource buffer is updated. If the resulting williamr@2: position lies beyond the end of the resource buffer, then the function raises williamr@2: a BAFL 4 panic. williamr@2: williamr@2: Use this build independent variant when the resource contains text. If the williamr@2: resource contains binary data, use the explicit 8-bit variant ReadHBufC8L(). williamr@2: williamr@2: @return A pointer to the heap descriptor containing a copy of the data following williamr@2: the leading byte count at the current position within the resource buffer. williamr@2: The pointer can be NULL. williamr@2: */ williamr@2: inline HBufC* TResourceReader::ReadHBufCL() williamr@2: { williamr@2: return ReadHBufC16L(); williamr@2: } williamr@2: williamr@2: /** williamr@2: Interprets the data at the current buffer position as leading byte count data williamr@2: and constructs a non modifiable pointer descriptor to represent this data. williamr@2: williamr@2: The data is interpreted as: williamr@2: williamr@2: a byte value defining the number of text characters or the length of binary williamr@2: data williamr@2: williamr@2: followed by: williamr@2: williamr@2: the text characters or binary data. This resource data is interpreted as either williamr@2: 8-bit or 16-bit, depending on the build. williamr@2: williamr@2: If the value of the leading byte is zero, calling Length() on the returned williamr@2: TPtrC returns zero. williamr@2: williamr@2: The current position within the resource buffer is updated. If the resulting williamr@2: position lies beyond the end of the resource buffer, then the function raises williamr@2: a BAFL 4 panic. williamr@2: williamr@2: Use this build independent variant when the resource contains text. If the williamr@2: resource contains binary data, use the explicit 8-bit variant ReadTPtrC8(). williamr@2: williamr@2: @return A non modifiable pointer descriptor representing the data following williamr@2: the leading byte count at the current position within the resource buffer. williamr@2: */ williamr@2: inline TPtrC TResourceReader::ReadTPtrC() williamr@2: { williamr@2: return ReadTPtrC16(); williamr@2: } williamr@2: williamr@2: /** williamr@2: Interprets the data within the specified resource buffer as an array of leading williamr@2: byte count data and constructs a non modifiable pointer descriptor to represent williamr@2: an element within this array. williamr@2: williamr@2: The function sets the buffer containing the resource data and sets the current williamr@2: position to the start of this buffer. Any buffer set by a previous call to williamr@2: SetBuffer() etc, is lost. williamr@2: williamr@2: The buffer is expected to contain an array of data elements preceded by a williamr@2: TInt16 value defining the number of elements within that array. williamr@2: williamr@2: Each element of the array is interpreted as: williamr@2: williamr@2: a byte value defining the number of text characters or the length of binary williamr@2: data williamr@2: williamr@2: followed by: williamr@2: williamr@2: the text characters or binary data. This resource data is interpreted as either williamr@2: 8-bit or 16-bit, depending on the build. williamr@2: williamr@2: If the value of the leading byte is zero, calling Length() on the returned williamr@2: TPtrC returns zero. williamr@2: williamr@2: The current position within the resource buffer is updated. If the resulting williamr@2: position lies beyond the end of the resource buffer, then the function raises williamr@2: a BAFL 4 panic. williamr@2: williamr@2: Use this build independent variant when the elements contain text. If the williamr@2: elements contain binary data, use the explicit 8-bit variant ReadTPtrC8(TInt,const TDesC8*). williamr@2: williamr@2: @param aIndex The position of the element within the array. This value is williamr@2: relative to zero. williamr@2: @param aBuffer The buffer containing the resource data. williamr@2: @return A non modifiable pointer descriptor representing the data following williamr@2: the leading byte count of the element at the specified position within the williamr@2: array. williamr@2: */ williamr@2: inline TPtrC TResourceReader::ReadTPtrC(TInt aIndex,const TDesC8* aBuffer) williamr@2: { williamr@2: return ReadTPtrC16(aIndex, aBuffer); williamr@2: } williamr@2: williamr@2: /** williamr@2: Interprets the data at the current buffer position as an array of leading byte williamr@2: count data and constructs a build independent flat array of descriptors. williamr@2: williamr@2: Each descriptor in the descriptor array corresponds to an element of the resource williamr@2: array. williamr@2: williamr@2: At the current buffer position, the buffer is expected to contain an array williamr@2: of data elements preceded by a TInt16 value defining the number of elements williamr@2: within that array. williamr@2: williamr@2: Each element of the array is interpreted as: williamr@2: williamr@2: a byte value defining the number of text characters or the length of binary williamr@2: data williamr@2: williamr@2: followed by: williamr@2: williamr@2: the text characters or binary data. This resource data is interpreted as either williamr@2: 8-bit or 16-bit, depending on the build. williamr@2: williamr@2: The current position within the resource buffer is updated. If the resulting williamr@2: position lies beyond the end of the resource buffer, then the function raises williamr@2: a BAFL 4 panic. williamr@2: williamr@2: Use this build independent variant when the elements contain text. If the williamr@2: elements contain binary data, use the explicit 8-bit variant ReadDesC8ArrayL(). williamr@2: williamr@2: @return A pointer to a build independent flat descriptor array. williamr@2: */ williamr@2: inline CDesCArrayFlat* TResourceReader::ReadDesCArrayL() williamr@2: { williamr@2: return ReadDesC16ArrayL(); williamr@2: } williamr@2: williamr@2: #else // defined(_UNICODE) williamr@2: williamr@2: inline HBufC* TResourceReader::ReadHBufCL() williamr@2: { williamr@2: return ReadHBufC8L(); williamr@2: } williamr@2: williamr@2: inline TPtrC TResourceReader::ReadTPtrC() williamr@2: { williamr@2: return ReadTPtrC8(); williamr@2: } williamr@2: williamr@2: inline TPtrC TResourceReader::ReadTPtrC(TInt aIndex,const TDesC8* aBuffer) williamr@2: { williamr@2: return ReadTPtrC8(aIndex, aBuffer); williamr@2: } williamr@2: williamr@2: inline CDesCArrayFlat* TResourceReader::ReadDesCArrayL() williamr@2: { williamr@2: return ReadDesC8ArrayL(); williamr@2: } williamr@2: williamr@2: #endif// defined(_UNICODE) williamr@2: williamr@2: williamr@2: williamr@2: #endif//__BARSREAD_H__