beautypg.com

HP Integrity NonStop J-Series User Manual

Page 228

background image

A Note on the RWFactory

Let's review what the RWDEFINITION_MACROs look like:

RWDEFINE_COLLECTABLE(className, numericID)

or, using a string ID:

RWDEFINE_NAMED_COLLECTABLE(className, stringID)

In the .cpp file for the bus example, the macros appear like this:

RWDEFINE_COLLECTABLE(Bus, 200)

and:

RWDEFINE_NAMED_COLLECTABLE(Client, "a client")

Because you use these macros, a program can allow a new instance of your class to be created
given only its RWClassID:

Bus* newBus = (Bus*)theFactory->create(200);

or its RWStringID:

Client* aClient = (Client*)theFactory->create("a client");

The pointer theFactory is a global pointer that points to a one-of-a-kind global instance of class

RWFactory

, used to hold information about all

RWCollectable

classes that have instances in the

executable. The create() method of RWFactory is used internally by the polymorphic persistence
machinery to create a new instance of a persisted object whose type is not known at run time. You
will not normally use this capability in your own source code, because the use of RWFactory is
generally transparent to the user. See the Class Reference for more details on RWFactory.

This manual is related to the following products: