Tools.h++ Manual
104011 Tandem Computers Incorporated 17-5
17
17.5 RWDECLARE_/RWDEFINE_COLLECTABLE()
Note – the macro invocation “
RWDECLARE_COLLECTABLE
(className)” in the
declaration for
Bus
. You must put this macro in your class declaration
1
, using
the class name as the argument. This macro automatically inserts declarations
for functions
isA()
and
newSpecies()
.
A corresponding macro “
RWDEFINE_COLLECTABLE
(className, classID)” must
be put in your
.cc
file, using the class name as the first argument, and its
chosen class ID as the second number (see below). It will automatically supply
the definitions for
isA(
) and
newSpecies()
.
Virtual function isA( )
virtual RWClassID isA() const;
The virtual function
isA()
returns a “class ID”, a unique number that
identifies an object’s class. It can be used to determine the class to which an
object belongs. The name "
RWClassID
" is actually a typedef to an
unsigned
short
. Numbers from 0x8000 (hex) and up are reserved for use by Tools.h++.
There is a set of class symbols defined in
<rw/tooldefs.h>
for the Tools.h++
Class Library . 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()
. The macro
RWDEFINE_COLLECTABLE
(className,
classID) will supply the definition.
1. At the time of this writing, this requirement is not being enforced to insure backwards compatibility with
earlier versions of Tools.h++. However, it will be in the future.