TAOVar Out type

TAOVar Out type

By WalterXia walter.xia@gmail.com

 

In our project, TAO, ACE are used widelyand they are crossing platforms. Especially, the CORBA based on them is highweight IPC infrastructure and used ininfra-card, inter-card, intra-process, and inter-process (different threads).

The Var, Out type implemented in TAO are employedto encapsulate defined IDL structures. In brief, the Var type is a smartpointer class and wrap native pointer and provides following member functions:

Supposed native type is T and its pointeris T*, T* & is a reference of native pointer.

Fucntion

Return type

Comment

in

const T &

Used as input parameter

out

T *&

The implementation is as followed:

  delete this->ptr_; //destruct the original pointed content

  this->ptr_ = 0; //set empty to the pointer

  return this->ptr_;

inout

T &

 

_retn()

T *

The implementation is as followed:

  T * tmp = this->ptr_;

  this->ptr_ = 0;  //original pointer will be set empty

  return tmp;  //original pointer content will be returned

ptr

T *

Return native pointer

 

While Out type is a reference of native pointer.

PracticeI:

If you want to convert the Var type to Out,such as XXX_Var to XXX_Out

XXX_Var à XXX_Out  //invoke XXX_Var’s _retn() member functionfor converting

 

Func(XXX_Out xxx_out)

{

  XXX_Var tmpVar;

   ….

   xxx_out= tmpVar. _retn();

}

 

If want to use as following:

XXX_Var xxx_var;

……//changing the xxx_var

Func(xxx_var)  //implicitly convert to Out type for the Vartype using following construct function TAO_Out_T (T_var &)

(OR) Func(xxx_var.out())

The xxx_var contents will be erased when invokingthe Func.

Make sure the Func the statement of “ xxx_out= tmpVar. _retn();” will be called and there will be issues (xxx_var will benull and accessing its member functions is forbidden) if exception is thrown orreturned before the statement is executed.

The construct function’s implementation isas followed:

template<typename T, typename T_var>

ACE_INLINE

TAO_Out_T<T,T_var>::TAO_Out_T (T_var& p)

  :ptr_ (p.out ())

{

  delete this->ptr_;  //original pointed content will be erased

 this->ptr_ = 0;    

}

 

PracticeII:

Passing native pointer as input argumentand doesn’t change the content

Using in member function of Var is recommended.

 

PracticeIII:

A function has an argument Var and want tochange the content in the function body. Just considering the Var ordinaryclass and its reference is recommend.

 

 

 

References:

ACE_wrappers/TAO/tao/VarOut_T.h  //header files for

ACE_wrappers/TAO/tao/VarOut_T.inl  //inline functions implementations

http://www.dre.vanderbilt.edu/Doxygen/5.5.1/html/tao/VarOut__T_8h.html 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值