00001 // -*- C++ -*- 00002 // 00003 // $Id: Intrusive_Ref_Count_Handle_T.inl 72684 2006-05-17 19:12:46Z dai_y $ 00004 00005 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00006 00007 template <typename T> 00008 ACE_INLINE 00009 TAO_Intrusive_Ref_Count_Handle<T>::TAO_Intrusive_Ref_Count_Handle (void) 00010 : ptr_(0) 00011 { 00012 } 00013 00014 00015 template <typename T> 00016 ACE_INLINE 00017 TAO_Intrusive_Ref_Count_Handle<T>::TAO_Intrusive_Ref_Count_Handle ( 00018 T* p, 00019 bool take_ownership) 00020 : ptr_(p) 00021 { 00022 if (!take_ownership) 00023 { 00024 this->claim (); 00025 } 00026 } 00027 00028 00029 template <typename T> 00030 ACE_INLINE 00031 TAO_Intrusive_Ref_Count_Handle<T>::TAO_Intrusive_Ref_Count_Handle ( 00032 const TAO_Intrusive_Ref_Count_Handle<T>& b) 00033 : ptr_(b.ptr_) 00034 { 00035 this->claim(); 00036 } 00037 00038 00039 template <typename T> 00040 ACE_INLINE 00041 TAO_Intrusive_Ref_Count_Handle<T>::~TAO_Intrusive_Ref_Count_Handle() 00042 { 00043 this->drop(); 00044 } 00045 00046 00047 template <typename T> 00048 ACE_INLINE 00049 TAO_Intrusive_Ref_Count_Handle<T>& 00050 TAO_Intrusive_Ref_Count_Handle<T>::operator=(T* p) 00051 { 00052 TAO_Intrusive_Ref_Count_Handle<T> tmp (p); 00053 return this->operator= (tmp); 00054 } 00055 00056 00057 template <typename T> 00058 ACE_INLINE 00059 TAO_Intrusive_Ref_Count_Handle<T>& 00060 TAO_Intrusive_Ref_Count_Handle<T>::operator= 00061 (const TAO_Intrusive_Ref_Count_Handle<T>& b) 00062 { 00063 // Strongly exception-safe assignment through the usual copy and 00064 // swap technique. 00065 00066 TAO_Intrusive_Ref_Count_Handle<T> tmp (b); 00067 00068 T * old_ptr = this->ptr_; 00069 this->ptr_ = tmp.ptr_; 00070 tmp.ptr_ = old_ptr; 00071 00072 return *this; 00073 } 00074 00075 00076 template <typename T> 00077 ACE_INLINE 00078 T* 00079 TAO_Intrusive_Ref_Count_Handle<T>::operator->() const 00080 { 00081 return this->ptr_; 00082 } 00083 00084 00085 template <typename T> 00086 ACE_INLINE 00087 bool 00088 TAO_Intrusive_Ref_Count_Handle<T>::is_nil() const 00089 { 00090 return this->ptr_ == 0; 00091 } 00092 00093 00094 template <typename T> 00095 ACE_INLINE 00096 T* 00097 TAO_Intrusive_Ref_Count_Handle<T>::in() const 00098 { 00099 return this->ptr_; 00100 } 00101 00102 00103 template <typename T> 00104 ACE_INLINE 00105 T*& 00106 TAO_Intrusive_Ref_Count_Handle<T>::inout() 00107 { 00108 return this->ptr_; 00109 } 00110 00111 00112 template <typename T> 00113 ACE_INLINE 00114 T*& 00115 TAO_Intrusive_Ref_Count_Handle<T>::out() 00116 { 00117 this->drop(); 00118 return this->ptr_; 00119 } 00120 00121 00122 template <typename T> 00123 ACE_INLINE 00124 T* 00125 TAO_Intrusive_Ref_Count_Handle<T>::_retn() 00126 { 00127 T* retval = this->ptr_; 00128 this->ptr_ = 0; 00129 return retval; 00130 } 00131 00132 00133 template <typename T> 00134 ACE_INLINE 00135 void 00136 TAO_Intrusive_Ref_Count_Handle<T>::claim() 00137 { 00138 if (this->ptr_ != 0) 00139 { 00140 this->ptr_->_add_ref(); 00141 } 00142 } 00143 00144 00145 template <typename T> 00146 ACE_INLINE 00147 void 00148 TAO_Intrusive_Ref_Count_Handle<T>::drop() 00149 { 00150 if (this->ptr_ != 0) 00151 { 00152 this->ptr_->_remove_ref(); 00153 this->ptr_ = 0; 00154 } 00155 } 00156 00157 TAO_END_VERSIONED_NAMESPACE_DECL