beautypg.com

Programming with rwstringids, Implementation details of rwstringid – HP Integrity NonStop J-Series User Manual

Page 274

background image

identifiers, than were possible under the old restriction. To accommodate the new identifiers, a temporary RWClassID
is now generated for each RWCollectable class that has an RWStringID specified by the developer. These
RWClassIDs are built as needed during the run of an executable, and remain constant throughout that run. However,
they may be generated in a different order on a different executable or during a different run, so they are not suitable
for permanent storage.

Programming with RWStringIDs

RWCollectable

now has a new regular member function, and two new static member functions. Since one of the

major goals of Version 7 of Tools.h++ is to maintain link compatibility with objects compiled against Version 6,
none of these functions is virtual. The functions are therefore slightly less efficient than they would be if we broke
link-compatibility.

The new regular member function is:

RWStringID stringID() const;

The new static member functions are:

RWStringID stringID(RWClassID); // looks up RWStringID
RWClassID classID(RWStringID); // looks up classID

RWFactory

also includes the following new functions:

void addFunction(RWuserCreator, RWClassID, RWStringID);
RWCollectable* create(RWStringID) const;
RWuserCreator getFunction(RWStringID) const;
void removeFunction(RWStringID);
RWStringID stringID(RWClassID) const;
RWClassID classID(RWStringID) const;

You can use

RWCollectable

s that ship with Tools.h++ and RWCollectables that have been defined with fixed

RWClassIDs exactly as in previous versions of Tools.h++. For instance, you could still use this common
programming idiom:

RWCollectable *ctp; // assign the pointer
if (ctp->isA() == SOME_CONST_CLASSID) // do a specific thing

However, when you use

RWCollectable

s that have user-provided RWStringIDs, which implies any non-permanent

ClassIDs, you must anticipate that the RWClassID may have different values during different runs of the executable.
For these classes, there are two possible idioms to replace the one above:

RWCollectable *ctp;
// assign the pointer somehow
// use with existing RWCollectable for comparison:
// comparison will be faster than comparing RWStringIDs
if(ctp->isA() == someRWCollectablePtr->isA())
// you may code to that class interface
// ...
// idiom to hard code the identification. Slightly
// slower because string comparisons are slower than int
// comparisons; also stringID() uses a dictionary lookup.
if (ctp->stringID() == "Some ID String") {
// you may code to that class interface
}

This manual is related to the following products: