Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWFactory


RWFactory-->RWSet

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

typedef unsigned short  RWClassID;
typedef RWCollectable*  (*RWuserCreator)();
#include <rw/factory.h>

RWFactory* theFactory;

Description

Class RWFactory can create an instance of an RWCollectable object, given a class ID. It does this by maintaining a table of class IDs and associated "creator functions." A creator function has prototype:

RWCollectable*  aCreatorFunction();

This function should create an instance of a particular class. For a given RWClassID tag, the appropriate function is selected, invoked and the resultant pointer returned. Because any object created this way is created off the heap, you are responsible for deleting it when done.

There is a one-of-a-kind global RWFactory which can be accessed using getRWFactory(). It is guaranteed to have creator functions in it for all of the classes referenced by your program. See also the section in the User's Guide about RWFactory.

Persistence

None

Example

#include <rw/factory.h>
#include <rw/rwbag.h>
#include <rw/colldate.h>
#include <rw/rstream.h>

main(){
 // Create new RWBag off the heap, using Class ID __RWBAG.

 RWBag* b = (RWBag*)rwcCreateFromFactory(__RWBAG);

 b->insert( new RWCollectableDate ); // Insert today's date
 // ...
 b->clearAndDestroy();     // Cleanup: first delete members,
 delete b;                 // then the bag itself
}

Public Constructors

RWFactory();

Public Operator

RWBoolean
operator<=(const RWFactory& h);

Public Member Functions

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


Previous fileTop of documentContentsIndexNext file
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.