Tools.h++ Manual

15-8 104011 Tandem Computers Incorporated
15
15.4 Virtual functions inherited from RWCollection
The Smalltalk-like collection classes inherited from the abstract base class
RWCollection
which, in turn, inherits from the abstract base class
RWCollectable
, described in Chapter 17, “Designing an RWCollectable
Class” (making it is possible to have collections of collections).
An "abstract base class" is a class that is not intended to be used per se, but
rather to be inherited by some other class. Its virtual functions provide a
template of functionality that act as a surrogate for the derived class. The class
RWCollection
is such a class. It provides a template for "collection" classes
by declaring various virtual functions such as
insert()
,
remove()
,
entries()
, etc.
This section describes the virtual functions inherited by all of the Smalltalk-like
collections. Any collection can be expected to understand them.
insert()
virtual RWCollectable* insert(RWCollectable*);
A pointer to an object is put into a collection by using
insert()
. It inserts in
the "most natural way" for the collection. For a stack, this means it is pushed
onto the stack. For a queue, the item is appended to the queue. For a sorted
collection, the item is inserted such that items before it compare less than (or
equal to if duplicates are allowed) itself, items after it compare greater than
itself. See the example in “Example” on page 4 for an example of
insert()
.
find() and friends
virtual RWBoolean contains(const RWCollectable*)
const;
virtual unsigned entries() const;
virtual RWCollectable* find(const RWCollectable*)
const;
virtual RWBoolean isEmpty() const;
virtual unsigned occurrencesOf(const
RWCollectable*) const;