Factory.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #include <rtm/Factory.h>
00021 #include <rtm/RTObject.h>
00022 
00023 namespace RTC 
00024 {
00032   FactoryBase::FactoryBase(const coil::Properties& profile)
00033     : m_Profile(profile), m_Number(-1)
00034   {
00035   }
00036   
00044   FactoryBase::~FactoryBase()
00045   {
00046   }
00047   
00055   coil::Properties& FactoryBase::profile()
00056   {
00057     return m_Profile;
00058   }
00059   
00067   int FactoryBase::number()
00068   {
00069     return m_Number;
00070   }
00071   
00079   FactoryCXX::FactoryCXX(const coil::Properties& profile,
00080                          RtcNewFunc new_func,
00081                          RtcDeleteFunc delete_func,
00082                          NumberingPolicy* policy)
00083     : FactoryBase(profile),
00084       m_New(new_func),
00085       m_Delete(delete_func),
00086       m_policy(policy)
00087   {
00088     if (m_policy == NULL)
00089       throw std::bad_alloc();
00090   }
00091   
00099   RTObject_impl* FactoryCXX::create(Manager* mgr)
00100   {
00101     try
00102       {
00103         RTObject_impl* rtobj(m_New(mgr));
00104         if (rtobj == 0) return NULL;
00105         
00106         ++m_Number;
00107         rtobj->setProperties(this->profile());
00108         
00109         // create instance_name
00110         std::string instance_name(rtobj->getTypeName());
00111         instance_name.append(m_policy->onCreate(rtobj));
00112         rtobj->setInstanceName(instance_name.c_str());
00113         
00114         return rtobj;
00115       }
00116     catch (...)
00117       {
00118         return NULL;
00119       }
00120   }
00121   
00129   void FactoryCXX::destroy(RTObject_impl* comp)
00130   {
00131     try
00132       {
00133         --m_Number;
00134         m_policy->onDelete(comp);
00135         m_Delete(comp);
00136       }
00137     catch (...)
00138       {
00139         
00140       }
00141   }
00142 };


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:04