OBT::PrototypeFactory< TIdentifier, TCreator > Class Template Reference

#include <OBTPrototypeFactory.h>

Collaboration diagram for OBT::PrototypeFactory< TIdentifier, TCreator >:

Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual ~PrototypeFactory ()
 destructor
const TCreator & create (const TIdentifier &classId) const
template<class TDerivedCreator>
bool registerCreator (const TIdentifier &classId)
 register a creator to classId

Private Member Functions

 PrototypeFactory ()
 constructor
 PrototypeFactory (const PrototypeFactory &)
 copy constructor
PrototypeFactoryoperator= (const PrototypeFactory &)
 assignment operator

Private Attributes

std::map
< TIdentifier,
TCreator * > 
_creators
 map of the creators

Friends

class Singleton< PrototypeFactory< TIdentifier, TCreator > >


Detailed Description

template<class TIdentifier, class TCreator>
class OBT::PrototypeFactory< TIdentifier, TCreator >

Template factory prototype class.

Author:
Michaël Rouillé, bunraku <michael.rouille@irisa.fr>
Helper class to provide you access to a template factory implementation. TIdentifier : type of the identifier used to register and retrieve a Creator. TCreator : creation functor ancestor, defines the ancestor class of the family of classes to be created by the factory and its constructor signature.

  // ancestor class creator
        class ACreator
  {
  public:

          // the operator() argument must match A constructor arguments
          virtual A* operator() (       std::string name, unsigned int identifier ) const
          {
                  return NULL ;
          }
  } ;

  // descendants will parametrize this class to register to the prototype factory
  template <class T>
  class ACreatorT : public ACreator
  {
  public:
        
          // this typedef is mandatory
          typedef T object_to_create ;

          // creates and returns a new instance of type T
          A* operator() (       std::string name, unsigned int identifier ) const
          {
                  return new T( name, identifier ) ;
          }
  } ;

Definition at line 69 of file OBTPrototypeFactory.h.


Constructor & Destructor Documentation

template<class TIdentifier, class TCreator>
OBT::PrototypeFactory< TIdentifier, TCreator >::~PrototypeFactory (  )  [inline, virtual]

destructor

Definition at line 114 of file OBTPrototypeFactory.h.

00115 {
00116 }

template<class TIdentifier, class TCreator>
OBT::PrototypeFactory< TIdentifier, TCreator >::PrototypeFactory (  )  [inline, private]

constructor

Definition at line 106 of file OBTPrototypeFactory.h.

00107 {
00108 }

template<class TIdentifier, class TCreator>
OBT::PrototypeFactory< TIdentifier, TCreator >::PrototypeFactory ( const PrototypeFactory< TIdentifier, TCreator > &   )  [private]

copy constructor


Member Function Documentation

template<class TIdentifier, class TCreator>
const TCreator & OBT::PrototypeFactory< TIdentifier, TCreator >::create ( const TIdentifier &  classId  )  const [inline]

returns the creator registered to classId if no creator has been registered TCreator is returned

Definition at line 123 of file OBTPrototypeFactory.h.

References OBT::PrototypeFactory< TIdentifier, TCreator >::_creators.

00124 {
00125         typename std::map< TIdentifier, TCreator* >::const_iterator ite( _creators.find( classId ) ) ;
00126         if( ite != _creators.end() )
00127         {
00128                 return *ite->second ;
00129         }
00130 
00131         static TCreator creator ;
00132         return creator ;
00133 }

template<class TIdentifier, class TCreator>
template<class TDerivedCreator>
bool OBT::PrototypeFactory< TIdentifier, TCreator >::registerCreator ( const TIdentifier &  classId  )  [inline]

register a creator to classId

Definition at line 141 of file OBTPrototypeFactory.h.

References OBT::PrototypeFactory< TIdentifier, TCreator >::_creators.

00142 {
00143         static TDerivedCreator creator ;
00144         _creators[classId] = &creator ;
00145         return true ;
00146 }

template<class TIdentifier, class TCreator>
PrototypeFactory& OBT::PrototypeFactory< TIdentifier, TCreator >::operator= ( const PrototypeFactory< TIdentifier, TCreator > &   )  [private]

assignment operator


Friends And Related Function Documentation

template<class TIdentifier, class TCreator>
friend class Singleton< PrototypeFactory< TIdentifier, TCreator > > [friend]

Definition at line 73 of file OBTPrototypeFactory.h.


Member Data Documentation

template<class TIdentifier, class TCreator>
std::map< TIdentifier, TCreator* > OBT::PrototypeFactory< TIdentifier, TCreator >::_creators [private]

map of the creators

Definition at line 99 of file OBTPrototypeFactory.h.

Referenced by OBT::PrototypeFactory< TIdentifier, TCreator >::create(), and OBT::PrototypeFactory< TIdentifier, TCreator >::registerCreator().


Generated on Wed Oct 1 11:34:18 2008 for OBT by  doxygen 1.5.3