Go to the previous, next section.
#include <nihcl/LinkOb.h>
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
LinkedList
s 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.
LinkOb(Object&
newVal
=*nil)
LinkOb
, initializing its value object pointer to
newVal.
virtual Object* value() const
LinkOb
.
virtual Object* value(Object&
newVal)
LinkOb
to
newVal, and returns the
previous
value object pointer.
virtual unsigned hash() const
hash()
to the value object of this
LinkOb
.
virtual int compare(const Object&
ob) const
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
.
virtual bool isEqual(const Object&
ob) const
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
.
virtual void deepenShallowCopy()
deepCopy()
to this value object pointer, then replacing the value object pointer with the pointer to its copy.
virtual unsigned capacity() const
virtual unsigned size() const
capacity()
or
size()
, respectively, to the value object of this
LinkOb
.
virtual void dumpOn(ostream&
strm
=cerr) const
virtual void printOn(ostream&
strm
=cout) const
dumpOn(strm)
or
printOn(strm)
, respectively, to the value object of this
LinkOb
.
virtual void storer(OIOofd&
fd) const
virtual void storer(OIOout&
strm) const
LinkOb
to
fd
or
strm
by applying
storeOn()
to the value object.
Go to the previous, next section.