Module: Essential Tools Module Group: RWCollectable
Does not inherit
typedef RWCollectable Object; // Smalltalk typedef #include <rw/collect.h>
Class RWCollectable is an abstract base class for collectable objects. This class contains virtual functions for identifying, hashing, comparing, storing and retrieving collectable objects. While these virtual functions have simple default definitions, objects that inherit this base class will typically redefine one or more of them.
All functions that inherit class RWCollectable have virtual destructors. This allows them to be deleted by such member functions as removeAndDestroy() without knowing their type.
virtual RWspace binaryStoreSize() const;
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 Section entitled "Virtual Function binaryStoreSize" for details.
virtual int compareTo(const RWCollectable*) const;
The function compareTo() is necessary to sort the items in a collection. If p1 and p2 are pointers to RWCollectable objects, the statement
0 if *p1 "is equal to" *p2;
>0 if *p1 is "larger" than *p2;
<0 if *p1 is "smaller" than *p2.
Note that the meaning of "is equal to," "larger" and "smaller" is left to the user. The default definition provided by the base class is based on the addresses, i.e.,
return this == p2 ? 0 : (this > p2 ? 1 : -1);
and is probably not very useful.
virtual unsigned hash() const;
Returns a hash value. This function is necessary for collection classes that use hash table look-up. The default definition provided by the base class hashes the object's address:
It is important that the hash value be the same for all objects which return TRUE to isEqual().
virtual RWClassID isA() const;
Returns a class identification number (with a typedef of unsigned short). The default definition returns __RWCOLLECTABLE. Identification numbers greater than or equal to 0x8000 (hex) are reserved for Rogue Wave objects. User defined classes should define isA() to return a number between 0 and 0x7FFF.
virtual RWBoolean isEqual(const RWCollectable* t) const;
Returns TRUE if collectable object "matches" object at address t. The default definition is:
return this == t;
i.e., both objects have the same address (a test for identity). The definition may be redefined in any consistent way.
virtual RWCollectable* newSpecies() const;
Allocates a new object off the heap of the same type as self and returns a pointer to it. You are responsible for deleting the object when done with it.
virtual void restoreGuts(RWFile&);
Reads an object's state from a binary file, using class RWFile, replacing the previous state.
virtual void restoreGuts(RWvistream&);
Reads an object's state from an input stream, replacing the previous state.
virtual void saveGuts(RWFile&) const;
Writes an object's state to a binary file, using class RWFile.
virtual void saveGuts(RWvostream&) const;
Writes an object's state to an output stream.
Returns the identification string for the class. Acts virtual, although it is not. See "Section 12.3, "RWStringID," in the User's Guide for more information on how to make a non-virtual function act like a virtual function.
RWspace recursiveStoreSize() const;
Returns the number of bytes required to store the object using the global operator:
RWFile& operator<<(RWFile&, const RWCollectable&);
Recursively calls binaryStoreSize(), taking duplicate objects into account.
static RWClassID classID(const RWStringID& name);
Returns the result of looking up the RWClassID associated with name in the global RWFactory.
static RWClassID classIsA();
Returns the RWClassID of this class.
static RWBoolean isAtom(RWClassID id);
Returns TRUE if id is the RWClassID that is associated with an RWCollectable class that has a programmer-chosen RWStringID.
static RWspace nilStoreSize();
Returns the number of bytes required to store a rwnil pointer in an RWFile.
RWvostream& operator<<(RWvostream&, const RWCollectable& obj); RWFile& operator<<(RWFile&, const RWCollectable& obj);
Saves the object obj to a virtual stream or RWFile, respectively. Recursively calls the virtual function saveGuts(), taking duplicate objects into account. See the Essential Tools Module User's Guide section entitled "Persistence" for more information.
RWvistream& operator>>(RWvistream&, RWCollectable& obj); RWFile& operator>>(RWFile&, RWCollectable& obj);
Restores an object inheriting from RWCollectable into obj from a virtual stream or RWFile, respectively, replacing the previous contents of obj. Recursively calls the virtual function restoreGuts(), taking duplicate objects into account. For more information, Chapter 9, "Persistence," in the Essential Tools Module User's Guide. Various exceptions that could be thrown are RWInternalErr (if the RWFactory does not know how to make the object), and RWExternalErr (corrupted stream or file).
RWvistream& operator>>(RWvistream&, RWCollectable*& obj); RWFile& operator>>(RWFile&, RWCollectable*& obj);
Looks at the next object on the input stream or RWFile, respectively, and either creates a new object of the proper type off the heap and returns a pointer to it, or else returns a pointer to a previously read instance. Recursively calls the virtual function restoreGuts(), taking duplicate objects into account. If an object is created off the heap, then you are responsible for deleting it. For more information, Chapter 9, "Persistence," in the Essential Tools Module User's Guide. Various exceptions that could be thrown are RWInternalErr (if the RWFactory does not know how to make the object), and RWExternalErr (corrupted stream or file). In case an exception is thrown during this call, the pointer to the partly restored object will probably be lost, and memory will leak. For this reason, you may prefer to use the static methods tryRecursiveRestore() documented above.
©2004 Copyright Quovadx, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Quovadx, 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.