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