WWC snapshot of http://www.alw.nih.gov/Docs/NIHCL/nihcl_24.html taken on Sat Jun 10 19:13:47 1995

Go to the previous, next section.

LookupKey--Abstract Class for Dictionary Associations

SYNOPSIS

#include <nihcl/LookupKey.h>

BASE CLASS

Object

DERIVED CLASSES

Assoc, AssocInt

RELATED CLASSES

Dictionary, IdentDict, KeySortCltn

DESCRIPTION

Class LookupKey serves as a base class for derived classes such as Assoc and AssocInt that provide associations between key objects and value objects. An instance of class LookupKey holds a pointer to the key object of an association, defines the virtual function key() for accessing the key object of the association, and declares the virtual function value() (which derived classes must implement) for accessing the value object of the association.

Class LookupKey implements the virtual member functions compare(), isEqual(), and hash() by applying the corresponding operation to the key object. Since a LookupKey behaves the same as the key object with respect to these functions, you can substitute a LookupKey in place of its key object for any of these operations.

CONSTRUCTORS

LookupKey(Object& newKey =*nil)
Constructs a LookupKey, initializing its key object pointer to newKey.

ACCESSING LOOKUPKEYS

virtual Object* key() const
Returns a pointer to the key object of this LookupKey.

virtual Object* key(Object& newKey)
Sets the key object pointer of this LookupKey to newKey, and returns the previous key object pointer.

virtual Object* value()
virtual const Object* value() const
Returns a pointer to the value object of this LookupKey. LookupKey::value() is implemented as a derivedClassResponsibility().

virtual Object* value(Object& newValue)
Sets the value object pointer of this LookupKey to newValue, and returns the previous value object pointer. LookupKey::value(Object&) is implemented as a
derivedClassResponsibility().

SEARCHING

virtual unsigned hash() const
Returns the result of applying hash() to the key object of this LookupKey.

COMPARING LOOKUPKEYS

virtual int compare(const Object& ob) const
Returns the negative of the result of applying compare() to the argument object ob with the key object of this LookupKey as the argument to compare(); that is, LookupKey::compare() is implemented as:

int LookupKey::compare(const Object& ob) const
{
    return -ob.compare(*akey);
}

The comparison is done this way to permit ob to be a LookupKey.

TESTING LOOKUPKEYS

virtual bool isEqual(const Object& ob) const
Returns the result of applying isEqual() to the argument object ob with the key object of this LookupKey as the argument to isEqual(); that is, LookupKey::isEqual() is implemented as:

bool LookupKey::isEqual(const Object& ob) const
{
    return ob.isEqual(*akey);
}

The comparison is done this way to permit ob to be a LookupKey.

COPYING LOOKUPKEYS

virtual void deepenShallowCopy()
Converts this shallow copy to a deep copy by applying deepCopy() to the key object pointer of this LookupKey, replacing the key object pointer by the pointer to its copy.

READING AND PRINTING LOOKUPKEYS

virtual void dumpOn(ostream& strm =cerr) const
Prints information about this LookupKey on the output stream strm. Prints the class name of this LookupKey, prints a `[', applies dumpOn() to this LookupKey's key object, prints `=>', applies dumpOn() to this LookupKey's value object, and prints `]\n'.

virtual void printOn(ostream& strm =cout) const
Prints information about this LookupKey on the output stream strm. Applies dumpOn() to this LookupKey's key object, prints `=>', and applies dumpOn() to this LookupKey's value object.

PROTECTED MEMBERS

Object I/O

virtual void storer(OIOofd& fd) const
virtual void storer(OIOout& strm) const
Stores the key object of this LookupKey to fd or strm by applying storeOn() to the key object.

EXCEPTIONS RAISED

None

Go to the previous, next section.