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> 104 template<
typename CLASS>
105 static CLASS*
newInstance( std::string
const& classIdentifier );
115 template<
typename CLASS>
116 static CLASS*
newInstance( std::string
const& classIdentifier,
117 int paramCount, ... );
119 template<
typename CLASS>
120 static CLASS*
newInstance( std::string
const& classIdentifier,
121 int paramCount, std::va_list list );
128 return instance().mRoot.isClassRegistered( classIdentifier );
137 return instance().mRoot.getClassByIdentifier( classIdentifier );
146 std::string
const& metaValue )
148 return instance().mRoot.getClassByMeta( metaKey, metaValue );
159 return instance().mRoot.getClassByMeta( funcPtr );
167 return instance().mRoot.getDerivedClasses();
175 static void registerClass( boost::shared_ptr<Class> iClass );
184 boost::shared_ptr<Class> baseClass );
198 std::vector< std::string>
const& parents );
222 boost::recursive_mutex mThreadMutex;
223 std::map<std::string, boost::shared_ptr<Class> > mClasses;
232 struct FactoryNullDeleter
234 void operator()(
void const *)
const 238 template<
typename TClassP,
typename Base>
239 struct FactoryRegisterClassHelper
241 static void invoke() {
242 boost::shared_ptr<TClass<TClassP> > tClass( &(TClassP::_CLASS()) , FactoryNullDeleter() );
243 boost::shared_ptr<Class> tClassPtr = boost::dynamic_pointer_cast<Class>( tClass );
244 boost::shared_ptr<TClass<Base> > tBase( &(Base::_CLASS()), FactoryNullDeleter() );
245 boost::shared_ptr<Class> tBasePtr = boost::dynamic_pointer_cast<Class>( tBase );
247 tClassPtr, tBasePtr );
251 template<
typename TClassP>
252 struct FactoryRegisterClassHelper<TClassP,
mira::
Object>
254 static void invoke() {
255 boost::shared_ptr<TClass<TClassP> > tClass( &(TClassP::_CLASS()), FactoryNullDeleter() );
256 boost::shared_ptr<Class> tClassPtr = boost::dynamic_pointer_cast<Class>( tClass );
261 template<
typename Class>
262 struct FactoryRegisterClassHelper<Class, bool>
264 static void invoke() {}
271 template<
typename Class,
273 typename Base1=bool,
typename Base2=bool,
274 typename Base3=bool,
typename Base4=
bool>
275 class FactoryRegisterClass
278 FactoryRegisterClass()
280 FactoryRegisterClassHelper<Class,Base0>::invoke();
281 FactoryRegisterClassHelper<Class,Base1>::invoke();
282 FactoryRegisterClassHelper<Class,Base2>::invoke();
283 FactoryRegisterClassHelper<Class,Base3>::invoke();
284 FactoryRegisterClassHelper<Class,Base4>::invoke();
298 template<
typename CLASS>
301 Object* tBase = instance().mRoot.newInstance( classIdentifier );
302 return mira_factoryDynamicCast<CLASS>( tBase );
305 template<
typename CLASS>
307 int paramCount, ... )
310 va_start(ap, paramCount);
311 Object* tObject = instance().mRoot.newVAInstance( classIdentifier,
313 return mira_factoryDynamicCast<CLASS>( tObject );
316 template<
typename CLASS>
318 int paramCount, std::va_list list )
320 Object* tObject = instance().mRoot.newVAInstance( classIdentifier,
322 return mira_factoryDynamicCast<CLASS>( tObject );
332 return ClassFactory::newInstance<Object>(pChildIdentifier);
335 template <
class CLASS>
338 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:145
static void finalizePostRegister()
Propagate all children to indirect parents and add meta information of parent classes to children...
$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:86
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:508
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
void propagateChild(ClassProxy &child, Class &parent)
Auxiliary function to propagate child classes to indirect parents.
static std::map< std::string, ClassProxy > getDerivedClasses()
Return list of registered classes.
Definition: Factory.h:165
Class object which supports some kind of class reflection.
Definition: Class.h:97
friend class LightFactoryMutexGetter
Definition: Factory.h:89
static bool isClassRegistered(std::string const &classIdentifier)
Return true if a class with the desired identifier is registered.
Definition: Factory.h:126
Provided for convenience.
Definition: Singleton.h:528
static ClassProxy getClassByIdentifier(std::string const &classIdentifier)
Return the Class object for the desired Class.
Definition: Factory.h:135
static void postRegisterBaseClasses(std::string const &iClass, std::vector< std::string > const &parents)
Register Parent - Child relationship.
static std::vector< ClassProxy > getClassByMeta(T funcPtr)
Return list of Class objects returning true for the given comparison function.
Definition: Factory.h:157
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:181
$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$.
bool internalClassRegister(boost::shared_ptr< Class > iClass)
Internal function to register a class.
static void registerClass(boost::shared_ptr< Class > iClass)
Register Class.
static void unregisterClass(Class *iClass)
Unregister Class.
ClassFactory()
Definition: Factory.h:93
static CLASS * newInstance(std::string const &classIdentifier)
Create new instance of the class defined by class identifier.
Definition: Factory.h:299
Object * newInstance(std::string const &childIdentifier) const
Return a new instance of the class with the given identifier.
Definition: Factory.h:330