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