Diana Software
QBaseModuleFactory.hh
Go to the documentation of this file.
1 #ifndef _Q_BASE_MODULE_FACTORY_HH_
2 #define _Q_BASE_MODULE_FACTORY_HH_
13 
14 class QSequence;
15 
16 // unfortunately QModuleFactory is already taken... :(
17 template<class T> class QModFactory {
18  public:
19  QModFactory<T>(const std::string& name) {
20  fName = name;
21  fCurrentSequence = NULL;
22  }
23  const std::string& GetName() const { return fName; }
24  virtual ~QModFactory<T>() {};
25  T* Create(QSequence* s) {
26  if( s != fCurrentSequence ) {
27  fCurrentSequence = s;
28  fOccurrence = 0;
29  } else {
30  fOccurrence++;
31  }
32  T* obj = GetObject(s);
33  return obj;
34  }
35  protected:
36  virtual T* GetObject(QSequence *s) = 0;
37 
38  std::string fName;
40 
42  friend class QGeneralFactory;
43 };
44 
46 
47 #define DECLARE_MODULE_FACTORY(clazz,modtype) \
48  class clazz ## Factory : public Diana::QModFactory<modtype>{\
49  public:\
50  clazz ## Factory() : Diana::QModFactory<modtype>(#clazz) {}\
51  private:\
52  modtype *GetObject(Diana::QSequence* s) {\
53  modtype* obj = new clazz();\
54  Diana::QBaseModule* bobj = (Diana::QBaseModule*) obj;\
55  bobj->Update(s,fOccurrence);\
56  return obj;\
57  }\
58  };
59 
60 #define REGISTER_MOD(clazz,modtype) \
61  DECLARE_MODULE_FACTORY(clazz,modtype);\
62 extern "C" void registerInFactory ## clazz() {\
63  Diana::QModFactory<modtype>* pt = new clazz ## Factory;\
64  Diana::QGeneralFactory::GetInstance().Register(pt);\
65 }
66 
67 #endif
68 
#define Q_END_NAMESPACE
Definition: QDiana.hh:22
#define Q_BEGIN_NAMESPACE
Definition: QDiana.hh:20
This class take care of plugin registration and creation.
abstract module factory and definition of macros that builds modulefactories and register function.
const std::string & GetName() const
std::string fName
T * Create(QSequence *s)
QSequence * fCurrentSequence
virtual T * GetObject(QSequence *s)=0
Diana Reconstruction program.
Definition: QSequence.hh:40