SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches

Creates an instance of an RWCollectable object, given a class ID. More...

#include <rw/factory.h>

Inheritance diagram for RWFactory:
RWSet RWHashTable RWCollection RWCollectable

Public Member Functions

 RWFactory ()
 
 ~RWFactory ()
 
void addFunction (RWuserCreator uc, RWClassID id)
 
void addFunction (RWuserCreator uc, RWClassID id, RWStringID sid)
 
RWCollectablecreate (RWClassID id) const
 
RWCollectablecreate (RWStringID sid) const
 
RWClassID getClassID (RWStringID sid) const
 
RWuserCreator getFunction (RWClassID id) const
 
RWuserCreator getFunction (RWStringID sid) const
 
RWStringID getStringID (RWClassID id) const
 
bool operator<= (const RWFactory &h)
 
bool operator<= (const RWHashTable &h) const
 
bool operator<= (const RWSet &h) const
 
void removeFunction (RWClassID id)
 
void removeFunction (RWStringID sid)
 
- Public Member Functions inherited from RWSet
 RWSet ()
 
 RWSet (const RWSet &h)
 
 RWSet (RWSet &&h)
 
 RWSet (size_t n)
 
virtual ~RWSet ()
 
virtual void clearAndDestroy ()
 
virtual RWCollectablecopy () const
 
virtual RWCollectableinsert (RWCollectable *c)
 
void intersectWith (const RWSet &h, RWSet &ret) const
 
virtual RWClassID isA () const
 
virtual bool isEqual (const RWCollectable *) const
 
virtual RWConstIteratornewConstIterator () const
 
virtual RWIteratornewIterator ()
 
virtual RWCollectablenewSpecies () const
 
virtual size_t occurrencesOf (const RWCollectable *target) const
 
RWSetoperator*= (const RWSet &h)
 
bool operator< (const RWSet &h) const
 
bool operator<= (const RWSet &h) const
 
RWSetoperator= (const RWSet &h)
 
RWSetoperator= (RWSet &&h)
 
- Public Member Functions inherited from RWHashTable
 RWHashTable ()
 
 RWHashTable (const RWHashTable &t)
 
 RWHashTable (RWHashTable &&t)
 
 RWHashTable (size_t N)
 
virtual void apply (RWapplyCollectable ap, void *)
 
virtual void clear ()
 
virtual size_t entries () const
 
virtual RWCollectablefind (const RWCollectable *) const
 
virtual bool isEmpty () const
 
bool operator!= (const RWHashTable &) const
 
bool operator<= (const RWHashTable &t) const
 
RWHashTableoperator= (const RWHashTable &t)
 
RWHashTableoperator= (RWHashTable &&t)
 
bool operator== (const RWHashTable &t) const
 
virtual RWCollectableremove (const RWCollectable *)
 
virtual void resize (size_t n=0)
 
void swap (RWHashTable &t)
 
- Public Member Functions inherited from RWCollection
virtual ~RWCollection ()
 
RWBag asBag () const
 
RWBinaryTree asBinaryTree () const
 
RWOrdered asOrderedCollection () const
 
RWSet asSet () const
 
RWBinaryTree asSortedCollection () const
 
virtual RWspace binaryStoreSize () const
 
virtual bool contains (const RWCollectable *target) const
 
void operator+= (const RWCollection &c)
 
void operator-= (const RWCollection &c)
 
virtual void removeAndDestroy (const RWCollectable *target)
 
virtual void restoreGuts (RWFile &)
 
virtual void restoreGuts (RWvistream &)
 
virtual void saveGuts (RWFile &) const
 
virtual void saveGuts (RWvostream &) const
 
RWCollectionselect (RWtestCollectable tst, void *vp) const
 
- Public Member Functions inherited from RWCollectable
virtual ~RWCollectable ()
 
virtual int compareTo (const RWCollectable *) const
 
virtual unsigned hash () const
 
RWspace recursiveStoreSize () const
 
RWStringID stringID () const
 

Related Symbols

(Note that these are not member symbols.)

RWFactorygetRWFactory ()
 
typedef RWCollectable *(* RWuserCreator) ()
 

Additional Inherited Members

- Static Public Member Functions inherited from RWCollectable
static RWClassID classID (const RWStringID &name)
 
static RWClassID classIsA ()
 
static bool isAtom (RWClassID id)
 
static RWspace nilStoreSize ()
 
- Static Public Attributes inherited from RWCollection
static size_t DEFAULT_CAPACITY
 

Detailed 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 the prototype:

RWCollectable* aCreatorFunction();
Contains virtual functions for identifying, hashing, comparing, storing and retrieving collectable ob...
Definition collect.h:441

This function creates 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.

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

Synopsis
typedef unsigned short RWClassID;
typedef RWCollectable* (*RWuserCreator)();
#include <rw/factory.h>
RWFactory* theFactory;
Creates an instance of an RWCollectable object, given a class ID.
Definition factory.h:112
unsigned short RWClassID
Definition compat.h:474
Persistence
None
Example
#include <iostream>
#include <rw/factory.h>
#include <rw/rwbag.h>
#include <rw/tools/ctdatetime.h>
int main() {
std::cout << "This program creates an RWBag using theFactory.\n";
// Dummy access to RWBag interface to stimulate
// the registration of RWBag with the factory.
RWBag().clear();
// Create the RWBag instance - use the special rwCreateFromFactory.
RWBag* ptr = (RWBag*)(rwCreateFromFactory(__RWBAG));
if (0 == ptr) {
std::cout << "RWBag instance creation failed.\n";
return 1;
}
std::cout << "RWBag instance has been created.\n";
// Insert today's date
ptr->insert(
std::cout << "RWBag instance contains an instance of "
"RWCollectableDateTime.\n";
// First delete members ...
std::cout << "RWBag instance content cleared.\n";
// ... then the bag itself.
delete ptr;
std::cout << "RWBag instance deleted.\n";
return 0;
}
Corresponds to the Smalltalk class Bag, representing a group of unordered elements not accessible by ...
Definition rwbag.h:65
virtual void clearAndDestroy()
virtual RWCollectable * insert(RWCollectable *c)
virtual void clear()
Provides a polymorphically persistable RWDateTime.
Definition ctdatetime.h:56
@ setCurrentTime
Definition tools/datetime.h:241

Program output:

This program creates an RWBag using theFactory.
RWBag instance has been created.
RWBag instance contains an instance of RWCollectableDateTime.
RWBag instance content cleared.
RWBag instance deleted.

Constructor & Destructor Documentation

◆ RWFactory()

RWFactory::RWFactory ( )

Constructs an RWFactory.

◆ ~RWFactory()

RWFactory::~RWFactory ( )

Calls clearAndDestroy(), which is inherited from RWSet.

Member Function Documentation

◆ addFunction() [1/2]

void RWFactory::addFunction ( RWuserCreator uc,
RWClassID id )

Adds to RWFactory the global function pointed to by uc, which creates an instance of an object with RWClassID id.

◆ addFunction() [2/2]

void RWFactory::addFunction ( RWuserCreator uc,
RWClassID id,
RWStringID sid )

Adds to RWFactory the global function pointed to by uc, which creates an instance of an object with RWClassID id and RWStringID sid.

◆ create() [1/2]

RWCollectable * RWFactory::create ( RWClassID id) const

Allocates a new instance of the class with RWClassID id off the heap and returns a pointer to it. Returns rwnil if id does not exist. Because this instance is allocated off the heap, you are responsible for deleting it when done.

◆ create() [2/2]

RWCollectable * RWFactory::create ( RWStringID sid) const

Allocates a new instance of the class with RWStringID sid off the heap and returns a pointer to it. Returns rwnil if sid does not exist. Because this instance is allocated off the heap, you are responsible for deleting it when done.

◆ getClassID()

RWClassID RWFactory::getClassID ( RWStringID sid) const

Looks up the RWClassID associated with sid and returns it. If there is no such association, returns __RWUNKNOWN.

◆ getFunction() [1/2]

RWuserCreator RWFactory::getFunction ( RWClassID id) const

Returns from RWFactory a pointer to the global function associated with RWClassID id. Returns rwnil if id does not exist.

◆ getFunction() [2/2]

RWuserCreator RWFactory::getFunction ( RWStringID sid) const

Returns from RWFactory a pointer to the global function associated with RWStringID sid. Returns rwnil if sid does not exist.

◆ getStringID()

RWStringID RWFactory::getStringID ( RWClassID id) const

Looks up the RWStringID associated with id and returns it. If there is no such association, returns RWStringID("NoID").

◆ operator<=() [1/3]

bool RWFactory::operator<= ( const RWFactory & h)
inline

Returns true if self is a subset of h, that is, every element of self has a counterpart in h which isEqual().

◆ operator<=() [2/3]

bool RWFactory::operator<= ( const RWHashTable & h) const
inline

Returns true if self is a subset of h, that is, every element of self has a counterpart in h which isEqual().

◆ operator<=() [3/3]

bool RWFactory::operator<= ( const RWSet & h) const
inline

Returns true if self is a subset of h, that is, every element of self has a counterpart in h which isEqual().

◆ removeFunction() [1/2]

void RWFactory::removeFunction ( RWClassID id)

Removes from the RWFactory the global function associated with RWClassID id. If id does not exist in the factory, no action is taken.

◆ removeFunction() [2/2]

void RWFactory::removeFunction ( RWStringID sid)

Removes from RWFactory the global function associated with RWStringID sid. If sid does not exist in the factory, no action is taken.

Friends And Related Symbol Documentation

◆ getRWFactory()

RWFactory * getRWFactory ( )
related

Returns a pointer to the global RWFactory object instance, creating it if necessary.

◆ RWuserCreator

typedef RWCollectable *(* RWuserCreator) ()
related

A global function used to allocate a RWCollectable derived class for RWFactory. A creator function has prototype:

RWCollectable* aCreatorFunction();

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.