ObjectRegistrar.h
Go to the documentation of this file.
1 #ifndef _utl_ObjectRegistrar_h_
2 #define _utl_ObjectRegistrar_h_
3 
13 #include <utl/ObjectFactory.h>
14 
15 
16 namespace utl {
17 
31  template<class ObjectType, class ObjectFactory>
33 
34  public:
36  { return ObjectType::Create; }
37 
38  };
39 
40 
66  template<class ObjectType,
67  class ObjFactoryType,
68  class CreatorPolicy = StandardCreator<ObjectType, ObjFactoryType> >
70 
71  public:
73  typedef ObjFactoryType ObjectFactoryType;
74  typedef typename ObjFactoryType::ObjectPtrType ObjectPtrType;
75 
76  // The default constructor is required to force the instantiation
77  // of the static member variable fgAutoRegistrar whose
78  // initialization triggers the registration with the factory
80  {
81  if (!fgAutoRegistrar)
82  fgAutoRegistrar = new ObjectRegistrar(true);
83  }
84 
85  private:
86  // This constructor in needed to avoid recursion during
87  // initialization of fgAutoRegistrar. The bool argument is ignored
88  ObjectRegistrar(bool) { }
89 
90  static
93  {
94  ObjectFactoryType::Register(ObjectType::GetRegistrationId(),
95  CreatorPolicy::GetCreator());
96  return new ObjectRegistrar(true);
97  }
98 
100 
101  }; // ObjectRegistrar
102 
103 
104  template<class Object, class ObjectFactory, class CreatorPolicy>
108 
109 } // utl
110 
111 
112 #endif // _utl_ObjectRegistrar_h_
113 
114 // Configure (x)emacs for this file ...
115 // Local Variables:
116 // mode: c++
117 // compile-command: "make -C .. -k"
118 // End:
ObjFactoryType::ObjectPtrType ObjectPtrType
ObjFactoryType ObjectFactoryType
The type of the ObjectFactory we register with.
static const ObjectRegistrar * fgAutoRegistrar
Class for the automatic registration of an object.
static ObjectFactory::CreatorType GetCreator()
static ObjectRegistrar * AutoRegister()
Class for the automatic creation of an object.
CreatType CreatorType
Definition: ObjectFactory.h:79

, generated on Tue Sep 26 2023.