ServantFactory.h
Go to the documentation of this file.
1 // -*- C++ -*-
19 #ifndef DOIL_SERVANTFACTORY_H
20 #define DOIL_SERVANTFACTORY_H
21 
22 #include <doil/ServantBase.h>
23 #include <doil/ImplBase.h>
24 
25 namespace doil
26 {
27  // Servant 生成・削除関数のtypedef
28  typedef ServantBase* (*ServantNewFunc)(ImplBase*);
29  typedef void (*ServantDeleteFunc)(ServantBase*);
30 
31  // Servant 生成のためのテンプレート関数 template <class Servant> ServantBase* New(ImplBase* impl) { return new Servant(impl); } // Servant 削除のためのテンプレート関数 template <class Servant> void Delete(ServantBase* servant) { if (servant != NULL) { delete servant; servant = NULL; } } class ServantFactoryBase { public: virtual ~ServantFactoryBase(){} virtual const char* name() = 0; virtual ServantBase* create() = 0; virtual void destroy(ServantBase* servant) = 0; }; class ServantFactory // : public ServantFactoryBase { public: ServantFactory(const char* id, ServantNewFunc new_func, ServantDeleteFunc delete_func) : m_id(id), m_new(new_func), m_delete(delete_func) { } /* ServantFactory(const ServantFactory& sf) { m_name = sf.m_name; m_new = sf.m_new; m_delete = sf.m_delete; } ServantFactory& operator=(ServantFactory& sf) { ServantFactory tmp(sf); std::swap(*this, tmp); return *this; } */ virtual ~ServantFactory(){}; virtual const char* id() { return m_id.c_str(); } virtual ServantBase* create(ImplBase* impl) { return m_new(impl); } virtual void destroy(ServantBase* servant) { m_delete(servant); } private: std::string m_id; ServantNewFunc m_new; ServantDeleteFunc m_delete; }; }; #endif // DOIL_SERVANTFACTORY_H
32  template <class Servant>
34  {
35  return new Servant(impl);
36  }
37 
38  // Servant 削除のためのテンプレート関数 template <class Servant> void Delete(ServantBase* servant) { if (servant != NULL) { delete servant; servant = NULL; } } class ServantFactoryBase { public: virtual ~ServantFactoryBase(){} virtual const char* name() = 0; virtual ServantBase* create() = 0; virtual void destroy(ServantBase* servant) = 0; }; class ServantFactory // : public ServantFactoryBase { public: ServantFactory(const char* id, ServantNewFunc new_func, ServantDeleteFunc delete_func) : m_id(id), m_new(new_func), m_delete(delete_func) { } /* ServantFactory(const ServantFactory& sf) { m_name = sf.m_name; m_new = sf.m_new; m_delete = sf.m_delete; } ServantFactory& operator=(ServantFactory& sf) { ServantFactory tmp(sf); std::swap(*this, tmp); return *this; } */ virtual ~ServantFactory(){}; virtual const char* id() { return m_id.c_str(); } virtual ServantBase* create(ImplBase* impl) { return m_new(impl); } virtual void destroy(ServantBase* servant) { m_delete(servant); } private: std::string m_id; ServantNewFunc m_new; ServantDeleteFunc m_delete; }; }; #endif // DOIL_SERVANTFACTORY_H
39  template <class Servant>
40  void Delete(ServantBase* servant)
41  {
42  if (servant != NULL)
43  {
44  delete servant;
45  servant = NULL;
46  }
47  }
48 
49  class ServantFactoryBase
50  {
51  public:
52  virtual ~ServantFactoryBase(){}
53  virtual const char* name() = 0;
54  virtual ServantBase* create() = 0;
55  virtual void destroy(ServantBase* servant) = 0;
56  };
57 
58 
59  class ServantFactory
60  // : public ServantFactoryBase
61  {
62  public:
63  ServantFactory(const char* id,
64  ServantNewFunc new_func,
65  ServantDeleteFunc delete_func)
66  : m_id(id), m_new(new_func), m_delete(delete_func)
67  {
68  }
69 
70  /*
71  ServantFactory(const ServantFactory& sf)
72  {
73  m_name = sf.m_name;
74  m_new = sf.m_new;
75  m_delete = sf.m_delete;
76  }
77 
78  ServantFactory& operator=(ServantFactory& sf)
79  {
80  ServantFactory tmp(sf);
81  std::swap(*this, tmp);
82  return *this;
83  }
84  */
85  virtual ~ServantFactory(){};
86 
87  virtual const char* id()
88  {
89  return m_id.c_str();
90  }
91  virtual ServantBase* create(ImplBase* impl)
92  {
93  return m_new(impl);
94  }
95  virtual void destroy(ServantBase* servant)
96  {
97  m_delete(servant);
98  }
99  private:
100  std::string m_id;
103  };
104 
105 
106 };
107 #endif // DOIL_SERVANTFACTORY_H
ServantFactory(const char *id, ServantNewFunc new_func, ServantDeleteFunc delete_func)
ServantBase *(* ServantNewFunc)()
ProxyBase * New(::CORBA::Object_ptr obj)
Definition: ProxyFactory.h:35
virtual ServantBase * create()=0
virtual const char * id()
ServantNewFunc m_new
virtual void destroy(ServantBase *servant)=0
doil implementation base class
virtual ServantBase * create(ImplBase *impl)
void(* ServantDeleteFunc)(ServantBase *)
doil implementation base class
virtual const char * name()=0
virtual void destroy(ServantBase *servant)
void Delete(ProxyBase *impl)
Definition: ProxyFactory.h:43
ServantDeleteFunc m_delete


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:26:00