OpenRTM-aist  2.1.0
CorbaConsumer.h
[詳解]
1 // -*- C++ -*-
20 #ifndef RTC_CORBACONSUMER_H
21 #define RTC_CORBACONSUMER_H
22 
23 #include <utility>
24 #include <iostream>
25 #ifdef ORB_IS_MICO
26 #include <CORBA.h>
27 #endif
28 #ifdef ORB_IS_OMNIORB
29 #include <omniORB4/CORBA.h>
30 #endif
31 #ifdef ORB_IS_ORBACUS
32 #include <OB/CORBA.h>
33 #endif
34 #ifdef ORB_IS_ORBIT2
35 #include <orbitcpp/orb-cpp/orbitcpp.h>
36 #endif
37 #ifdef ORB_IS_ORBIX
38 #include <CORBA.h>
39 #endif
40 #ifdef ORB_IS_TAO
41 #include <tao/corba.h>
42 #endif
43 
58 namespace RTC
59 {
84  {
85  public:
97  CorbaConsumerBase() = default;
98 
115 #ifdef ORB_IS_ORBEXPRESS
116  : m_objref(CORBA::Object::_duplicate(x.m_objref.in()))
117 #else
118  : m_objref(CORBA::Object::_duplicate(x.m_objref))
119 #endif
120  {
121  }
122 
143  {
144  CorbaConsumerBase tmp(x);
145  tmp.swap(*this);
146  return *this;
147  }
148 
165  {
166  CORBA::Object_var tmpref = x.m_objref;
167  x.m_objref = this->m_objref;
168  this->m_objref = tmpref;
169  }
170 
183  {
184  releaseObject();
185  }
186 
214  virtual bool setObject(CORBA::Object_ptr obj)
215  {
216  if (CORBA::is_nil(obj))
217  {
218  return false;
219  }
220  m_objref = CORBA::Object::_duplicate(obj);
221  return true;
222  }
223 
247  virtual CORBA::Object_ptr getObject()
248  {
249  return m_objref;
250  }
251 
269  virtual void releaseObject()
270  {
271  m_objref = CORBA::Object::_nil();
272  }
273 
274  protected:
282  CORBA::Object_var m_objref;
283  };
284 
328  template <class ObjectType,
329  typename ObjectTypePtr = typename ObjectType::_ptr_type,
330  typename ObjectTypeVar = typename ObjectType::_var_type>
332  : public CorbaConsumerBase
333  {
334  public:
347 
365 #ifdef ORB_IS_ORBEXPRESS
366  , m_var(ObjectType::_duplicate(x.m_var.in()))
367 #else
368  , m_var(ObjectType::_duplicate(x.m_var))
369 #endif
370  {
371  }
372 
393  {
394  CorbaConsumer tmp(x);
395  tmp.swap(*this);
396  return *this;
397  }
398 
400  {
402  ObjectTypeVar tmpref = x.m_var;
403  x.m_var = this->m_var;
404  this->m_var = tmpref;
405 
406  }
407 
419  ~CorbaConsumer() override
420  {
421  releaseObject();
422  }
423 
452  bool setObject(CORBA::Object_ptr obj) override
453  {
455  {
456  releaseObject();
457  return false; // object is nil
458  }
459 
460  ObjectTypeVar var = ObjectType::_narrow(m_objref);
461 
462  if (CORBA::is_nil(var))
463  {
464  releaseObject();
465  return false;
466  }
467 
468  m_var = var;
469  return true;
470  }
471 
496  inline ObjectTypePtr _ptr()
497  {
498  return m_var.inout();
499  }
500 
525  inline ObjectTypePtr operator->()
526  {
527  return m_var.inout();
528  }
529 
547  void releaseObject() override
548  {
550  m_var = ObjectType::_nil();
551  }
552 
553  protected:
561  ObjectTypeVar m_var;
562  };
563 
564  // No inline for gcc warning, too big
565  template <class T, class U, class V>
567 } // namespace RTC
568 #endif // RTC_CORBACONSUMER_H
オブジェクトリファレンスを保持するプレースホルダ基底クラス
Definition: CorbaConsumer.h:84
CORBA::Object_var m_objref
設定された CORBA オブジェクト
Definition: CorbaConsumer.h:282
CorbaConsumerBase(const CorbaConsumerBase &x)
コピーコンストラクタ
Definition: CorbaConsumer.h:114
CorbaConsumerBase()=default
コンストラクタ
void swap(CorbaConsumerBase &x)
swap関数
Definition: CorbaConsumer.h:164
virtual bool setObject(CORBA::Object_ptr obj)
CORBAオブジェクトをセットする
Definition: CorbaConsumer.h:214
virtual void releaseObject()
CORBAオブジェクトの設定をクリアする
Definition: CorbaConsumer.h:269
virtual ~CorbaConsumerBase()
仮想デストラクタ
Definition: CorbaConsumer.h:182
CorbaConsumerBase & operator=(const CorbaConsumerBase &x)
代入演算子
Definition: CorbaConsumer.h:142
virtual CORBA::Object_ptr getObject()
CORBAオブジェクトを取得する
Definition: CorbaConsumer.h:247
オブジェクトリファレンスを保持するプレースホルダテンプレートクラス
Definition: CorbaConsumer.h:333
void releaseObject() override
CORBAオブジェクトの設定をクリアする
Definition: CorbaConsumer.h:547
~CorbaConsumer() override
仮想デストラクタ
Definition: CorbaConsumer.h:419
CorbaConsumer(const CorbaConsumer &x)
コピーコンストラクタ
Definition: CorbaConsumer.h:363
void swap(CorbaConsumer &x)
Definition: CorbaConsumer.h:399
CorbaConsumer & operator=(const CorbaConsumer &x)
代入演算子
Definition: CorbaConsumer.h:392
bool setObject(CORBA::Object_ptr obj) override
オブジェクトをセットする
Definition: CorbaConsumer.h:452
CorbaConsumer()
コンストラクタ
ObjectTypePtr _ptr()
ObjectType 型のオブジェクトのリファレンスを取得
Definition: CorbaConsumer.h:496
ObjectTypeVar m_var
設定された CORBA オブジェクト
Definition: CorbaConsumer.h:561
ObjectTypePtr operator->()
ObjectType 型のオブジェクトのリファレンスを取得
Definition: CorbaConsumer.h:525
RTコンポーネント