Rwstringid, Duration of identifiers – HP Integrity NonStop J-Series User Manual
Page 273

Click on the banner to return to the user guide home page.
©Copyright 1996 Rogue Wave Software
RWStringID
Many Rogue Wave clients have asked for a larger range of possible class identifiers for
RWCollectable
classes than is
available using RWClassID. We did not change the meaning of RWClassID, in order to preserve backward
compatibility for existing polymorphically persisted files, but we did add a new kind of class identifier, RWStringID.
An RWStringID is an identifier for
RWCollectable
s in Tools.h++ Version 7 and later. It is derived from
RWCString
,
and may be manipulated by any of the const RWCString methods. The non-const methods have been hidden to
prevent the disaster that could occur if the RWStringID of a class changed at run time.
You can associate an RWStringID with an
RWCollectable
class in one of two ways: pick the RWStringID for the
class, or allow the library to automatically generate an RWStringID that is the same sequence of characters as the
name of the class; for example, class MyColl : public RWCollectable would get the automatic RWStringID
"MyColl".
You specify a class with a fixed RWClassID and generated RWStringID by using the macro
RWDEFINE_COLLECTABLE as follows:
RWDEFINE_COLLECTABLE(ClassName, ClassID)
RWDEFINE_COLLECTABLE(MyCollectable1,0x1000) //for example
You specify a class with a fixed RWStringID and a generated RWClassID by using the new macro
RWDEFINE_NAMED_COLLECTABLE as follows:
RWDEFINE_NAMED_COLLECTABLE(ClassName, StringID)
RWDEFINE_NAMED_COLLECTABLE(MyCollectable2, "Second Collectable") // for example
Using the examples above, you could write:
// First set up the experiment
MyCollectable1 one; MyCollectable2 two;
// All running RWClassIDs are guaranteed distinct
one.isA() != two.isA();
// Every RWCollectable has an RWStringID
one.stringID() == "MyCollectable1";
// There are several ways to find ids
RWCollectable::stringID(0x1000) == "MyCollectable1";
two.isA() == RWCollectable::classID("Second Collectable");
Duration of Identifiers
Providing polymorphic persistence between different executions of the same or different programs requires a
permanent identifier for each class being persisted. Until now, the permanent identifier for any
RWCollectable
has
been its RWClassID. For each class that derives from RWCollectable, the macro RWDEFINE_COLLECTABLE
caused code to be generated that forever associated the class and its RWClassID. This identification has been
retained, but in the current version of Tools.h++ you may choose the RWDEFINE_NAMED_COLLECTABLE
macro, which will permanently link the chosen RWStringID with the class.
The addition of RWStringID identifiers will result in more identifiers, and more self-documenting
RWCollectable