|
||
TKey
derived classes
The constructors are used to set the following information:
the key offset
the type of comparison to be made between keys
the length of the key (for text type keys only).
For example:
TKeyDerived::TKeyDerived(TInt anOffset,TKeyCmpText aType)
: TKey(anOffset,aType)
{}
TKeyDerived::TKeyDerived(TInt anOffset,TKeyCmpText aType,TInt aLength)
: TKey(anOffset,aType,aLength)
{}
TKeyDerived::TKeyDerived(TInt anOffset,TKeyCmpNumeric aType)
: TKey(anOffset,aType)
{}
A typical implementation of the virtual function At()
, which gets a pointer to the key of an element corresponding to a given index, might be structured:
TAny* TKeyDerived::At(TInt anIndex) const
{
if (anIndex==KIndexPtr)
{
return((TUint8 *)iPtr+iKeyOffset);
}
//
// code to return a pointer to the key in the appropriate element
//
}
The derived class will need to have a pointer to the array it represents. At the very least, the derived class will need a
data member for this pointer and, possibly, a member function to set it. This is needed in order to implement the At()
function.
TKey
and derived classes use untyped pointers, i.e. pointers of type TAny*
. It may be desirable to provide type safety by further deriving a templated class.