00001 // -*- C++ -*- 00002 // 00003 // EC_Lifetime_Utils_T.i,v 1.6 2005/11/24 11:05:44 ossama Exp 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 ACE_TRY_NEW_ENV 00059 { 00060 this->command_.execute (ACE_ENV_SINGLE_ARG_PARAMETER); 00061 ACE_TRY_CHECK; 00062 } 00063 ACE_CATCHANY 00064 { 00065 // ignore. 00066 } 00067 ACE_ENDTRY; 00068 } 00069 } 00070 00071 template <class T> 00072 ACE_INLINE void 00073 TAO_EC_Auto_Command<T>::allow_command (void) 00074 { 00075 this->allow_command_ = 1; 00076 } 00077 00078 template <class T> 00079 ACE_INLINE void 00080 TAO_EC_Auto_Command<T>::disallow_command (void) 00081 { 00082 this->allow_command_ = 0; 00083 } 00084 00085 00086 //*************************************************************************** 00087 00088 template <class T> 00089 ACE_INLINE 00090 TAO_EC_Shutdown_Command<T>::TAO_EC_Shutdown_Command (void) 00091 : target_ () 00092 { 00093 } 00094 00095 template <class T> 00096 ACE_INLINE 00097 TAO_EC_Shutdown_Command<T>::TAO_EC_Shutdown_Command (T target) 00098 : target_ (target) 00099 { 00100 } 00101 00102 template <class T> 00103 ACE_INLINE void 00104 TAO_EC_Shutdown_Command<T>::execute (ACE_ENV_SINGLE_ARG_DECL) 00105 { 00106 if (this->target_.in ()) 00107 { 00108 this->target_->shutdown (ACE_ENV_SINGLE_ARG_PARAMETER); 00109 ACE_CHECK; 00110 } 00111 } 00112 00113 //*************************************************************************** 00114 00115 00116 TAO_END_VERSIONED_NAMESPACE_DECL 00117 00118 // Life would be much easier if _add_ref() and _remove_ref() 00119 // had throw specs of "throw ()" 00120 00121 #include <algorithm> 00122 00123 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00124 00125 template <class T> 00126 ACE_INLINE TAO_EC_Servant_Var<T>:: 00127 TAO_EC_Servant_Var(T * p) 00128 : ptr_(p) 00129 { 00130 } 00131 00132 // If _add_ref throws, this object will not be completely constructed 00133 // so the destructor will not be called. 00134 template <class T> 00135 ACE_INLINE TAO_EC_Servant_Var<T>:: 00136 TAO_EC_Servant_Var(TAO_EC_Servant_Var<T> const & rhs) 00137 : ptr_(rhs.ptr_) 00138 { 00139 if (ptr_) 00140 { 00141 ACE_TRY_NEW_ENV 00142 { 00143 ptr_->_add_ref (ACE_ENV_SINGLE_ARG_PARAMETER); 00144 ACE_TRY_CHECK; 00145 } 00146 ACE_CATCHALL 00147 { 00148 ACE_RE_THROW; 00149 } 00150 ACE_ENDTRY; 00151 } 00152 } 00153 00154 template <class T> 00155 ACE_INLINE TAO_EC_Servant_Var<T> & TAO_EC_Servant_Var<T>:: 00156 operator=(TAO_EC_Servant_Var<T> const & rhs) 00157 { 00158 TAO_EC_Servant_Var<T> tmp(rhs); 00159 00160 // std::swap(tmp.ptr_, ptr_); 00161 T * swap_temp = tmp.ptr_; 00162 tmp.ptr_ = ptr_; 00163 ptr_ = swap_temp; 00164 00165 return *this; 00166 } 00167 00168 template <class T> 00169 ACE_INLINE TAO_EC_Servant_Var<T> & TAO_EC_Servant_Var<T>:: 00170 operator=(T * p) 00171 { 00172 TAO_EC_Servant_Var<T> tmp(p); 00173 00174 // std::swap(tmp.ptr_, ptr_); 00175 T * swap_temp = tmp.ptr_; 00176 tmp.ptr_ = ptr_; 00177 ptr_ = swap_temp; 00178 00179 return *this; 00180 } 00181 00182 template <class T> 00183 ACE_INLINE TAO_EC_Servant_Var<T>:: 00184 ~TAO_EC_Servant_Var() 00185 { 00186 // Unfortunately, there is no throw spec on _remove_ref, so we 00187 // can't assume that it will not throw. If it does, then we are in 00188 // trouble. In any event, we can't let the exception escape our 00189 // destructor. 00190 if (ptr_ != 0) 00191 { 00192 ACE_TRY_NEW_ENV 00193 { 00194 ptr_->_remove_ref (ACE_ENV_SINGLE_ARG_PARAMETER); 00195 ACE_TRY_CHECK; 00196 } 00197 ACE_CATCHALL 00198 { 00199 } 00200 ACE_ENDTRY; 00201 } 00202 } 00203 00204 #if !defined(ACE_LACKS_MEMBER_TEMPLATES) 00205 template <class T> template <class Y> 00206 ACE_INLINE TAO_EC_Servant_Var<T>:: 00207 TAO_EC_Servant_Var(Y * p) 00208 : ptr_(p) 00209 { 00210 } 00211 00212 template <class T> template <class Y> 00213 ACE_INLINE TAO_EC_Servant_Var<T>:: 00214 TAO_EC_Servant_Var(TAO_EC_Servant_Var<Y> const & rhs) 00215 : ptr_(rhs.in()) 00216 { 00217 if (ptr_) 00218 { 00219 ptr_->_add_ref(); 00220 } 00221 } 00222 00223 template <class T> template <class Y> 00224 ACE_INLINE TAO_EC_Servant_Var<T> & TAO_EC_Servant_Var<T>:: 00225 operator=(TAO_EC_Servant_Var<Y> const & rhs) 00226 { 00227 TAO_EC_Servant_Var<T> tmp(rhs); 00228 00229 // std::swap(tmp.ptr_, ptr_); 00230 T * swap_temp = tmp.ptr_; 00231 tmp.ptr_ = ptr_; 00232 ptr_ = swap_temp; 00233 00234 return *this; 00235 } 00236 00237 template <class T> template <class Y> 00238 ACE_INLINE TAO_EC_Servant_Var<T> & TAO_EC_Servant_Var<T>:: 00239 operator=(Y * p) 00240 { 00241 TAO_EC_Servant_Var<T> tmp(p); 00242 00243 // std::swap(tmp.ptr_, ptr_); 00244 T * swap_temp = tmp.ptr_; 00245 tmp.ptr_ = ptr_; 00246 ptr_ = swap_temp; 00247 00248 return *this; 00249 } 00250 #endif /* ACE_LACKS_MEMBER_TEMPLATES */ 00251 00252 template <class T> 00253 ACE_INLINE T const * TAO_EC_Servant_Var<T>:: 00254 operator->() const 00255 { 00256 return ptr_; 00257 } 00258 00259 template <class T> 00260 ACE_INLINE T * TAO_EC_Servant_Var<T>:: 00261 operator->() 00262 { 00263 return ptr_; 00264 } 00265 00266 template <class T> 00267 ACE_INLINE T const & TAO_EC_Servant_Var<T>:: 00268 operator*() const 00269 { 00270 return *ptr_; 00271 } 00272 00273 template <class T> 00274 ACE_INLINE T & TAO_EC_Servant_Var<T>:: 00275 operator*() 00276 { 00277 return *ptr_; 00278 } 00279 00280 template <class T> 00281 ACE_INLINE TAO_EC_Servant_Var<T>:: 00282 operator void const * () const 00283 { 00284 return ptr_; 00285 } 00286 00287 template <class T> 00288 ACE_INLINE T * TAO_EC_Servant_Var<T>:: 00289 in() const 00290 { 00291 return ptr_; 00292 } 00293 00294 template <class T> 00295 ACE_INLINE T *& TAO_EC_Servant_Var<T>:: 00296 inout() 00297 { 00298 return ptr_; 00299 } 00300 00301 template <class T> 00302 ACE_INLINE T *& TAO_EC_Servant_Var<T>:: 00303 out() 00304 { 00305 TAO_EC_Servant_Var<T> tmp; 00306 00307 // std::swap(tmp.ptr_, ptr_); 00308 T * swap_temp = tmp.ptr_; 00309 tmp.ptr_ = ptr_; 00310 ptr_ = swap_temp; 00311 00312 return ptr_; 00313 } 00314 00315 template <class T> 00316 ACE_INLINE T * TAO_EC_Servant_Var<T>:: 00317 _retn() 00318 { 00319 T * rval = ptr_; 00320 ptr_ = 0; 00321 return rval; 00322 } 00323 00324 template <class X, class Y> 00325 ACE_INLINE bool 00326 operator==(TAO_EC_Servant_Var<X> const & x, 00327 TAO_EC_Servant_Var<Y> const & y) 00328 { 00329 return x.in() == y.in(); 00330 } 00331 00332 template <class X, class Y> 00333 ACE_INLINE bool 00334 operator!=(TAO_EC_Servant_Var<X> const & x, 00335 TAO_EC_Servant_Var<Y> const & y) 00336 { 00337 return x.in() != y.in(); 00338 } 00339 00340 TAO_END_VERSIONED_NAMESPACE_DECL