# BasicDynamicClassFactory Class Reference

Manages dynamic class aggregation. More...

`#include <BasicDynamicClassFactory.h>`

Collaboration diagram for BasicDynamicClassFactory:

[legend]
List of all members.

## Public Member Functions

| BasicDynamicClassFactory ()
void * | create ()
| This function will allocate one contiguous block of memory the size of the sum of the sizes of the registered class nodes.
void | destroy (void *x)
| Deallocate a dynamic class.
unsigned int | getClassSize ()
| The current total size of the dynamic class.
unsigned int | getNumNodes ()
| The current number of nodes in this dynamic class factory.
unsigned int | getNumClasses ()
| The current number of existing instances of the dynamic class.

## Protected Member Functions

void | registerNode (BasicDynamicClassNodeBase *node)
| This function is only callable by BasicDynamicClassNodeBase.

## Private Attributes

unsigned int | classSize
unsigned int | numClasses
BasicArray< BasicDynamicClassNodeBase * > | nodes

## Detailed Description

Manages dynamic class aggregation.

BasicDynamicClassNode(s) can be be registered with an instance of a BasicDynamicClassFactory to create type safe dynamically aggregated classes.

Pros:

- Less memory usage, because the classes are all allocated as one block of memory.
- Data and functionality can be added on the fly allowing pluggins to augment classes after compile time.

Cons:

- Constructors and destructors are never called. This means classes like std::string can not be used as class nodes. Classes can be initialized by overriding BasicDynamicClassNode::init().
- Classes with virtual members cannot be reliably used as class nodes. Virtual classes have an internal pointer to their class virtual table. Unless you can copy this internal pointer virtual classes with not work and may yield unexpected behavior. Assure that there are no virtual functions anywhere in the inheritance tree before registering a class as a dynamic class node.

Don't use this class unless you know why and how to use it.

See also this similar class BasicClassGroupFactory.

## Constructor & Destructor Documentation

BasicDynamicClassFactory::BasicDynamicClassFactory | ( |  | ) |

## Member Function Documentation

void * BasicDynamicClassFactory::create | ( |  | ) |

This function will allocate one contiguous block of memory the size of the sum of the sizes of the registered class nodes.

If the registered class nodes have overridden the BasicDynamicClassNode::init() function it will be called first. WARNING the constructors of the dynamic class nodes are NOT called.

Returns:
  A new instance of the dynamic class.

void BasicDynamicClassFactory::destroy | ( | void * | x | ) |

Deallocate a dynamic class.

WARNING the destructors are NOT called.

Parameters:

  | x | A pointer the the dynamic class do be destroyed.

unsigned int BasicDynamicClassFactory::getClassSize | ( |  | ) | `[inline]`

| The current total size of the dynamic class.

unsigned int BasicDynamicClassFactory::getNumClasses | ( |  | ) | `[inline]`

| The current number of existing instances of the dynamic class.

unsigned int BasicDynamicClassFactory::getNumNodes | ( |  | ) | `[inline]`

| The current number of nodes in this dynamic class factory.

void BasicDynamicClassFactory::registerNode | ( | BasicDynamicClassNodeBase * | node | ) | `[protected]`

| This function is only callable by BasicDynamicClassNodeBase. See BasicDynamicClassNodeBase::registerNode().

## Member Data Documentation

unsigned int BasicDynamicClassFactory::classSize `[private]`

BasicArray<BasicDynamicClassNodeBase *> BasicDynamicClassFactory::nodes `[private]`

unsigned int BasicDynamicClassFactory::numClasses `[private]`

The documentation for this class was generated from the following files:

- BasicDynamicClassFactory.h
- BasicDynamicClassFactory.cpp