Original Symbian headers
Selected EUSER, Window Server, networking, graphics and device declarations
Loading...
Searching...
No Matches
TKey Class Reference

Defines the characteristics of a key used to access the elements of an array. More...

#include <e32std.h>

Inheritance diagram for TKey:
TKeyArrayFix TKeyArrayVar TKeyArrayPak

Public Member Functions

void SetPtr (const TAny *aPtr)
 Sets the pointer to a sample element whose key is to be used for comparison.
 
virtual IMPORT_C TInt Compare (TInt aLeft, TInt aRight) const
 Compares the keys of two array elements.
 
virtual IMPORT_C TAny * At (TInt anIndex) const
 Gets a pointer to the key of a specified array element.
 

Protected Member Functions

IMPORT_C TKey ()
 Protected default constructor.
 
IMPORT_C TKey (TInt aOffset, TKeyCmpText aType)
 Constructs the characteristics of a descriptor type key.
 
IMPORT_C TKey (TInt aOffset, TKeyCmpText aType, TInt aLength)
 Constructs the characteristics of a text key.
 
IMPORT_C TKey (TInt aOffset, TKeyCmpNumeric aType)
 Constructs the characteristics of a numeric key.
 

Protected Attributes

TInt iKeyOffset
 
TInt iKeyLength
 
TInt iCmpType
 
const TAny * iPtr
 

Detailed Description

Defines the characteristics of a key used to access the elements of an array.

The class is abstract and cannot be instantiated. A derived class must be defined and implemented.

The classes TKeyArrayFix, TKeyArrayVar and TKeyArrayPak, derived from TKey, are already supplied to implement keys for the fixed length element, variable length element and packed arrays.

A derived class would normally be written to define the characteristics of a key for a non standard array.

See also
TKeyArrayFix
TKeyArrayVar
TKeyArrayPak
API status
Published to all clients. Released API.

Definition at line 914 of file e32std.h.

Constructor & Destructor Documentation

◆ TKey() [1/4]

IMPORT_C TKey::TKey ( )
protected

Protected default constructor.

This constructor prevents TKey objects from being constructed directly.

(generated from Symbian Developer Library)

◆ TKey() [2/4]

IMPORT_C TKey::TKey ( TInt  aOffset,
TKeyCmpText  aType 
)
protected

Constructs the characteristics of a descriptor type key.

This constructor should be called by the corresponding derived class constructor that takes the same arguments. Typically, the derived class constructor calls this constructor in its constructor initialization list.

No length value is passed as this is implied by the type of key.

Note that the constructor sets the offset value into the protected data member iKeyOffset.

Parameters
aOffsetThe offset of the key from the start of an array element.
aTypeAn enumeration which defines the type of comparison to be made between two descriptor keys.

Panic condition: USER 98, if anOffset is negative.

(generated from Symbian Developer Library)

◆ TKey() [3/4]

IMPORT_C TKey::TKey ( TInt  aOffset,
TKeyCmpText  aType,
TInt  aLength 
)
protected

Constructs the characteristics of a text key.

This constructor should be called by the corresponding derived class constructor that takes the same arguments. Typically, the derived class constructor calls this constructor in its constructor initialization list.

Note that the constructor sets the offset value into the protected data member iKeyOffset.

Parameters
aOffsetThe offset of the key from the start of an array element.
aTypeAn enumeration which defines the type of comparison to be made between two text keys.
aLengthThe length of the text key.

Panic condition: USER 98, if anOffset is negative.

(generated from Symbian Developer Library)

◆ TKey() [4/4]

IMPORT_C TKey::TKey ( TInt  aOffset,
TKeyCmpNumeric  aType 
)
protected

Constructs the characteristics of a numeric key.

This constructor should be called by the corresponding derived class constructor that takes the same arguments. Typically, the derived class constructor calls this constructor in its constructor initialization list.

No length value is passed as this is implied by the type of key.

Note that the constructor sets the offset value into the protected data member iKeyOffset.

Parameters
aOffsetThe offset of the key from the start of an array element.
aTypeAn enumeration which defines the type of the numeric key.

Panic condition: USER 98, if anOffset is negative.

(generated from Symbian Developer Library)

Member Function Documentation

◆ At()

IMPORT_C TAny * TKey::At ( TInt  anIndex) const
virtual

Gets a pointer to the key of a specified array element.

The default implementation raises a USER 35 panic.

The function is called by TKey::Compare() to compare the keys of two elements.

The implementation provided by a derived class must convert the index to a pointer to the key within the corresponding element. The implementation depends on the design of the array but, as general rule, use the index value to get a pointer to the corresponding element and then add the TKey protected data member iKeyOffset to this pointer to get a pointer to the key itself.

By convention, the index value is relative to zero; i.e. a zero value refers to the first element in the array. By this convention, the index can take any value between zero and the number of elements within the array minus one.

The function must also handle the special index value KIndexPtr. When this value is passed, the function should return a pointer to the key within the sample element. A pointer to the sample element is held in the protected data member iPtr and can be set up using SetPtr().

The implementation of this function also assumes that the derived class has a pointer to the array itself or has a function for finding it.

Parameters
anIndexThe index of the array element or the special index value KIndexPtr.

Panic condition: USER 35, if no replacement function has been provided by a derived class.

(generated from Symbian Developer Library)

Reimplemented in TKeyArrayFix, TKeyArrayVar, and TKeyArrayPak.

◆ Compare()

IMPORT_C TInt TKey::Compare ( TInt  aLeft,
TInt  aRight 
) const
virtual

Compares the keys of two array elements.

This function is called by User::BinarySearch() and User::QuickSort().

The position of the elements are identified by the specified index values. The default implementation uses the At() virtual function to convert the index values into pointers to the elements themselves.

The default implementation also uses:

  1. the TDesC comparison functions to compare descriptor type keys
  2. the Mem functions to compare text type keys
  3. numeric comparison for numeric type keys.

User::BinarySearch() User::QuickSort() TDesC Mem

Parameters
aLeftThe index of an array element participating in the comparison, designated the left element.
aRightThe index of an array element participating in the comparison, designated the right element.

(generated from Symbian Developer Library)

◆ SetPtr()

void TKey::SetPtr ( const TAny *  aPtr)
inline

Sets the pointer to a sample element whose key is to be used for comparison.

The element can be in an existing array or it can be located anywhere in addressable memory.

The At() member function supplied by a derived class must return a pointer to this sample element's key when passed an index value of KIndexPtr.

SetPtr() must be called before calling User::BinarySearch() because this algorithm uses the key of this sample element as the basis for searching the array.

Parameters
aPtrA pointer to a sample element.

(generated from Symbian Developer Library)

Member Data Documentation

◆ iCmpType

TInt TKey::iCmpType
protected

Definition at line 928 of file e32std.h.

◆ iKeyLength

TInt TKey::iKeyLength
protected

Definition at line 927 of file e32std.h.

◆ iKeyOffset

TInt TKey::iKeyOffset
protected

Definition at line 926 of file e32std.h.

◆ iPtr

const TAny* TKey::iPtr
protected

Definition at line 929 of file e32std.h.


The documentation for this class was generated from the following files: