MAK RTIspy API Documentation for HLA 1.3
Public Types | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
DtPluggableFactory< Key, Product, ProductCreatorParameter > Class Template Reference

The DtPluggableFactory class provides a singleton factory class It returns a shared pointer to the created product objects since the caller takes ownership of the created objects. More...

+ Collaboration diagram for DtPluggableFactory< Key, Product, ProductCreatorParameter >:

List of all members.

Public Types

typedef DtBoost::shared_ptr
< Product > 
DtFactoryProductSP
typedef DtFactoryProductSP(* DtCreatorFn )()
typedef DtFactoryProductSP(* DtParamCreatorFn )(ProductCreatorParameter)
typedef std::map< Key,
DtCreatorFn
DtKeyToCreatorMap
typedef std::map< Key,
DtParamCreatorFn
DtKeyToParamCreatorMap

Static Public Member Functions

static bool isCreatable (const Key &key)
static DtFactoryProductSP create (const Key &key)
 Returns null if no creator available.
static DtFactoryProductSP create (const Key &key, ProductCreatorParameter parameter)
 Returns null if no creator available.
static MAKRti::DtString registerCreator (const Key &key, DtCreatorFn creator)
 Overwrites any previously registered creator for key.
static MAKRti::DtString registerCreator (const Key &key, DtParamCreatorFn creator)
 Overwrites any previously registered creator for key.

Private Member Functions

 DtPluggableFactory ()
 Pluggable factories should not be manually created - they are singletons.
bool productHasCreator (const Key &key)
DtFactoryProductSP createProduct (const Key &key)
DtFactoryProductSP createProduct (const Key &key, ProductCreatorParameter param)
MAKRti::DtString registerProductCreator (const Key &key, DtCreatorFn creator)
MAKRti::DtString registerProductCreator (const Key &key, DtParamCreatorFn creator)

Static Private Member Functions

static DtPluggableFactory< Key,
Product,
ProductCreatorParameter > * 
factory ()

Private Attributes

DtKeyToCreatorMap theCreators
DtKeyToParamCreatorMap theParamCreators

Detailed Description

template<typename Key, typename Product, typename ProductCreatorParameter>
class DtPluggableFactory< Key, Product, ProductCreatorParameter >

The DtPluggableFactory class provides a singleton factory class It returns a shared pointer to the created product objects since the caller takes ownership of the created objects.

Since the Factory is implemented as Template, it may not be used across dll boundaries directly. Instead, the user must create a concrete class that wraps the factory and exists entirely within one dll or execution module (it is not safe within static libraries if multiple dlls may link the library). Ex. In .h: class CreatableBaseClass { public: static CreatableBaseClassSP create( unsigned int key ); protected: typedef DtPluggableFactory< unsigned int, CreatableBaseClass, void > DtFactory; }

In .cxx CreatableBaseClassSP CreatableBaseClass::create( unsigned int key ) { if ( !DtFactory::isCreatable( key ) ) throw DtInvalidFactoryKeyException(); return DtFactory::create( key ); }

NOTE: Since the Factory uses stl containers, all Keys must have full value and comparison semantics (ie - const char* is not a good idea, since it doesn't have operator== for other string types use a class like MAKRti::DtString instead)

The factory may be used as a stand-alone factory. In that case, all product classes must register their creators at runtime. Derive product classes from the DtPluggableFactoryProduct template to ease registration by doing the register at static initialization time.


Member Typedef Documentation

template<typename Key, typename Product, typename ProductCreatorParameter>
typedef DtFactoryProductSP(* DtPluggableFactory< Key, Product, ProductCreatorParameter >::DtCreatorFn)()
template<typename Key, typename Product, typename ProductCreatorParameter>
typedef DtBoost::shared_ptr<Product> DtPluggableFactory< Key, Product, ProductCreatorParameter >::DtFactoryProductSP
template<typename Key, typename Product, typename ProductCreatorParameter>
typedef std::map< Key, DtCreatorFn > DtPluggableFactory< Key, Product, ProductCreatorParameter >::DtKeyToCreatorMap
template<typename Key, typename Product, typename ProductCreatorParameter>
typedef std::map< Key, DtParamCreatorFn > DtPluggableFactory< Key, Product, ProductCreatorParameter >::DtKeyToParamCreatorMap
template<typename Key, typename Product, typename ProductCreatorParameter>
typedef DtFactoryProductSP(* DtPluggableFactory< Key, Product, ProductCreatorParameter >::DtParamCreatorFn)(ProductCreatorParameter)

Constructor & Destructor Documentation

template<typename Key , typename Product , typename ProductCreatorParameter >
DtPluggableFactory< Key, Product, ProductCreatorParameter >::DtPluggableFactory ( ) [private]

Pluggable factories should not be manually created - they are singletons.


Member Function Documentation

template<typename Key , typename Product , typename ProductCreatorParameter >
DtPluggableFactory< Key, Product, ProductCreatorParameter >::DtFactoryProductSP DtPluggableFactory< Key, Product, ProductCreatorParameter >::create ( const Key &  key) [static]

Returns null if no creator available.

Referenced by DtSpyXmlBlock::createChildren().

template<typename Key , typename Product , typename ProductCreatorParameter >
DtPluggableFactory< Key, Product, ProductCreatorParameter >::DtFactoryProductSP DtPluggableFactory< Key, Product, ProductCreatorParameter >::create ( const Key &  key,
ProductCreatorParameter  parameter 
) [static]

Returns null if no creator available.

template<typename Key , typename Product , typename ProductCreatorParameter >
DtPluggableFactory< Key, Product, ProductCreatorParameter >::DtFactoryProductSP DtPluggableFactory< Key, Product, ProductCreatorParameter >::createProduct ( const Key &  key) [private]
template<typename Key , typename Product , typename ProductCreatorParameter >
DtPluggableFactory< Key, Product, ProductCreatorParameter >::DtFactoryProductSP DtPluggableFactory< Key, Product, ProductCreatorParameter >::createProduct ( const Key &  key,
ProductCreatorParameter  param 
) [private]
template<typename Key , typename Product , typename ProductCreatorParameter >
DtPluggableFactory< Key, Product, ProductCreatorParameter > * DtPluggableFactory< Key, Product, ProductCreatorParameter >::factory ( ) [static, private]
template<typename Key , typename Product , typename ProductCreatorParameter >
bool DtPluggableFactory< Key, Product, ProductCreatorParameter >::isCreatable ( const Key &  key) [static]
template<typename Key , typename Product , typename ProductCreatorParameter >
bool DtPluggableFactory< Key, Product, ProductCreatorParameter >::productHasCreator ( const Key &  key) [private]
template<typename Key , typename Product , typename ProductCreatorParameter >
MAKRti::DtString DtPluggableFactory< Key, Product, ProductCreatorParameter >::registerCreator ( const Key &  key,
DtCreatorFn  creator 
) [static]

Overwrites any previously registered creator for key.

template<typename Key , typename Product , typename ProductCreatorParameter >
MAKRti::DtString DtPluggableFactory< Key, Product, ProductCreatorParameter >::registerCreator ( const Key &  key,
DtParamCreatorFn  creator 
) [static]

Overwrites any previously registered creator for key.

template<typename Key , typename Product , typename ProductCreatorParameter >
MAKRti::DtString DtPluggableFactory< Key, Product, ProductCreatorParameter >::registerProductCreator ( const Key &  key,
DtCreatorFn  creator 
) [private]
template<typename Key , typename Product , typename ProductCreatorParameter >
MAKRti::DtString DtPluggableFactory< Key, Product, ProductCreatorParameter >::registerProductCreator ( const Key &  key,
DtParamCreatorFn  creator 
) [private]

Member Data Documentation

template<typename Key, typename Product, typename ProductCreatorParameter>
DtKeyToCreatorMap DtPluggableFactory< Key, Product, ProductCreatorParameter >::theCreators [private]
template<typename Key, typename Product, typename ProductCreatorParameter>
DtKeyToParamCreatorMap DtPluggableFactory< Key, Product, ProductCreatorParameter >::theParamCreators [private]

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

Document ID: Generated on Thu Jun 14 14:15:04 EDT 2012 from SVN revision 116116
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)