QwAnalysis
VQwFactory< base_t > Class Template Referenceabstract

Pure virtual factory. More...

#include <QwFactory.h>

+ Inheritance diagram for VQwFactory< base_t >:

Public Member Functions

virtual ~VQwFactory ()
 Default virtual destructor. More...
 
virtual base_t * Create (const std::string &name) const =0
 Creation of objects by type (pure virtual) More...
 
virtual base_t * Cast (base_t *base) const =0
 Dynamic cast to type (pure virtual) More...
 

Static Public Member Functions

static base_t * Create (const std::string &type, const std::string &name)
 Create an object of type with name. More...
 
static base_t * Cast (base_t *base, const std::string &type)
 Dynamic cast of object into type. More...
 
static bool InheritsFrom (base_t *base, const std::string &type)
 Test whether object inherits from type. More...
 

Static Protected Member Functions

static std::map< std::string,
VQwFactory * > & 
GetRegisteredTypes ()
 Map from string to concrete type factories. More...
 
static void ListRegisteredTypes ()
 List available type factories. More...
 
static VQwFactoryGetFactory (const std::string &type)
 Get a concrete type factory by string. More...
 

Detailed Description

template<class base_t>
class VQwFactory< base_t >

Pure virtual factory.

In order to enable the instantiation of types based on run-time information, we generate a map of type factories by type name. This map is filled automatically when the executable is loaded, and contains concrete factories derived from this pure virtual base class.

Definition at line 33 of file QwFactory.h.

Constructor & Destructor Documentation

template<class base_t>
virtual VQwFactory< base_t >::~VQwFactory ( )
inlinevirtual

Default virtual destructor.

Definition at line 38 of file QwFactory.h.

38 { }

Member Function Documentation

template<class base_t>
static base_t* VQwFactory< base_t >::Cast ( base_t *  base,
const std::string &  type 
)
inlinestatic

Dynamic cast of object into type.

Definition at line 46 of file QwFactory.h.

Referenced by VQwFactory< VQwDataElement >::Cast(), and VQwFactory< VQwDataElement >::InheritsFrom().

46  {
47  return GetFactory(type)->Cast(base);
48  }
static base_t * Cast(base_t *base, const std::string &type)
Dynamic cast of object into type.
Definition: QwFactory.h:46
static VQwFactory * GetFactory(const std::string &type)
Get a concrete type factory by string.
Definition: QwFactory.h:76

+ Here is the caller graph for this function:

template<class base_t>
virtual base_t* VQwFactory< base_t >::Cast ( base_t *  base) const
pure virtual
template<class base_t>
static base_t* VQwFactory< base_t >::Create ( const std::string &  type,
const std::string &  name 
)
inlinestatic

Create an object of type with name.

Definition at line 41 of file QwFactory.h.

Referenced by VQwFactory< VQwDataElement >::Create().

41  {
42  return GetFactory(type)->Create(name);
43  }
static base_t * Create(const std::string &type, const std::string &name)
Create an object of type with name.
Definition: QwFactory.h:41
static VQwFactory * GetFactory(const std::string &type)
Get a concrete type factory by string.
Definition: QwFactory.h:76

+ Here is the caller graph for this function:

template<class base_t>
virtual base_t* VQwFactory< base_t >::Create ( const std::string &  name) const
pure virtual
template<class base_t>
static VQwFactory* VQwFactory< base_t >::GetFactory ( const std::string &  type)
inlinestaticprotected

Get a concrete type factory by string.

Definition at line 76 of file QwFactory.h.

Referenced by VQwFactory< VQwDataElement >::Cast(), and VQwFactory< VQwDataElement >::Create().

76  {
77  if (GetRegisteredTypes().find(type) != GetRegisteredTypes().end())
78  return GetRegisteredTypes()[type];
79  else {
80  QwError << "Type " << type << " is not registered!" << QwLog::endl;
81  QwMessage << "Available types:" << QwLog::endl;
83  QwWarning << "To register this type, add the following line to the top "
84  << "of the source file:" << QwLog::endl;
85  QwWarning << " RegisterSomethingFactory(" << type << ");" << QwLog::endl;
86  QwWarning << "Ensure that the dynamic library contains the factory object."
87  << QwLog::endl;
89  }
90  }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
static std::map< std::string, VQwFactory * > & GetRegisteredTypes()
Map from string to concrete type factories.
Definition: QwFactory.h:63
static void ListRegisteredTypes()
List available type factories.
Definition: QwFactory.h:68
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
#define QwWarning
Predefined log drain for warnings.
Definition: QwLog.h:45
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40

+ Here is the caller graph for this function:

template<class base_t>
static std::map<std::string,VQwFactory*>& VQwFactory< base_t >::GetRegisteredTypes ( )
inlinestaticprotected

Map from string to concrete type factories.

Definition at line 63 of file QwFactory.h.

Referenced by VQwFactory< VQwDataElement >::GetFactory(), VQwFactory< VQwDataElement >::ListRegisteredTypes(), and QwFactory< VQwSubsystem, subsystem_t >::QwFactory().

63  {
64  static std::map<std::string,VQwFactory<base_t>*> theMap;
65  return theMap;
66  }

+ Here is the caller graph for this function:

template<class base_t>
static bool VQwFactory< base_t >::InheritsFrom ( base_t *  base,
const std::string &  type 
)
inlinestatic

Test whether object inherits from type.

Definition at line 51 of file QwFactory.h.

51  {
52  return (Cast(base,type) != 0);
53  }
static base_t * Cast(base_t *base, const std::string &type)
Dynamic cast of object into type.
Definition: QwFactory.h:46
template<class base_t>
static void VQwFactory< base_t >::ListRegisteredTypes ( )
inlinestaticprotected

List available type factories.

Definition at line 68 of file QwFactory.h.

Referenced by VQwFactory< VQwDataElement >::GetFactory().

68  {
69  typename std::map<std::string,VQwFactory<base_t>*>::iterator type;
70  for (type = GetRegisteredTypes().begin();
71  type != GetRegisteredTypes().end(); type++ )
72  QwMessage << type->first << QwLog::endl;
73  }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
static std::map< std::string, VQwFactory * > & GetRegisteredTypes()
Map from string to concrete type factories.
Definition: QwFactory.h:63
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299

+ Here is the caller graph for this function:


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