48 #ifndef _MIRA_FACTORY_H_ 49 #define _MIRA_FACTORY_H_ 55 #include <boost/type_traits/is_abstract.hpp> 56 #include <boost/mpl/eval_if.hpp> 57 #include <boost/assign.hpp> 58 #include <boost/preprocessor/seq.hpp> 59 #include <boost/preprocessor/tuple.hpp> 92 friend class LightFactoryMutexGetter;
107 template<
typename CLASS>
108 static CLASS* newInstance( std::string
const& classIdentifier );
118 template<
typename CLASS>
119 static CLASS* newInstance( std::string
const& classIdentifier,
120 int paramCount, ... );
122 template<
typename CLASS>
123 static CLASS* newInstance( std::string
const& classIdentifier,
124 int paramCount, std::va_list list );
131 return instance().mRoot.isClassRegistered( classIdentifier );
149 std::string
const& metaValue )
151 return instance().mRoot.getClassByMeta( metaKey, metaValue );
162 return instance().mRoot.getClassByMeta( funcPtr );
170 return instance().mRoot.getDerivedClasses();
178 static void registerClass( boost::shared_ptr<Class> iClass );
186 static void registerClass( boost::shared_ptr<Class> iClass,
187 boost::shared_ptr<Class> baseClass );
193 static void unregisterClass(
Class* iClass );
200 static void postRegisterBaseClasses( std::string
const& iClass,
201 std::vector< std::string>
const& parents );
208 static void finalizePostRegister();
220 bool internalClassRegister( boost::shared_ptr<Class> iClass );
225 boost::recursive_mutex mThreadMutex;
226 std::map<std::string, boost::shared_ptr<Class> > mClasses;
235 struct FactoryNullDeleter
237 void operator()(
void const *)
const 241 template<
typename TClassP,
typename Base>
242 struct FactoryRegisterClassHelper
244 static void invoke() {
245 boost::shared_ptr<TClass<TClassP> > tClass( &(TClassP::_CLASS()) , FactoryNullDeleter() );
246 boost::shared_ptr<Class> tClassPtr = boost::dynamic_pointer_cast<Class>( tClass );
247 boost::shared_ptr<TClass<Base> > tBase( &(Base::_CLASS()), FactoryNullDeleter() );
248 boost::shared_ptr<Class> tBasePtr = boost::dynamic_pointer_cast<Class>( tBase );
250 tClassPtr, tBasePtr );
254 template<
typename TClassP>
255 struct FactoryRegisterClassHelper<TClassP,
mira::
Object>
257 static void invoke() {
258 boost::shared_ptr<TClass<TClassP> > tClass( &(TClassP::_CLASS()), FactoryNullDeleter() );
259 boost::shared_ptr<Class> tClassPtr = boost::dynamic_pointer_cast<Class>( tClass );
264 template<
typename Class>
265 struct FactoryRegisterClassHelper<Class, bool>
267 static void invoke() {}
274 template<
typename Class,
276 typename Base1=bool,
typename Base2=bool,
277 typename Base3=bool,
typename Base4=
bool>
278 class FactoryRegisterClass
281 FactoryRegisterClass()
283 FactoryRegisterClassHelper<Class,Base0>::invoke();
284 FactoryRegisterClassHelper<Class,Base1>::invoke();
285 FactoryRegisterClassHelper<Class,Base2>::invoke();
286 FactoryRegisterClassHelper<Class,Base3>::invoke();
287 FactoryRegisterClassHelper<Class,Base4>::invoke();
301 template<
typename CLASS>
304 Object* tBase = instance().mRoot.newInstance( classIdentifier );
305 return mira_factoryDynamicCast<CLASS>( tBase );
308 template<
typename CLASS>
310 int paramCount, ... )
313 va_start(ap, paramCount);
314 Object* tObject = instance().mRoot.newVAInstance( classIdentifier,
316 return mira_factoryDynamicCast<CLASS>( tObject );
319 template<
typename CLASS>
321 int paramCount, std::va_list list )
323 Object* tObject = instance().mRoot.newVAInstance( classIdentifier,
325 return mira_factoryDynamicCast<CLASS>( tObject );
335 return ClassFactory::newInstance<Object>(pChildIdentifier);
338 template <
class CLASS>
341 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:148
$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:89
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:168
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:129
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:138
static std::vector< ClassProxy > getClassByMeta(T funcPtr)
Return list of Class objects returning true for the given comparison function.
Definition: Factory.h:160
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:96
static CLASS * newInstance(std::string const &classIdentifier)
Create new instance of the class defined by class identifier.
Definition: Factory.h:302
Object * newInstance(std::string const &childIdentifier) const
Return a new instance of the class with the given identifier.
Definition: Factory.h:333