Rogue Wave Banner

Click on the banner to return to the user guide home page.

©Copyright 1996 Rogue Wave Software

Other Functions Shared by All RWCollections

There are several other functions that are shared by all classes that inherit from RWCollection. Note that these are not virtual functions.

Class Conversions

The following functions allow any collection class to be converted into an RWBag, RWSet, RWOrdered, or a SortedCollection (that is, an RWBinaryTree):

RWBag         asBag() const;
RWSet         asSet() const;
RWOrdered     asOrderedCollection() const;
RWBinaryTree  asSortedCollection() const

Note that since these functions mimic similar Smalltalk methods, they return a copy of the new collection by value. For large collections, this can be very expensive. Consider using operator+=() instead.

Inserting and Removing Other Collections

You can use these functions to respectively insert or remove the contents of their argument.

void  operator+=(const RWCollection&);
void  operator-=(const RWCollection&);

Selection

The function select():

typedef RWBoolean (*RWtestCollectable)(const RWCollectable*,
                   const void*);
RWCollection*     select(RWtestCollectable tst, void*);

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, so you are responsible for deleting it when done.


Previous file Table of Contents Next file