SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches

Contains virtual functions for identifying, hashing, comparing, storing and retrieving collectable objects. More...

#include <rw/collect.h>

Inheritance diagram for RWCollectable:
RWCollectableAssociation RWCollectableDate RWCollectableDateTime RWCollectableInt RWCollectableString RWCollectableTime RWCollectableWString RWCollection RWDBAssignment RWDBBlob RWDBCheckConstraint RWDBCollectableExpr RWDBForeignKey RWDBRow RWDBUniqueConstraint RWDBValue RWModelClient

Public Member Functions

virtual ~RWCollectable ()
 
virtual RWspace binaryStoreSize () const
 
virtual int compareTo (const RWCollectable *) const
 
virtual RWCollectablecopy () const
 
virtual unsigned hash () const
 
virtual RWClassID isA () const
 
virtual bool isEqual (const RWCollectable *t) const
 
virtual RWCollectablenewSpecies () const
 
RWspace recursiveStoreSize () const
 
virtual void restoreGuts (RWFile &)
 
virtual void restoreGuts (RWvistream &)
 
virtual void saveGuts (RWFile &) const
 
virtual void saveGuts (RWvostream &) const
 
RWStringID stringID () const
 

Static Public Member Functions

static RWClassID classID (const RWStringID &name)
 
static RWClassID classIsA ()
 
static bool isAtom (RWClassID id)
 
static RWspace nilStoreSize ()
 

Friends

RWFileoperator<< (RWFile &f, const RWCollectable &obj)
 
RWvostreamoperator<< (RWvostream &v, const RWCollectable &obj)
 
RWFileoperator>> (RWFile &f, RWCollectable &obj)
 
RWFileoperator>> (RWFile &f, RWCollectable *&pCl)
 
RWvistreamoperator>> (RWvistream &s, RWCollectable *&pCl)
 
RWvistreamoperator>> (RWvistream &v, RWCollectable &obj)
 

Detailed Description

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 typically redefine one or more of them.

Synopsis
typedef RWCollectable Object; // Smalltalk typedef
#include <rw/collect.h>
Contains virtual functions for identifying, hashing, comparing, storing and retrieving collectable ob...
Definition collect.h:441
Persistence
Polymorphic

Constructor & Destructor Documentation

◆ ~RWCollectable()

virtual RWCollectable::~RWCollectable ( )
virtual

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.

Member Function Documentation

◆ binaryStoreSize()

virtual RWspace RWCollectable::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 in RWCollectableAssociation, RWCollectableDate, RWCollectableDateTime, RWCollectableInt, RWCollectableString, RWCollectableTime, RWCollectableWString, RWCollection, RWDBBlob, RWDBCheckConstraint, RWDBCollectableExpr, RWDBForeignKey, RWDBRow, RWDBUniqueConstraint, and RWDBValue.

◆ classID()

static RWClassID RWCollectable::classID ( const RWStringID & name)
inlinestatic

Returns the result of looking up the RWClassID associated with name in the global RWFactory.

◆ classIsA()

static RWClassID RWCollectable::classIsA ( )
static

Returns the RWClassID of this class.

◆ compareTo()

virtual int RWCollectable::compareTo ( const RWCollectable * ) const
virtual

The function compareTo() is necessary to sort the items in a collection. If p1 and p2 are pointers to RWCollectable objects, the statement:

p1->compareTo(p2);

should return:

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.

In derived classes, it is recommended that compareTo() first perform ordering on the RWCollectable type (via the isA() method). If both sides are of the same type, then ordering based on the rules for that type should be applied.

Reimplemented in RWCollectableAssociation, RWCollectableDate, RWCollectableDateTime, RWCollectableInt, RWCollectableString, RWCollectableTime, RWCollectableWString, RWDBBlob, RWDBCheckConstraint, RWDBCollectableExpr, RWDBForeignKey, RWDBRow, RWDBUniqueConstraint, and RWDBValue.

◆ copy()

◆ hash()

virtual unsigned RWCollectable::hash ( ) const
virtual

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 that return true to isEqual().

Reimplemented in RWCollectableAssociation, RWCollectableDate, RWCollectableDateTime, RWCollectableInt, RWCollectableString, RWCollectableTime, RWCollectableWString, RWDBBlob, RWDBCheckConstraint, RWDBCollectableExpr, RWDBForeignKey, RWDBRow, RWDBUniqueConstraint, and RWDBValue.

◆ isA()

virtual RWClassID RWCollectable::isA ( ) const
virtual

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.

Reimplemented in RWBag, RWBinaryTree, RWBTree, RWBTreeDictionary, RWCollectableAssociation, RWCollectableDate, RWCollectableDateTime, RWCollectableInt, RWCollectableString, RWCollectableTime, RWCollectableWString, RWCollection, RWDBBlob, RWDBCheckConstraint, RWDBCollectableExpr, RWDBForeignKey, RWDBRow, RWDBUniqueConstraint, RWDBValue, RWDlistCollectables, RWHashDictionary, RWHashTable, RWIdentityDictionary, RWIdentitySet, RWOrdered, RWSet, RWSlistCollectables, RWSlistCollectablesQueue, RWSlistCollectablesStack, and RWSortedVector.

◆ isAtom()

static bool RWCollectable::isAtom ( RWClassID id)
static

Returns true if id is the RWClassID that is associated with an RWCollectable class that has a programmer-chosen RWStringID.

◆ isEqual()

◆ newSpecies()

◆ nilStoreSize()

static RWspace RWCollectable::nilStoreSize ( )
static

Returns the number of bytes required to store an rwnil pointer in an RWFile.

◆ recursiveStoreSize()

RWspace RWCollectable::recursiveStoreSize ( ) const

Returns the number of bytes required to store the object using the global operator:

friend RWvostream & operator<<(RWvostream &v, const RWCollectable &obj)
Definition collect.h:506
Represents an abstraction of a filesystem regular file.
Definition rwfile.h:68

Recursively calls binaryStoreSize(), taking duplicate objects into account.

◆ restoreGuts() [1/2]

◆ restoreGuts() [2/2]

◆ saveGuts() [1/2]

◆ saveGuts() [2/2]

◆ stringID()

RWStringID RWCollectable::stringID ( ) const
inline

Returns the identification string for the class. Acts virtual, although it is not. See the discussion on RWStringID in the Essential Tools Module User's Guide for more information on how to make a non-virtual function act like a virtual function.

Friends And Related Symbol Documentation

◆ operator<< [1/2]

RWFile & operator<< ( RWFile & f,
const RWCollectable & obj )
friend

Saves the object obj to an RWFile. Recursively calls the virtual function saveGuts(), taking duplicate objects into account. See the discussion on Persistence in the Essential Tools Module User's Guide for more information.

◆ operator<< [2/2]

RWvostream & operator<< ( RWvostream & v,
const RWCollectable & obj )
friend

Saves the object obj to a virtual stream. Recursively calls the virtual function saveGuts(), taking duplicate objects into account. See the discussion on Persistence in the Essential Tools Module User's Guide for more information.

◆ operator>> [1/4]

RWFile & operator>> ( RWFile & f,
RWCollectable & obj )
friend

Restores an object inheriting from RWCollectable into obj from an RWFile, replacing the previous contents of obj. Recursively calls the virtual function restoreGuts(), taking duplicate objects into account. For more information, see the discussion on 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).

◆ operator>> [2/4]

RWFile & operator>> ( RWFile & f,
RWCollectable *& pCl )
friend

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, see the discussion on 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). If an exception is thrown during this call, pCl may point to the partly restored object.

◆ operator>> [3/4]

RWvistream & operator>> ( RWvistream & s,
RWCollectable *& pCl )
friend

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, see the discussion on 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). If an exception is thrown during this call, pCl may point to the partly restored object.

◆ operator>> [4/4]

RWvistream & operator>> ( RWvistream & v,
RWCollectable & obj )
friend

Restores an object inheriting from RWCollectable into obj from a virtual stream, replacing the previous contents of obj. Recursively calls the virtual function restoreGuts(), taking duplicate objects into account. For more information, see the discussion on 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).

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.