Hopsan
ClassFactory< _Key, _Base, _Predicator > Class Template Reference

Template class for automatic object instantiation by key-value. More...

#include <ClassFactory.hpp>

Public Types

enum  RegisterStatusEnumT { RegisteredOk , AllreadyRegistered , NotRegistered }
 
typedef std::vector< std::pair< _Key, int > > RegStatusVectorT
 

Public Member Functions

void registerCreatorFunction (const _Key &rIdKey, CreatorFunctionT classCreator)
 Used to register creator functions.
 
bool reserveKey (const _Key &rIdKey)
 Reserve keyword by inserting NULL ptr,.
 
_Base * createInstance (const _Key &rIdKey)
 Creates an instance based on the key using creator function (if registered)
 
bool hasKey (const _Key &rIdKey) const
 Check if the factory has key registered.
 
const std::vector< _Key > getRegisteredKeys () const
 Return a vector with all registered keys.
 
void unRegisterCreatorFunction (const _Key &rIdKey)
 Unregister creator functions for given key.
 
RegStatusVectorT getRegisterStatus ()
 Get a copy of the internal error vector, it maps key values against error codes, error codes come from registration or unregistration.
 
void clearRegisterStatus ()
 Clears the internal error status vector.
 
void clearFactory ()
 Clear the entire factory map (unregister everything)
 

Protected Types

typedef _Base *(*) CreatorFunctionT(void)
 
typedef std::map< _Key, CreatorFunctionT, _Predicator > FactoryMapT
 
typedef std::pair< _Key, CreatorFunctionT > FactoryPairT
 

Protected Attributes

FactoryMapT mFactoryMap
 Map where the construction info is stored.
 
RegStatusVectorT mRegStatusVector
 Error status map.
 

Detailed Description

template<typename _Key, typename _Base, typename _Predicator = std::less<_Key>>
class hopsan::ClassFactory< _Key, _Base, _Predicator >

Template class for automatic object instantiation by key-value.

This code is based on: http://www.codeproject.com/KB/architecture/SimpleDynCreate.aspx

Member Function Documentation

◆ unRegisterCreatorFunction()

template<typename _Key , typename _Base , typename _Predicator = std::less<_Key>>
void unRegisterCreatorFunction ( const _Key & rIdKey)
inline

Unregister creator functions for given key.