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

Go to the previous, next section.

LinkOb--Link Containing Object Pointer

SYNOPSIS

#include <nihcl/LinkOb.h>

BASE CLASS

Link

DERIVED CLASSES

None

RELATED CLASSES

LinkedList

DESCRIPTION

Class LinkOb is a derived class of Link that adds a member variable (Object* val) to point to an object, called the value object, to be placed on a LinkedList. Since there is no limit on the number of LinkOb instances that can point to an object, they can be used to indirectly link an object on as many LinkedLists as desired.

Using instances of class LinkOb to indirectly link objects on a LinkedList is less efficient than directly linking objects derived from class Link on a LinkedList. You must dereference an additional pointer (which also consumes additional memory) to access an indirectly linked object, and allocating the memory for a separate LinkOb object requires an extra call to the memory allocator.

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

CONSTRUCTORS

LinkOb(Object& newVal =*nil)
Constructs a LinkOb, initializing its value object pointer to newVal.

ACCESSING LINKOBS

virtual Object* value() const
Returns a pointer to the value object of this LinkOb.

virtual Object* value(Object& newVal)
Sets the value object pointer of this LinkOb to newVal, and returns the previous value object pointer.

SEARCHING

virtual unsigned hash() const
Returns the result of applying hash() to the value object of this LinkOb.

COMPARING LINKOBS

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

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

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

TESTING LINKOBS

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

bool LinkOb::isEqual(const Object& ob) const
{
    return ob.isEqual(*val);
}

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

COPYING LINKOBS

virtual void deepenShallowCopy()
Converts this shallow copy to a deep copy by applying deepCopy() to this value object pointer, then replacing the value object pointer with the pointer to its copy.

LINKOB CAPACITY AND SIZE

virtual unsigned capacity() const
virtual unsigned size() const
Returns the result of applying capacity() or size(), respectively, to the value object of this LinkOb.

READING AND PRINTING LINKOBS

virtual void dumpOn(ostream& strm =cerr) const
virtual void printOn(ostream& strm =cout) const
Applies dumpOn(strm) or printOn(strm), respectively, to the value object of this LinkOb.

PROTECTED MEMBERS

Object I/O

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

EXCEPTIONS RAISED

None

Go to the previous, next section.