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
RWCollectables. 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
RW_DEFINE_COLLECTABLE_CLASS_BY_ID as follows:
RW_DEFINE_COLLECTABLE_CLASS_BY_ID(USER_MODULE,ClassName, ClassID)
RW_DEFINE_COLLECTABLE_CLASS_BY_ID(USER_MODULE,MyCollectable1,0x1000) // for example
You specify a class with a fixed
RWStringID and a generated
RWClassID by using the new macro
RW_DEFINE_COLLECTABLE_CLASS_BY_NAME as follows:
RW_DEFINE_COLLECTABLE_CLASS_BY_NAME(USER_MODULE, ClassName, StringID)
RW_DEFINE_COLLECTABLE_CLASS_BY_NAME(USER_MODULE, 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");