diff --git a/src/BackendFactory.h b/src/BackendFactory.h index 9b784c9..56db93d 100644 --- a/src/BackendFactory.h +++ b/src/BackendFactory.h @@ -1,61 +1,78 @@ /** * \file BackendFactory.h * * \date Jun 21, 2012 * \author Alexandre Tuleu */ #ifndef LIBONCILLA_BACKENDFACTORY_H_ #define LIBONCILLA_BACKENDFACTORY_H_ #include #include namespace rci{ namespace oncilla{ class OncillaSynchronizer; typedef std::tr1::shared_ptr OncillaSynchronizerPtr; class BackendFactory { public : /** * define the priority of the backend */ enum Priority{ HARDWARE = 0, SIMULATION = 1, USER_DEFINED_PRIORITY = 2 }; /** * Pointer to a function that will be the entry of the Backend. */ typedef OncillaSynchronizerPtr (*EntryPtr)(); static BackendFactory & Instance(); /** * Register a new backend. * \param p the Priority of the backend * \param entry the EntryPtr of the backend * \warning : if a backend with the same priority is already here, the call * will be silently discarded. */ void RegisterBackend(Priority p, EntryPtr entry); /** * \return the EntryPtr of the highest priority backend or 0 if none was * registered with RegisterBackend(). */ EntryPtr HighestPriorityBackend() const; private: typedef std::map EntryByPriority; EntryByPriority d_entries; }; + template + class BackendRegistrator { + public : + BackendRegistrator(); + }; + + template + inline + BackendRegistrator::BackendRegistrator(){ + BackendFactory::Instance().RegisterBackend(P, + &(OncillaSynchronizerSubClass::Create)); + } +#define LIBONCILLA_REGISTER_THIS_CLASS(ClassName,PriorityValue) public :\ + static rci::oncilla::OncillaSynchronizerPtr Create();\ + private :\ + rci::oncilla::BackendRegistrator < ClassName , PriorityValue > s_registrator; + #endif // LIBONCILLA_BACKENDFACTORY_H_ } }