Tools.h++ Manual

17-16 104011 Tandem Computers Incorporated
17
RWvistream& operator>>(RWvistream&, RWCollectable*&);
which will allocate a new object of the proper type off the heap, followed by
insert()
. Because all of the Tools.h++ Smalltalk-like collection classes inherit
from
RWCollection
, they all use this mechanism.
If you decide to write your own collection classes and inherit from class
RWCollection
, you will rarely have to define your own
saveGuts()
or
restoreGuts()
.
There are exceptions. For example, class
RWBinaryTree
has its own version
of
saveGuts()
. This is necessary because the default version of
saveGuts()
stores items “in order”. For a binary tree this would result in a severely
unbalanced tree (essentially, you would get the degenerate case of a linked list)
when the tree was read back in. Hence,
RWBinaryTree
’s version of
saveGuts()
stores the tree level-by-level.
17.11 Summary
In general, you may not have to supply definitions for all of these virtual
functions. For example, if you know that your class will never be used in
sorted collections, then you do not need a definition for
compareTo()
.
Nevertheless, it is a good idea to do it anyway: that’s the best way to
encourage code reuse!
Here then, is the complete listing for our class
Bus
:
BUS.H:
#ifndef __BUS_H__
#define __BUS_H__
#include <rw/rwset.h>
#include <rw/collstr.h>
class Bus : public RWCollectable
{
RWDECLARE_COLLECTABLE(Bus)
public: