00001 // -*- C++ -*- 00019 /* 00020 * $Log: Factory.h,v $ 00021 * Revision 1.5 2006/11/06 01:28:36 n-ando 00022 * Now the "instance_name" is set to the component at creation time. 00023 * 00024 * Revision 1.4 2006/10/25 17:36:00 n-ando 00025 * Classes were renamed, and class reference manual was described. 00026 * 00027 * Revision 1.3 2006/10/24 14:23:45 n-ando 00028 * Renamed RtcFactory.h to Factory.h 00029 * 00030 * Revision 1.2 2005/05/16 06:06:30 n-ando 00031 * - RtcFactoryBase, RtcFactoryCXX classes were DLL exported for Windows port. 00032 * 00033 * Revision 1.1.1.1 2005/05/12 09:06:18 n-ando 00034 * Public release. 00035 * 00036 * 00037 */ 00038 00039 #ifndef RtcFactory_h 00040 #define RtcFactory_h 00041 #define EXPORTS 00042 #include "rtm/Properties.h" 00043 #include "rtm/RTObject.h" 00044 #include <rtm/NumberingPolicy.h> 00045 00046 00047 namespace RTC 00048 { 00049 typedef RTObject_impl RtcBase; 00050 class Manager; 00051 00052 typedef RtcBase* (*RtcNewFunc)(Manager* manager); 00053 typedef void (*RtcDeleteFunc)(RtcBase* rtc); 00054 00055 template <class _New> 00056 RtcBase* Create(Manager* manager) 00057 { 00058 return new _New(manager); 00059 } 00060 00061 template <class _Delete> 00062 void Delete(RtcBase* rtc) 00063 { 00064 delete rtc; 00065 } 00066 00067 00087 class EXPORTS FactoryBase 00088 { 00089 public: 00109 FactoryBase(const Properties& profile); 00110 virtual ~FactoryBase(); 00111 00133 virtual RtcBase* create(Manager* mgr) = 0; 00134 00156 virtual void destroy(RtcBase* comp) = 0; 00157 00173 virtual Properties& profile(); 00174 00190 virtual int number(); 00191 00192 protected: 00200 Properties m_Profile; 00208 int m_Number; 00209 }; 00210 00211 00212 00232 class EXPORTS FactoryCXX 00233 : public FactoryBase 00234 { 00235 public: 00264 FactoryCXX(const Properties& profile, 00265 RtcNewFunc new_func, 00266 RtcDeleteFunc delete_func, 00267 NumberingPolicy* policy = new DefaultNumberingPolicy()); 00268 00288 virtual RtcBase* create(Manager* mgr); 00289 00309 virtual void destroy(RtcBase* comp); 00310 00311 protected: 00319 RtcNewFunc m_New; 00320 00328 RtcDeleteFunc m_Delete; 00329 00330 NumberingPolicy* m_policy; 00331 }; 00332 }; 00333 00334 00335 #endif // RtcFactory_h