glotzutil::ObjectFactory< BaseClassType, UniqueIdType > Class Template Reference
[Utilities]

a generic object factory More...

#include <ObjectFactory.h>

List of all members.

Public Types

typedef std::map
< UniqueIdType,
CreateObjectFunc >
::const_iterator 
ConstIterator
typedef std::map
< UniqueIdType,
CreateObjectFunc >
::iterator 
Iterator

Public Member Functions

template<typename ClassType>
bool Register (UniqueIdType unique_id)
bool Unregister (UniqueIdType unique_id)
BaseClassType * Create (UniqueIdType unique_id)
ConstIterator GetBegin () const
Iterator GetBegin ()
ConstIterator GetEnd () const
Iterator GetEnd ()

Protected Types

typedef BaseClassType *(* CreateObjectFunc )()

Protected Attributes

std::map
< UniqueIdType,
CreateObjectFunc
mObjectCreator


Detailed Description

template<typename BaseClassType, typename UniqueIdType>
class glotzutil::ObjectFactory< BaseClassType, UniqueIdType >

a generic object factory

Author:
Aaron Keys
Note:
This code was taken more or less verbatim from http://www.gamedev.net/reference/articles/article2097.asp .
When reading serialized data from a file, there comes a time when we must create a given object based on a string that was parsed. This is not particularly easy to do without writing large one or more large swich() statements that must appended every time we generate a new class. The ObjectFactory allows us to solve this problem by registering our new class with the factory at run time, allowing us to dynamically create objects in a non-invasive way.

Member Typedef Documentation

template<typename BaseClassType, typename UniqueIdType>
typedef BaseClassType*(* glotzutil::ObjectFactory< BaseClassType, UniqueIdType >::CreateObjectFunc)() [protected]

template<typename BaseClassType, typename UniqueIdType>
typedef std::map<UniqueIdType, CreateObjectFunc>::const_iterator glotzutil::ObjectFactory< BaseClassType, UniqueIdType >::ConstIterator

template<typename BaseClassType, typename UniqueIdType>
typedef std::map<UniqueIdType, CreateObjectFunc>::iterator glotzutil::ObjectFactory< BaseClassType, UniqueIdType >::Iterator


Member Function Documentation

template<typename BaseClassType, typename UniqueIdType>
template<typename ClassType>
bool glotzutil::ObjectFactory< BaseClassType, UniqueIdType >::Register ( UniqueIdType  unique_id  )  [inline]

template<typename BaseClassType, typename UniqueIdType>
bool glotzutil::ObjectFactory< BaseClassType, UniqueIdType >::Unregister ( UniqueIdType  unique_id  )  [inline]

template<typename BaseClassType, typename UniqueIdType>
BaseClassType* glotzutil::ObjectFactory< BaseClassType, UniqueIdType >::Create ( UniqueIdType  unique_id  )  [inline]

template<typename BaseClassType, typename UniqueIdType>
ConstIterator glotzutil::ObjectFactory< BaseClassType, UniqueIdType >::GetBegin (  )  const [inline]

template<typename BaseClassType, typename UniqueIdType>
Iterator glotzutil::ObjectFactory< BaseClassType, UniqueIdType >::GetBegin (  )  [inline]

template<typename BaseClassType, typename UniqueIdType>
ConstIterator glotzutil::ObjectFactory< BaseClassType, UniqueIdType >::GetEnd (  )  const [inline]

template<typename BaseClassType, typename UniqueIdType>
Iterator glotzutil::ObjectFactory< BaseClassType, UniqueIdType >::GetEnd (  )  [inline]


Member Data Documentation

template<typename BaseClassType, typename UniqueIdType>
std::map<UniqueIdType, CreateObjectFunc> glotzutil::ObjectFactory< BaseClassType, UniqueIdType >::mObjectCreator [protected]


The documentation for this class was generated from the following file:
Generated on Tue Feb 24 20:55:04 2009 by  doxygen 1.5.3