Factory.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
20 #include <rtm/Factory.h>
21 #include <rtm/RTObject.h>
22 
23 namespace RTC
24 {
33  : m_Profile(profile), m_Number(-1)
34  {
35  }
36 
45  {
46  }
47 
56  {
57  return m_Profile;
58  }
59 
68  {
69  return m_Number;
70  }
71 
80  RtcNewFunc new_func,
81  RtcDeleteFunc delete_func,
82  NumberingPolicy* policy)
83  : FactoryBase(profile),
84  m_New(new_func),
85  m_Delete(delete_func),
86  m_policy(policy)
87  {
88  if (m_policy == NULL)
89  throw std::bad_alloc();
90  }
91 
100  {
101  try
102  {
103  RTObject_impl* rtobj(m_New(mgr));
104  if (rtobj == 0) return NULL;
105 
106  ++m_Number;
107  rtobj->setProperties(this->profile());
108 
109  // create instance_name
110  std::string instance_name(rtobj->getTypeName());
111  instance_name.append(m_policy->onCreate(rtobj));
112  rtobj->setInstanceName(instance_name.c_str());
113 
114  return rtobj;
115  }
116  catch (...)
117  {
118  return NULL;
119  }
120  }
121 
130  {
131  try
132  {
133  --m_Number;
134  m_policy->onDelete(comp);
135  m_Delete(comp);
136  }
137  catch (...)
138  {
139 
140  }
141  }
142 };
RTObject_impl *(* RtcNewFunc)(Manager *manager)
Definition: rtm/Factory.h:33
int m_Number
Number of current RT-Component&#39;s instances.
Definition: rtm/Factory.h:262
RT-Component.
virtual coil::Properties & profile()
Get the component profile.
Definition: Factory.cpp:55
NumberingPolicy * m_policy
The naming policy on creating the components.
Definition: rtm/Factory.h:405
virtual int number()
Get the number of current instances.
Definition: Factory.cpp:67
RT-Component class.
Definition: RTObject.h:89
Manager class.
Definition: Manager.h:80
coil::Properties m_Profile
Component profile.
Definition: rtm/Factory.h:253
FactoryCXX(const coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func, NumberingPolicy *policy=new DefaultNumberingPolicy())
Constructor.
Definition: Factory.cpp:79
virtual void onDelete(void *obj)=0
Delete the name when deleting objects.
const char * getTypeName()
[local interface] Get type name
Definition: RTObject.h:1998
Abstruct class for naming policy management when creating objects.
FactoryBase(const coil::Properties &profile)
Constructor.
Definition: Factory.cpp:32
RtcNewFunc m_New
The pointer to component object create function.
Definition: rtm/Factory.h:387
Class represents a set of properties.
Definition: Properties.h:101
virtual std::string onCreate(void *obj)=0
Create the name when creating objects.
virtual ~FactoryBase(void)
Destructor.
Definition: Factory.cpp:44
FactoryBase base class.
Definition: rtm/Factory.h:118
void setInstanceName(const char *instance_name)
[local interface] Set instance name
Definition: RTObject.cpp:1441
void(* RtcDeleteFunc)(RTObject_impl *rtc)
Definition: rtm/Factory.h:34
virtual RTObject_impl * create(Manager *mgr)
Create RT-Components.
Definition: Factory.cpp:99
virtual void destroy(RTObject_impl *comp)
Destroy RT-Components.
Definition: Factory.cpp:129
void setProperties(const coil::Properties &prop)
[local interface] Set RTC property
Definition: RTObject.cpp:1501
RtcDeleteFunc m_Delete
The pointer to component object destroy function.
Definition: rtm/Factory.h:396


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:43