Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

IopcClassFactory Class Reference

Container that stores pointers to functions that can create new instance of / reference to appropriate IopcPersistentObject ancestor. More...

#include <iopcClassFactory.h>

List of all members.

Public Member Functions

 ~IopcClassFactory ()
void addClass (const char *className, IopcPersistentObject *(*createInstance)(), RefBase *(*createReference)())
int getClass (const char *className, IopcPersistentObject *(*&createInstance)(), RefBase *(*&createReference)())

Protected Attributes

void * classFactoryMap


Detailed Description

Container that stores pointers to functions that can create new instance of / reference to appropriate IopcPersistentObject ancestor.

These functions are static, their names are iopcCreateInstance() and iopcCreateReference() and their implementation is generated by IOPC SP.

Class IopcClassFactory has only one instance - iopcClassFactory.

This class doesn't have constructor and doesn't contain any attributes with constructors, so it is possible to call addClass() from constructors of other global objects (space for the class is allocated before any constructor is executed) and initialize the only class's attribute in the first addClass() call. This is done because it is not guaranteed in which order constructors of global objects from different modules will be executed.

The objects from whose constructors is addClass() called are instances of template IopcClassRegistrar.


Constructor & Destructor Documentation

IopcClassFactory::~IopcClassFactory  ) 
 

Destructor. Destroys classFactoryMap.


Member Function Documentation

void IopcClassFactory::addClass const char *  className,
IopcPersistentObject *(*  createInstance)(),
RefBase *(*  createReference)()
 

Adds information about a class to the container.

If called for the first time, allocates a map of type ClassFactoryMap and puts its address into classFactoryMap. First call is distingushed from the value of classFactoryMap - because the only instance of this class is global, in the first call value of this attribute must be NULL.

Always adds information from its parameters to the map.

Note:
If a record for className is present in the container, it is not replaced. If a class is declared in a header which is included into more .cpp files, more IopcClassRegistrar objects will be created and all of them will call this function in their constructors with the same parameters.
Parameters:
className Name of the class to be registered.
createInstance Function that is able to create instances of the class.
createReference Function that is able to create Ref<T> references to the class instances.

int IopcClassFactory::getClass const char *  className,
IopcPersistentObject *(*&  createInstance)(),
RefBase *(*&  createReference)()
 

Finds class specified by className in the container, returns pointers to its iopcCreateInstance() and iopcCreateReference() functions.

Used by IopcClassObjectImpl::createInstance() and IopcClassObjectImpl::createReference().

Parameters:
className Name of the class.
createInstance Function that is able to create instances of the class.
createReference Function that is able to create Ref<T> references to the class instances.


Member Data Documentation

void* IopcClassFactory::classFactoryMap [protected]
 

Map - key = class name, value = pointers to iopcCreateInstance() and iopcCreateReference() functions.

The map must be created dynamically when addClass() is called for the first time (because IopcClassFactory's constructor can be called later - order of global object constructor calls is linker dependent). We know that memory for each global object is zero filled before any constructor call, so we can find out, whether addClass() is called for the first time or not.

Variable is declared as pointer to void because I don't want to include anything from STL in headers that are included into IopcLib.h and probably it isn't possible to make forward declaration of std::map.


The documentation for this class was generated from the following files:
Generated on Wed Aug 11 22:35:33 2004 for IOPC by Doxygen 1.3.6