48 #ifndef _MIRA_FACTORY_H_ 49 #define _MIRA_FACTORY_H_ 55 #include <boost/type_traits/is_abstract.hpp> 56 #include <boost/assign.hpp> 57 #include <boost/preprocessor/seq.hpp> 58 #include <boost/preprocessor/tuple.hpp> 91 friend class LightFactoryMutexGetter;
106 template<
typename CLASS>
107 static CLASS* newInstance( std::string
const& classIdentifier );
117 template<
typename CLASS>
118 static CLASS* newInstance( std::string
const& classIdentifier,
119 int paramCount, ... );
121 template<
typename CLASS>
122 static CLASS* newInstance( std::string
const& classIdentifier,
123 int paramCount, std::va_list list );
130 return instance().mRoot.isClassRegistered( classIdentifier );
148 std::string
const& metaValue )
150 return instance().mRoot.getClassByMeta( metaKey, metaValue );
161 return instance().mRoot.getClassByMeta( funcPtr );
169 return instance().mRoot.getDerivedClasses();
177 static void registerClass( boost::shared_ptr<Class> iClass );
185 static void registerClass( boost::shared_ptr<Class> iClass,
186 boost::shared_ptr<Class> baseClass );
192 static void unregisterClass(
Class* iClass );
199 static void postRegisterBaseClasses( std::string
const& iClass,
200 std::vector< std::string>
const& parents );
207 static void finalizePostRegister();
219 bool internalClassRegister( boost::shared_ptr<Class> iClass );
224 boost::recursive_mutex mThreadMutex;
225 std::map<std::string, boost::shared_ptr<Class> > mClasses;
234 struct FactoryNullDeleter
236 void operator()(
void const *)
const 240 template<
typename TClassP,
typename Base>
241 struct FactoryRegisterClassHelper
243 static void invoke() {
244 boost::shared_ptr<TClass<TClassP> > tClass( &(TClassP::_CLASS()) , FactoryNullDeleter() );
245 boost::shared_ptr<Class> tClassPtr = boost::dynamic_pointer_cast<Class>( tClass );
246 boost::shared_ptr<TClass<Base> > tBase( &(Base::_CLASS()), FactoryNullDeleter() );
247 boost::shared_ptr<Class> tBasePtr = boost::dynamic_pointer_cast<Class>( tBase );
249 tClassPtr, tBasePtr );
253 template<
typename TClassP>
254 struct FactoryRegisterClassHelper<TClassP,
mira::
Object>
256 static void invoke() {
257 boost::shared_ptr<TClass<TClassP> > tClass( &(TClassP::_CLASS()), FactoryNullDeleter() );
258 boost::shared_ptr<Class> tClassPtr = boost::dynamic_pointer_cast<Class>( tClass );
263 template<
typename Class>
264 struct FactoryRegisterClassHelper<Class, bool>
266 static void invoke() {}
273 template<
typename Class,
275 typename Base1=bool,
typename Base2=bool,
276 typename Base3=bool,
typename Base4=
bool>
277 class FactoryRegisterClass
280 FactoryRegisterClass()
282 FactoryRegisterClassHelper<Class,Base0>::invoke();
283 FactoryRegisterClassHelper<Class,Base1>::invoke();
284 FactoryRegisterClassHelper<Class,Base2>::invoke();
285 FactoryRegisterClassHelper<Class,Base3>::invoke();
286 FactoryRegisterClassHelper<Class,Base4>::invoke();
300 template<
typename CLASS>
303 Object* tBase = instance().mRoot.newInstance( classIdentifier );
304 return mira_factoryDynamicCast<CLASS>( tBase );
307 template<
typename CLASS>
309 int paramCount, ... )
312 va_start(ap, paramCount);
313 Object* tObject = instance().mRoot.newVAInstance( classIdentifier,
315 return mira_factoryDynamicCast<CLASS>( tObject );
318 template<
typename CLASS>
320 int paramCount, std::va_list list )
322 Object* tObject = instance().mRoot.newVAInstance( classIdentifier,
324 return mira_factoryDynamicCast<CLASS>( tObject );
334 return ClassFactory::newInstance<Object>(pChildIdentifier);
337 template <
class CLASS>
340 return ClassFactory::newInstance<CLASS>(pChildIdentifier);
Registration and unregistration helper class.
$Macros for registering classes$.
$Definition of the Class which supports some kind of class reflection and acts like a class factory$...
static std::vector< ClassProxy > getClassByMeta(std::string const &metaKey, std::string const &metaValue)
Return list of Class objects matching the meta criterion.
Definition: Factory.h:147
$In contrast to the VacantClass this is the "real" class specific implementation which is able to con...
What should i say, the class factory.
Definition: Factory.h:88
The class proxy assures that the pointer to the class object is always valid.
Definition: Class.h:400
static Type & instance()
Returns a reference to the singleton instance.
Definition: Singleton.h:544
Preprocessor workaround to handle single parameters that contain a comma.
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
static std::map< std::string, ClassProxy > getDerivedClasses()
Return list of registered classes.
Definition: Factory.h:167
Class object which supports some kind of class reflection.
Definition: Class.h:97
static bool isClassRegistered(std::string const &classIdentifier)
Return true if a class with the desired identifier is registered.
Definition: Factory.h:128
Provided for convenience.
Definition: Singleton.h:564
static ClassProxy getClassByIdentifier(std::string const &classIdentifier)
Return the Class object for the desired Class.
Definition: Factory.h:137
static std::vector< ClassProxy > getClassByMeta(T funcPtr)
Return list of Class objects returning true for the given comparison function.
Definition: Factory.h:159
ClassProxy getClassByIdentifier(std::string const &classIdentifier) const
Return the Class object for the desired Class.
Includes, defines and functions for threads.
A singleton class that can be freely configured using policies that control the creation, instantiation, lifetime and thread-safety.
The object class acts as a generic base class for classes which should be used with the classFactory...
Definition: Object.h:144
The VacantClass object is the implementation of the Class class for classes which are NOT available s...
Definition: VacantClass.h:68
json_spirit::mObject Object
A representation of an object (class, struct) in JSON.
Definition: JSON.h:183
$Definition of the template class objects which enables the factory to work with template classes$...
The TClass object is the implementation of the class class for classes which are available since the ...
Definition: TClass.h:75
$Defines object class as base class for classFactory compatible classes$.
ClassFactory()
Definition: Factory.h:95
static CLASS * newInstance(std::string const &classIdentifier)
Create new instance of the class defined by class identifier.
Definition: Factory.h:301
Object * newInstance(std::string const &childIdentifier) const
Return a new instance of the class with the given identifier.
Definition: Factory.h:332