00001 // -*- C++ -*- 00002 // 00003 // $Id: EC_Lifetime_Utils_T.inl 76626 2007-01-26 13:50:03Z elliott_c $ 00004 00005 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00006 00007 template <class T> 00008 ACE_INLINE 00009 TAO_EC_Auto_Command<T>::TAO_EC_Auto_Command (void) 00010 : command_ () 00011 , allow_command_ (0) 00012 { 00013 } 00014 00015 template <class T> 00016 ACE_INLINE 00017 TAO_EC_Auto_Command<T>::TAO_EC_Auto_Command (const T & command) 00018 : command_ (command) 00019 , allow_command_ (1) 00020 { 00021 } 00022 00023 template <class T> 00024 ACE_INLINE 00025 TAO_EC_Auto_Command<T>::~TAO_EC_Auto_Command (void) 00026 { 00027 this->execute (); 00028 } 00029 00030 template <class T> 00031 ACE_INLINE void 00032 TAO_EC_Auto_Command<T>::set_command (const T & command) 00033 { 00034 this->command_ = command; 00035 this->allow_command_ = 1; 00036 } 00037 00038 template <class T> 00039 ACE_INLINE void 00040 TAO_EC_Auto_Command<T>::set_command (TAO_EC_Auto_Command<T> & auto_command) 00041 { 00042 if (this == &auto_command) 00043 return; 00044 00045 this->command_ = auto_command.command_; 00046 this->allow_command_ = auto_command.allow_command_; 00047 auto_command.allow_command_ = 0; 00048 } 00049 00050 template <class T> 00051 ACE_INLINE void 00052 TAO_EC_Auto_Command<T>::execute (void) 00053 { 00054 if (this->allow_command_) 00055 { 00056 this->allow_command_ = 0; 00057 00058 try 00059 { 00060 this->command_.execute (); 00061 } 00062 catch (const CORBA::Exception&) 00063 { 00064 // ignore. 00065 } 00066 } 00067 } 00068 00069 template <class T> 00070 ACE_INLINE void 00071 TAO_EC_Auto_Command<T>::allow_command (void) 00072 { 00073 this->allow_command_ = 1; 00074 } 00075 00076 template <class T> 00077 ACE_INLINE void 00078 TAO_EC_Auto_Command<T>::disallow_command (void) 00079 { 00080 this->allow_command_ = 0; 00081 } 00082 00083 00084 //*************************************************************************** 00085 00086 template <class T> 00087 ACE_INLINE 00088 TAO_EC_Shutdown_Command<T>::TAO_EC_Shutdown_Command (void) 00089 : target_ () 00090 { 00091 } 00092 00093 template <class T> 00094 ACE_INLINE 00095 TAO_EC_Shutdown_Command<T>::TAO_EC_Shutdown_Command (T target) 00096 : target_ (target) 00097 { 00098 } 00099 00100 template <class T> 00101 ACE_INLINE void 00102 TAO_EC_Shutdown_Command<T>::execute (void) 00103 { 00104 if (this->target_.in ()) 00105 { 00106 this->target_->shutdown (); 00107 } 00108 } 00109 00110 //*************************************************************************** 00111 00112 00113 TAO_END_VERSIONED_NAMESPACE_DECL 00114 00115 // Life would be much easier if _add_ref() and _remove_ref() 00116 // had throw specs of "throw ()" 00117 00118 #include <algorithm> 00119 00120 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00121 00122 template <class T> 00123 ACE_INLINE TAO_EC_Servant_Var<T>:: 00124 TAO_EC_Servant_Var(T * p) 00125 : ptr_(p) 00126 { 00127 } 00128 00129 // If _add_ref throws, this object will not be completely constructed 00130 // so the destructor will not be called. 00131 template <class T> 00132 ACE_INLINE TAO_EC_Servant_Var<T>:: 00133 TAO_EC_Servant_Var(TAO_EC_Servant_Var<T> const & rhs) 00134 : ptr_(rhs.ptr_) 00135 { 00136 if (ptr_) 00137 { 00138 try 00139 { 00140 ptr_->_add_ref (); 00141 } 00142 catch (...) 00143 { 00144 throw; 00145 } 00146 } 00147 } 00148 00149 template <class T> 00150 ACE_INLINE TAO_EC_Servant_Var<T> & TAO_EC_Servant_Var<T>:: 00151 operator=(TAO_EC_Servant_Var<T> const & rhs) 00152 { 00153 TAO_EC_Servant_Var<T> tmp(rhs); 00154 00155 // std::swap(tmp.ptr_, ptr_); 00156 T * swap_temp = tmp.ptr_; 00157 tmp.ptr_ = ptr_; 00158 ptr_ = swap_temp; 00159 00160 return *this; 00161 } 00162 00163 template <class T> 00164 ACE_INLINE TAO_EC_Servant_Var<T> & TAO_EC_Servant_Var<T>:: 00165 operator=(T * p) 00166 { 00167 TAO_EC_Servant_Var<T> tmp(p); 00168 00169 // std::swap(tmp.ptr_, ptr_); 00170 T * swap_temp = tmp.ptr_; 00171 tmp.ptr_ = ptr_; 00172 ptr_ = swap_temp; 00173 00174 return *this; 00175 } 00176 00177 template <class T> 00178 ACE_INLINE TAO_EC_Servant_Var<T>:: 00179 ~TAO_EC_Servant_Var() 00180 { 00181 // Unfortunately, there is no throw spec on _remove_ref, so we 00182 // can't assume that it will not throw. If it does, then we are in 00183 // trouble. In any event, we can't let the exception escape our 00184 // destructor. 00185 if (ptr_ != 0) 00186 { 00187 try 00188 { 00189 ptr_->_remove_ref (); 00190 } 00191 catch (...) 00192 { 00193 } 00194 } 00195 } 00196 00197 #if !defined(ACE_LACKS_MEMBER_TEMPLATES) 00198 template <class T> template <class Y> 00199 ACE_INLINE TAO_EC_Servant_Var<T>:: 00200 TAO_EC_Servant_Var(Y * p) 00201 : ptr_(p) 00202 { 00203 } 00204 00205 template <class T> template <class Y> 00206 ACE_INLINE TAO_EC_Servant_Var<T>:: 00207 TAO_EC_Servant_Var(TAO_EC_Servant_Var<Y> const & rhs) 00208 : ptr_(rhs.in()) 00209 { 00210 if (ptr_) 00211 { 00212 ptr_->_add_ref(); 00213 } 00214 } 00215 00216 template <class T> template <class Y> 00217 ACE_INLINE TAO_EC_Servant_Var<T> & TAO_EC_Servant_Var<T>:: 00218 operator=(TAO_EC_Servant_Var<Y> const & rhs) 00219 { 00220 TAO_EC_Servant_Var<T> tmp(rhs); 00221 00222 // std::swap(tmp.ptr_, ptr_); 00223 T * swap_temp = tmp.ptr_; 00224 tmp.ptr_ = ptr_; 00225 ptr_ = swap_temp; 00226 00227 return *this; 00228 } 00229 00230 template <class T> template <class Y> 00231 ACE_INLINE TAO_EC_Servant_Var<T> & TAO_EC_Servant_Var<T>:: 00232 operator=(Y * p) 00233 { 00234 TAO_EC_Servant_Var<T> tmp(p); 00235 00236 // std::swap(tmp.ptr_, ptr_); 00237 T * swap_temp = tmp.ptr_; 00238 tmp.ptr_ = ptr_; 00239 ptr_ = swap_temp; 00240 00241 return *this; 00242 } 00243 #endif /* ACE_LACKS_MEMBER_TEMPLATES */ 00244 00245 template <class T> 00246 ACE_INLINE T const * TAO_EC_Servant_Var<T>:: 00247 operator->() const 00248 { 00249 return ptr_; 00250 } 00251 00252 template <class T> 00253 ACE_INLINE T * TAO_EC_Servant_Var<T>:: 00254 operator->() 00255 { 00256 return ptr_; 00257 } 00258 00259 template <class T> 00260 ACE_INLINE T const & TAO_EC_Servant_Var<T>:: 00261 operator*() const 00262 { 00263 return *ptr_; 00264 } 00265 00266 template <class T> 00267 ACE_INLINE T & TAO_EC_Servant_Var<T>:: 00268 operator*() 00269 { 00270 return *ptr_; 00271 } 00272 00273 template <class T> 00274 ACE_INLINE TAO_EC_Servant_Var<T>:: 00275 operator void const * () const 00276 { 00277 return ptr_; 00278 } 00279 00280 template <class T> 00281 ACE_INLINE T * TAO_EC_Servant_Var<T>:: 00282 in() const 00283 { 00284 return ptr_; 00285 } 00286 00287 template <class T> 00288 ACE_INLINE T *& TAO_EC_Servant_Var<T>:: 00289 inout() 00290 { 00291 return ptr_; 00292 } 00293 00294 template <class T> 00295 ACE_INLINE T *& TAO_EC_Servant_Var<T>:: 00296 out() 00297 { 00298 TAO_EC_Servant_Var<T> tmp; 00299 00300 // std::swap(tmp.ptr_, ptr_); 00301 T * swap_temp = tmp.ptr_; 00302 tmp.ptr_ = ptr_; 00303 ptr_ = swap_temp; 00304 00305 return ptr_; 00306 } 00307 00308 template <class T> 00309 ACE_INLINE T * TAO_EC_Servant_Var<T>:: 00310 _retn() 00311 { 00312 T * rval = ptr_; 00313 ptr_ = 0; 00314 return rval; 00315 } 00316 00317 template <class X, class Y> 00318 ACE_INLINE bool 00319 operator==(TAO_EC_Servant_Var<X> const & x, 00320 TAO_EC_Servant_Var<Y> const & y) 00321 { 00322 return x.in() == y.in(); 00323 } 00324 00325 template <class X, class Y> 00326 ACE_INLINE bool 00327 operator!=(TAO_EC_Servant_Var<X> const & x, 00328 TAO_EC_Servant_Var<Y> const & y) 00329 { 00330 return x.in() != y.in(); 00331 } 00332 00333 TAO_END_VERSIONED_NAMESPACE_DECL