Add definitions for virtual functions, Below, Add definitions – HP Integrity NonStop J-Series User Manual
Page 219

or:
RWDEFINE_NAMED_COLLECTABLE(Client, "a client")
The first use provides a numeric ID 200 for class Bus, and the second provides a string ID, "a
client", for class Client.
In the remainder of this manual, we use RWDEFINITION_MACRO to indicate that you can choose
either of these macros. In example code, we will pick one or the other macro.
Either macro will automatically supply the definitions for the virtual functions isA() and
newSpecies().
[23]
In the next several sections, we describe these virtual functions, discuss the
stringID() method which is new in Version 7 of Tools.h++, and provide a brief introduction to the
RWFactory
class, which helps implement polymorphic persistence.
Virtual Function isA()
The virtual function isA() returns a class identifier: a unique number that identifies an object's
class. It can be used to determine the class to which an object belongs. Here's the function
declaration provided by macro RWDECLARE_COLLECTABLE:
virtual RWClassID isA() const;
RWClassID is actually a typedef to an unsigned short. Numbers from 0x8000 (hex) and up are
reserved for use by Rogue Wave. You may choose a numeric class ID from 9x0001 to 0x7fff.
There is a set of class symbols defined in
Generally, these follow the pattern of a double underscore followed by the class name with all
letters in upper case. For example:
RWCollectableString yogi;
yogi.isA() == __RWCOLLECTABLESTRING; // Evaluates TRUE
The macro RWDECLARE_COLLECTABLE(className) will automatically provide a declaration
for isA(). Either RWDEFINITION_MACRO will supply the definition.
Virtual Function newSpecies()
The job of this function is to return a pointer to a brand new object of the same type as self. Here is
the function declaration provided by macro RWDECLARE_COLLECTABLE:
virtual RWCollectable* newSpecies() const;
The definition is automatically provided by either version of RWDEFINITION_MACRO.
Function stringID()
The stringID() function acts like a virtual function, but it is not.
[24]
It returns an instance of
RWStringID, a unique string that identifies an object's class. RWStringID is derived from class
RWCString
. By default, the string identifier for a class is the same as the name of the class.
RWStringID can be used instead of, or as a suppplement to, RWClassIDs.