SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
Contains virtual functions for inserting and retrieving pointers to RWCollectable objects into the collection classes. More...
#include <rw/colclass.h>
Public Member Functions | |
virtual | ~RWCollection () |
virtual RWspace | binaryStoreSize () const |
virtual RWClassID | isA () const |
virtual void | restoreGuts (RWvistream &) |
virtual void | restoreGuts (RWFile &) |
virtual void | saveGuts (RWvostream &) const |
virtual void | saveGuts (RWFile &) const |
virtual void | apply (RWapplyCollectable ap, void *vp)=0 |
virtual void | clear ()=0 |
virtual void | clearAndDestroy () |
virtual bool | contains (const RWCollectable *target) const |
virtual size_t | entries () const =0 |
virtual RWCollectable * | find (const RWCollectable *target) const =0 |
virtual RWCollectable * | insert (RWCollectable *e)=0 |
virtual bool | isEmpty () const =0 |
virtual size_t | occurrencesOf (const RWCollectable *t) const =0 |
virtual RWCollectable * | remove (const RWCollectable *target)=0 |
virtual void | removeAndDestroy (const RWCollectable *target) |
virtual RWIterator * | newIterator ()=0 |
virtual RWConstIterator * | newConstIterator () const =0 |
void | operator+= (const RWCollection &c) |
void | operator-= (const RWCollection &c) |
RWBag | asBag () const |
RWOrdered | asOrderedCollection () const |
RWSet | asSet () const |
RWBinaryTree | asSortedCollection () const |
RWBinaryTree | asBinaryTree () const |
RWCollection * | select (RWtestCollectable tst, void *vp) const |
Static Public Attributes | |
static size_t | DEFAULT_CAPACITY |
Related Functions | |
(Note that these are not member functions.) | |
typedef bool(* | RWtestCollectable )(const RWCollectable *, const void *) |
typedef bool(* | RWtestCollectablePair )(const RWCollectable *, const RWCollectable *, const void *) |
typedef void(* | RWapplyCollectable )(RWCollectable *, void *) |
Class RWCollection is an abstract base class for the Smalltalk-like collection classes. The class contains virtual functions for inserting and retrieving pointers to RWCollectable objects into the collection classes. Virtual functions are also provided for storing and reading the collections to files and streams. Collections that inherit this base class typically redefine one or more of these functions.
Several of the methods of this class are abstract. These functions must be defined in derived classes. For these functions the description is intended to be generic -- all inheriting collection classes generally follow the described pattern. Exceptions are noted in the documentation for the particular class.
For many other functions, a suitable definition is provided by RWCollection and a deriving class may not need to redefine the function. Examples are contains() or restoreGuts().
#include <rw/colclass.h> typedef RWCollection Collection; // Smalltalk typedef
Polymorphic
virtual RWCollection::~RWCollection | ( | ) | [virtual] |
Empty destructor.
virtual void RWCollection::apply | ( | RWapplyCollectable | ap, | |
void * | vp | |||
) | [pure virtual] |
This function applies the user-supplied function pointed to by ap to each member of the collection. This function should have the following prototype:
void yourApplyFunction(RWCollectable* ctp, void* vp);
The function yourApplyFunction()
can perform any operation on the item at address ctp
that does not change the hash value or sorting order of the item. Client data may be passed to this function through the second argument vp.
Implemented in RWBinaryTree, RWBTree, RWDlistCollectables, RWHashTable, RWOrdered, RWBag, RWSequenceable, and RWSlistCollectables.
RWBag RWCollection::asBag | ( | ) | const |
Allows any collection to be converted to an RWBag. The return value is a copy of the data. This can be very expensive for large collections. You should consider using operator+=() to insert each item from this collection into a collection of your choice.
RWBinaryTree RWCollection::asBinaryTree | ( | ) | const |
Allows any collection to be converted to an RWBinaryTree. The return value is a copy of the data. This can be very expensive for large collections. You should consider using operator+=() to insert each item from this collection into a collection of your choice.
RWOrdered RWCollection::asOrderedCollection | ( | ) | const |
Allows any collection to be converted to an RWOrdered. The return value is a copy of the data. This can be very expensive for large collections. You should consider using operator+=() to insert each item from this collection into a collection of your choice.
RWSet RWCollection::asSet | ( | ) | const |
Allows any collection to be converted to an RWSet. The return value is a copy of the data. This can be very expensive for large collections. You should consider using operator+=() to insert each item from this collection into a collection of your choice.
RWBinaryTree RWCollection::asSortedCollection | ( | ) | const |
Allows any collection to be converted to an RWBinaryTree. The return value is a copy of the data. This can be very expensive for large collections. You should consider using operator+=() to insert each item from this collection into a collection of your choice.
virtual RWspace RWCollection::binaryStoreSize | ( | ) | const [virtual] |
Returns the number of bytes used by the virtual function saveGuts(RWFile&) to store an object. Typically, this involves adding up the space required to store all primitives, plus the results of calling recursiveStoreSize() for all objects inheriting from RWCollectable. See the Essential Tools Module User's Guide for details.
Reimplemented from RWCollectable.
virtual void RWCollection::clear | ( | ) | [pure virtual] |
Removes all objects from the collection. Does not delete the objects themselves.
Implemented in RWBinaryTree, RWBTreeDictionary, RWBTree, RWDlistCollectables, RWHashDictionary, RWHashTable, RWOrdered, RWBag, RWSequenceable, and RWSlistCollectables.
virtual void RWCollection::clearAndDestroy | ( | ) | [virtual] |
Removes all objects from the collection and deletes them. Takes into account duplicate objects within a collection and only deletes them once. However, it does not take into account objects shared between different collections. Either do not use this function if you are sharing objects between separate collections, or put all collections that could be sharing objects into one single "super-collection" and call clearAndDestroy() on that.
Reimplemented in RWBTreeDictionary, RWHashDictionary, RWBag, and RWSet.
virtual bool RWCollection::contains | ( | const RWCollectable * | target | ) | const [virtual] |
Returns true
if the collection contains an item where the virtual function find() returns non-nil.
Reimplemented in RWDlistCollectables, and RWSlistCollectables.
virtual size_t RWCollection::entries | ( | ) | const [pure virtual] |
Returns the total number of items in the collection.
Implemented in RWBinaryTree, RWBTree, RWDlistCollectables, RWHashTable, RWOrdered, RWBag, RWSequenceable, and RWSlistCollectables.
virtual RWCollectable* RWCollection::find | ( | const RWCollectable * | target | ) | const [pure virtual] |
Returns a pointer to the first item in the collection which "matches" the object pointed to by target or rwnil if no item was found. For most collections, an item "matches" the target if either isEqual() or compareTo() find equivalence, whichever is appropriate for the actual collection type. However, the "identity collections" (i.e., RWIdentitySet and RWIdentityDictionary) look for an item with the same address (i.e., "is identical to").
Implemented in RWBinaryTree, RWBTreeDictionary, RWBTree, RWDlistCollectables, RWHashDictionary, RWHashTable, RWIdentitySet, RWOrdered, RWBag, RWSequenceable, and RWSlistCollectables.
virtual RWCollectable* RWCollection::insert | ( | RWCollectable * | e | ) | [pure virtual] |
Adds an item to the collection and returns a pointer to it. If the item is already in the collection, some collections derived from RWCollection return the old instance, others return rwnil.
Implemented in RWBinaryTree, RWBTree, RWDlistCollectables, RWHashDictionary, RWHashTable, RWIdentitySet, RWOrdered, RWBag, RWSet, RWSequenceable, RWSlistCollectables, RWSortedVector, and RWSlistCollectablesStack.
virtual RWClassID RWCollection::isA | ( | ) | const [inline, virtual] |
Returns __RWCOLLECTION
Reimplemented from RWCollectable.
Reimplemented in RWBinaryTree, RWBTreeDictionary, RWBTree, RWDlistCollectables, RWHashDictionary, RWHashTable, RWIdentityDictionary, RWIdentitySet, RWOrdered, RWSlistCollectablesQueue, RWBag, RWSet, RWSlistCollectables, RWSortedVector, and RWSlistCollectablesStack.
virtual bool RWCollection::isEmpty | ( | ) | const [pure virtual] |
Returns true
if the collection is empty, otherwise returns false
.
Implemented in RWBinaryTree, RWBTree, RWDlistCollectables, RWHashTable, RWOrdered, RWBag, RWSequenceable, and RWSlistCollectables.
virtual RWConstIterator* RWCollection::newConstIterator | ( | ) | const [pure virtual] |
Returns a const pointer to a dynamically allocated iterator for the collection.
Implemented in RWBinaryTree, RWBTree, RWDlistCollectables, RWHashDictionary, RWHashTable, RWOrdered, RWBag, RWSet, and RWSlistCollectables.
virtual RWIterator* RWCollection::newIterator | ( | ) | [pure virtual] |
Returns a dynamically allocated iterator for the collection.
Implemented in RWBinaryTree, RWBTree, RWDlistCollectables, RWHashDictionary, RWHashTable, RWOrdered, RWBag, RWSet, and RWSlistCollectables.
virtual size_t RWCollection::occurrencesOf | ( | const RWCollectable * | t | ) | const [pure virtual] |
Returns the number of items in the collection which are "matches" for t. See function find() for a definition of matches.
Implemented in RWBinaryTree, RWBTree, RWDlistCollectables, RWHashTable, RWOrdered, RWBag, RWSet, RWSequenceable, RWSlistCollectables, and RWSortedVector.
void RWCollection::operator+= | ( | const RWCollection & | c | ) |
Adds each item in c to self. Calling operator+=() on a RWBinaryTree where c is a sorted collection can cause that tree to become unbalanced, possibly to the point of stack overflow.
void RWCollection::operator-= | ( | const RWCollection & | c | ) |
Removes each item in c from self.
virtual RWCollectable* RWCollection::remove | ( | const RWCollectable * | target | ) | [pure virtual] |
Removes and returns a pointer to the first item in the collection which "matches" the object pointed to by target. Returns nil
if no object was found. Does not delete the object. See function find() for a definition of matches.
Implemented in RWBinaryTree, RWBTreeDictionary, RWBTree, RWDlistCollectables, RWHashDictionary, RWHashTable, RWIdentitySet, RWOrdered, RWSlistCollectablesQueue, RWBag, RWSequenceable, RWSlistCollectables, and RWSlistCollectablesStack.
virtual void RWCollection::removeAndDestroy | ( | const RWCollectable * | target | ) | [virtual] |
Removes and deletes the first item in the collection which "matches" the object pointed to by target.
Reimplemented in RWBTreeDictionary, RWHashDictionary, RWSlistCollectablesQueue, RWBag, and RWSlistCollectablesStack.
virtual void RWCollection::restoreGuts | ( | RWFile & | ) | [virtual] |
Repeatedly calls the global operator:
RWFile& operator>>(RWFile&, RWCollectable*&);
followed by insert(RWCollectable*) for each item in the collection.
Reimplemented from RWCollectable.
Reimplemented in RWSlistCollectablesStack.
virtual void RWCollection::restoreGuts | ( | RWvistream & | ) | [virtual] |
Repeatedly calls the global operator:
RWvistream& operator>>(RWvistream&, RWCollectable*&);
followed by insert(RWCollectable*) for each item in the collection.
Reimplemented from RWCollectable.
Reimplemented in RWSlistCollectablesStack.
virtual void RWCollection::saveGuts | ( | RWFile & | ) | const [virtual] |
Calls the global operator:
RWFile& operator<<(RWFile&, const RWCollectable&);
for each object in the collection.
Reimplemented from RWCollectable.
Reimplemented in RWBinaryTree.
virtual void RWCollection::saveGuts | ( | RWvostream & | ) | const [virtual] |
Calls the global operator.
RWvostream& operator<<(RWvostream&, const RWCollectable&);
for each object in the collection.
Reimplemented from RWCollectable.
Reimplemented in RWBinaryTree.
RWCollection* RWCollection::select | ( | RWtestCollectable | tst, | |
void * | vp | |||
) | const |
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 allocated off the heap of the same type as self and returns a pointer to this new collection. Because the new collection is allocated off the heap, you are responsible for deleting it when done. This is not a virtual function.
Reimplemented in RWBTreeDictionary, RWBTreeDictionary, RWHashDictionary, and RWHashDictionary.
typedef void(* RWapplyCollectable)(RWCollectable *, void *) [related] |
A global function used by the apply() method in RWCollection classes to apply a user defined action to an RWCollectable object. A applyCollectable function has prototype:
void RWapplyCollectable(RWCollectable*, void*);
typedef bool(* RWtestCollectable)(const RWCollectable *, const void *) [related] |
A global function used by the select() method in RWCollection classes to test an RWCollectable object for a user defined property. A testCollectable function has prototype:
bool RWtestCollectable(const RWCollectable*, const void*);
typedef bool(* RWtestCollectablePair)(const RWCollectable *, const RWCollectable *, const void *) [related] |
A global function used by the select() method in RWCollection classes to test a pair of RWCollectable objects for a user defined property. A testCollectablePair function has prototype:
bool RWtestCollectablePair(const RWCollectable*, const RWCollectable*, const void*);
size_t RWCollection::DEFAULT_CAPACITY [static] |
The default number of buckets in a RWCollection class.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.