00001 // -*- C++ -*- 00020 #ifndef Factory_h 00021 #define Factory_h 00022 00023 #include <rtm/Properties.h> 00024 #include <rtm/RTObject.h> 00025 #include <rtm/NumberingPolicy.h> 00026 00027 00028 namespace RTC 00029 { 00030 typedef RTObject_impl RtcBase; 00031 class Manager; 00032 00033 typedef RtcBase* (*RtcNewFunc)(Manager* manager); 00034 typedef void (*RtcDeleteFunc)(RtcBase* rtc); 00035 00064 template <class _New> 00065 RtcBase* Create(Manager* manager) 00066 { 00067 return new _New(manager); 00068 } 00069 00091 template <class _Delete> 00092 void Delete(RtcBase* rtc) 00093 { 00094 delete rtc; 00095 } 00096 00118 class FactoryBase 00119 { 00120 public: 00140 FactoryBase(const Properties& profile); 00141 00155 virtual ~FactoryBase(); 00156 00180 virtual RtcBase* create(Manager* mgr) = 0; 00181 00201 virtual void destroy(RtcBase* comp) = 0; 00202 00222 virtual Properties& profile(); 00223 00243 virtual int number(); 00244 00245 protected: 00253 Properties m_Profile; 00254 00262 int m_Number; 00263 }; 00264 00286 class FactoryCXX 00287 : public FactoryBase 00288 { 00289 public: 00323 FactoryCXX(const Properties& profile, 00324 RtcNewFunc new_func, 00325 RtcDeleteFunc delete_func, 00326 NumberingPolicy* policy = new DefaultNumberingPolicy()); 00327 00351 virtual RtcBase* create(Manager* mgr); 00352 00372 virtual void destroy(RtcBase* comp); 00373 00374 protected: 00382 RtcNewFunc m_New; 00383 00391 RtcDeleteFunc m_Delete; 00392 00400 NumberingPolicy* m_policy; 00401 }; 00402 }; 00403 #endif // Factory_h