RResourceFile Class Reference

class RResourceFile

Accesses a resource file and reads the resource data into a buffer.

Interpretation of the data is achieved using the TResourceReader class.

RResourceFile instance behaviour when some problem occurs - it panics. Or asserts, if the used method is not "L" method.

Expected behaviour when assignment operator or copy constructor is called: The class doesn't have assignment operator and copy constructor, so the compiler generated ones will be used. The heap buffers used by the source class instance will be shared with the destination class instance.

Expected behaviour when the RResourceFile instance is about to be destroyed: The class doesn't have destructor so compiler generated one will be used. Always call Close() to free allocated by the instance resources.

TResourceReader

Public Member Functions
RResourceFile ()
IMPORT_C HBufC8 * AllocReadL ( TInt )
IMPORT_C HBufC8 * AllocReadLC ( TInt )
IMPORT_C void Close ()
IMPORT_C void ConfirmSignatureL ( TInt )
IMPORT_C void ConfirmSignatureL ()
TInt Offset ()
IMPORT_C void OpenL ( RFs &, const TDesC &)
IMPORT_C void OpenL ( RFs &, const TDesC &, TUint , TInt )
IMPORT_C TBool OwnsResourceId ( TInt )
IMPORT_C TBool OwnsResourceIdL ( TInt )
IMPORT_C void ReadL ( TDes8 &, TInt )
IMPORT_C TInt SignatureL ()
IMPORT_C TUidType UidType ()
Private Member Functions
void DoOpenL ( RFs &, const TDesC &, TUint , TInt )
RResourceFileImpl * Impl ()
const RResourceFileImpl * Impl ()
IMPORT_C TInt Offset2 ()
Private Member Enumerations
enum anonymous { KRscFileSize  = 24 }
Private Attributes
TUint8 iImpl

Constructor & Destructor Documentation

RResourceFile()

IMPORT_C RResourceFile ( )

Constructs a default resource file object.

Member Functions Documentation

AllocReadL(TInt)

IMPORT_C HBufC8 * AllocReadL ( TInt aResourceId ) const

Reads a resource into a heap descriptor and returns a pointer to that descriptor.

A heap descriptor of appropriate length is allocated for the resource. Ownership of the heap descriptor passes to the caller who must destroy it when it is no longer needed.

The search for the resource uses the following algorithm:

A resource id in the range 1 to 4095 is looked up in this resource file. The function leaves if there is no matching resource.

If the resource id is greater than 4095, then the most significant 20 bits of the resource id is treated as an offset and the least significant 12 bits is treated as the real resource id. If the offset matches the offset value defined for this file, then the resource is looked up in this resource file using the real resource id (i.e. the least significant 12 bits). If the offset does not match, then the function leaves.

Note, do not call this function until a call to ConfirmSignatureL() has completed successfully.

leave
KErrNotFound - there is no resource with aResourceId in the file.
panic
If the file is corrupted - the method will panic in debug mode.
RResourceFile::Offset() TBafPanic for panic codes.

Parameters

TInt aResourceId The numeric id of the resource to be read.

AllocReadLC(TInt)

IMPORT_C HBufC8 * AllocReadLC ( TInt aResourceId ) const

Reads a resource into a heap descriptor, returns a pointer to that descriptor and pushes the pointer onto the cleanup stack.

A heap descriptor of appropriate length is allocated for the resource. Ownership of the heap descriptor passes to the caller who must destroy it and pop its pointer off the cleanup stack when it is no longer needed.

The search for the resource uses the following algorithm:

A resource id in the range 1 to 4095 is looked up in this resource file. The function leaves if there is no matching resource.

If the resource id is greater than 4095, then the most significant 20 bits of the resource id is treated as an offset and the least significant 12 bits is treated as the real resource id. If the offset matches the offset value defined for this file, then the resource is looked up in this resource file using the real resource id (i.e. the least significant 12 bits). If the offset does not match, then the function leaves.

Note, do not call this function until a call to ConfirmSignatureL() has completed successfully.

leave
KErrNotFound - there is no resource with aResourceId in the file.
panic
If the file is corrupted - the method will panic in debug mode.
RResourceFile::Offset() TBafPanic for panic codes.

Parameters

TInt aResourceId The numeric id of the resource to be read.

Close()

IMPORT_C void Close ( )

Closes the resource file reader. This function is called after finishing reading all resources.

ConfirmSignatureL(TInt)

IMPORT_C void ConfirmSignatureL ( TInt aSignature )

Initialises the offset value from the first resource.

The function assumes that the first resource in the file consists of two 32-bit integers. The first integer contains the version number and the second is a self-referencing link whose value is the offset for the resources in the file, plus 1.This function must be called before calling Offset() , AllocReadL() , AllocReadLC() or ReadL() .

leave
KErrCorrupt - wrong size of the first resource in the file. Probably the file is corrupted.
panic
If the file is corrupted - the method will panic in debug mode.
TBafPanic for panic codes.

Parameters

TInt aSignature This argument value is not used by the function.

ConfirmSignatureL()

IMPORT_C void ConfirmSignatureL ( )

Initialises the offset value from the first resource.

The function tests to catch cases where the first resource is not an RSS_SIGNATURE. It assumes that the first resource in the file consists of two 32-bit integers. The first integer contains the version number and the second is a self-referencing link whose value is the offset for the resources in the file, plus 1.This function must be called before calling Offset() , AllocReadL() , AllocReadLC() or ReadL() .

leave
KErrCorrupt - wrong size of the first resource in the file. Probably the file is corrupted.
panic
If the file is corrupted - the method will panic in debug mode.
TBafPanic for panic codes.

DoOpenL(RFs &, const TDesC &, TUint, TInt)

void DoOpenL ( RFs & aFs,
const TDesC & aName,
TUint aFileOffset,
TInt aFileSize
) [private]

Opens the resource file reader.

leave
The function leaves if the named file cannot be opened or the header record at the beginning of the file cannot be read.
panic
If the file is corrupted - the method will panic in debug mode.
TBafPanic for panic codes.

Parameters

RFs & aFs Handle to a file server session.
const TDesC & aName File to open as a resource file.
TUint aFileOffset Resource file section offset from the beginning of the file.
TInt aFileSize Resource file section size.

Impl()

RResourceFileImpl * Impl ( ) [private]

The method returns a pointer to the object implementing resource file reader functionality.

Impl()

const RResourceFileImpl * Impl ( ) const [private]

The method returns a const pointer to the object implementing resource file reader functionality.

Offset()

TInt Offset ( ) const [inline]

Returns the offset value defined for this resource file.

This function must not be called until a call to ConfirmSignatureL() has completed successfully, otherwise the value returned by this function may be meaningless.

RResourceFile::ConfirmSignatureL()

Offset2()

IMPORT_C TInt Offset2 ( ) const [private]

Returns the offset value defined for this resource file.

This function must not be called until a call to ConfirmSignatureL() has completed successfully, otherwise the value returned by this function may be meaningless.

OpenL(RFs &, const TDesC &)

IMPORT_C void OpenL ( RFs & aFs,
const TDesC & aName
)

Opens the resource file reader.

The resource file reader must be opened before reading resources or checking the signature of the resource file. This function initially closes the resource-file object if it is currently open. If a leave occurs during the function, the object is reverted to its closed state.

leave
The function leaves if the named file cannot be opened or the header record at the beginning of the file cannot be read.
panic
If the file is corrupted - the method will panic in debug mode.
TBafPanic for panic codes.

Parameters

RFs & aFs Handle to a file server session.
const TDesC & aName File to open as a resource file

OpenL(RFs &, const TDesC &, TUint, TInt)

IMPORT_C void OpenL ( RFs & aFs,
const TDesC & aName,
TUint aFileOffset,
TInt aFileSize
)

Opens the resource file reader.

The resource file reader must be opened before reading resources or checking the signature of the resource file. This function initially closes the resource-file object if it is currently open. If a leave occurs during the function, the object is reverted to its closed state.

leave
Function leaves if the named file cannot be opened or the header record at the beginning of the file cannot be read.
panic
If the file is corrupted - the method will panic in debug mode.
TBafPanic for panic codes.

Parameters

RFs & aFs Handle to a file server session
const TDesC & aName File to open as a resource file
TUint aFileOffset Resource file section offset from the beginning of the file.
TInt aFileSize Resource file section size.

OwnsResourceId(TInt)

IMPORT_C TBool OwnsResourceId ( TInt aResourceId ) const

Tests whether the resource file owns the specified resource id.

The resource file owns the resource id if the most significant 20 bits of the resource id are zero or match the offset value as returned from a call to the Offset() member function. Interface is deprecated because it is unsafe as it may leave. RResourceFile::OwnsResourceIdL

Parameters

TInt aResourceId The resource id to test or if the resource id is not out of range.

OwnsResourceIdL(TInt)

IMPORT_C TBool OwnsResourceIdL ( TInt aResourceId ) const

Tests whether the resource file owns the specified resource id.

The resource file owns the resource id if the most significant 20 bits of the resource id are zero or match the offset value as returned from a call to the Offset() member function or if the resource id is not out of range.

panic
If the file is corrupted - the method will panic in debug mode.
TBafPanic for panic codes.

Parameters

TInt aResourceId The resource id to test.

ReadL(TDes8 &, TInt)

IMPORT_C void ReadL ( TDes8 & aDes,
TInt aResourceId
) const

Reads a resource specified by resource id into the specified descriptor.

The descriptor must be long enough to contain the entire resource

The search for the resource uses the following algorithm:

A resource id in the range 1 to 4095 is looked up in this resource file. The function leaves if there is no matching resource.

If the resource id is greater than 4095, then the most significant 20 bits of the resource id is treated as an offset and the least significant 12 bits is treated as the real resource id. If the offset matches the offset value defined for this file, then the resource is looked up in this resource file using the real resource id (i.e. the least significant 12 bits). If the offset does not match, then the function leaves.

Note, do not call this function until a call to ConfirmSignatureL() has completed successfully.

leave
The function leaves if this resource id is not in this resource file.
panic
If the file is corrupted - the method will panic in debug mode.
TBafPanic for panic codes.

Parameters

TDes8 & aDes On return, contains the resource that has been read. The function leaves if the descriptor is not long enough to contain the entire resource.
TInt aResourceId The numeric id of the resource to be read.

SignatureL()

IMPORT_C TInt SignatureL ( ) const

Returns this resource file's version number.

The function assumes that the first resource in the file consists of two 32-bit integers. The first integer contains the version number.

leave
KErrCorrupt Wrong size of the first resource in the file. Probably the file is corrupted.
panic
If the file is corrupted - the method will panic in debug mode.
RResourceFile::ConfirmSignatureL() TBafPanic for panic codes.

UidType()

IMPORT_C TUidType UidType ( ) const

Retrieve the UID tuple of the opened resource file.

Pre-condition
OpenL() has been called successfully.
panic
If the file is not opened or class data members initialization fails - the method will panic always.
TBafPanic for panic codes.

Member Enumerations Documentation

Enum anonymous

Enumerators

KRscFileSize = 24

Member Data Documentation

TUint8 iImpl

TUint8 iImpl [private]