Tools.h++ Manual

15-14 104011 Tandem Computers Incorporated
15
Selection
typedef RWBoolean
(*RWtestCollectable)(const RWCollectable*, const void*);
RWCollection* select(RWtestCollectable tst, void*);
The function
select()
evaluates the function pointed to by
tst
for each item
in the collection. It inserts those items for which the function returns
TRUE
into
a new collection of the same type as self and returns a pointer to it. This new
collection is allocated off the heap, hence you are responsible for deleting it
when done.
15.6 Virtual functions inherited from RWSequenceable
The abstract base class
RWSequenceable
is derived from
RWCollection
.
Collections that inherit from it have an inate ordering. That is, the ordering is
meaningful (unlike, say, a hash table).
virtual RWCollectable*& at(size_t i);
virtual const RWCollectable* at(size_t i) const;
These virtual functions allow access to the i'th item in the collection, similar to
subscripting an array. The compiler choses which function to use on the basis
of whether or not your collection has been declared "const". If it has, the
second variant is used, otherwise the first. The first can be used as an lvalue:
RWOrdered od;
od.insert(new RWCollectableInt(0)); // 0
od.insert(new RWCollectableInt(1)); // 0 1
od.insert(new RWCollectableInt(2)); // 0 1 2
delete od(1); // Use variant available for RWOrdered
od.at(1) = new RWCollectableInt(3); // 0 3 2
These operation are very efficient for the class
RWOrdered
(which is
implemented as a vector) but, as you might expect, relatively inefficient for
classes implemented as a linked-list (the entire list must be traversed in order
to find a particular index).
virtual RWCollectable* first() const;
virtual RWCollectable* last() const;