diff options
Diffstat (limited to 'TAO/tao/VarOut_T.cpp')
-rw-r--r-- | TAO/tao/VarOut_T.cpp | 96 |
1 files changed, 68 insertions, 28 deletions
diff --git a/TAO/tao/VarOut_T.cpp b/TAO/tao/VarOut_T.cpp index 85a31f687e4..618198edfad 100644 --- a/TAO/tao/VarOut_T.cpp +++ b/TAO/tao/VarOut_T.cpp @@ -1,7 +1,7 @@ // $Id$ -#ifndef TAO_VAROUT_T_CPP -#define TAO_VAROUT_T_CPP +#ifndef TAO_VAROUT_T_C +#define TAO_VAROUT_T_C #include "tao/VarOut_T.h" @@ -9,12 +9,22 @@ #include "tao/VarOut_T.inl" #endif /* __ACE_INLINE__ */ -TAO_BEGIN_VERSIONED_NAMESPACE_DECL +ACE_RCSID (tao, + VarOut_T, + "$Id$") template<typename T> TAO_Var_Base_T<T>::TAO_Var_Base_T (const TAO_Var_Base_T<T> & p) - : ptr_ (p.ptr_ ? new T (*p.ptr_) : 0) { + if (p.ptr_) + { + ACE_NEW (this->ptr_, + T (*p.ptr_)); + } + else + { + this->ptr_ = 0; + } } // ************************************************************* @@ -23,13 +33,29 @@ template<typename T> TAO_Fixed_Var_T<T> & TAO_Fixed_Var_T<T>::operator= (const TAO_Fixed_Var_T<T> & p) { - // Strongly exception safe assignment using copy and non-throwing - // swap technique. - TAO_Fixed_Var_T<T> tmp (p); - - T * old_ptr = this->ptr_; - this->ptr_ = tmp.ptr_; - tmp.ptr_ = old_ptr; + if (this != &p) + { + if (p.ptr_ == 0) + { + delete this->ptr_; + this->ptr_ = 0; + } + else + { + T * deep_copy = 0; + ACE_NEW_RETURN (deep_copy, + T (*p.ptr_), + *this); + + if (deep_copy != 0) + { + T * tmp = deep_copy; + deep_copy = this->ptr_; + this->ptr_ = tmp; + delete deep_copy; + } + } + } return *this; } @@ -39,13 +65,13 @@ template<typename T> TAO_Fixed_Var_T<T> & TAO_Fixed_Var_T<T>::operator= (const T & p) { - // Strongly exception safe assignment using copy and non-throwing - // swap technique. - TAO_Fixed_Var_T<T> tmp (p); - - T * old_ptr = this->ptr_; - this->ptr_ = tmp.ptr_; - tmp.ptr_ = old_ptr; + if (this->ptr_ != &p) + { + delete this->ptr_; + ACE_NEW_RETURN (this->ptr_, + T (p), + *this); + } return *this; } @@ -56,17 +82,31 @@ template<typename T> TAO_Var_Var_T<T> & TAO_Var_Var_T<T>::operator= (const TAO_Var_Var_T<T> & p) { - // Strongly exception safe assignment using copy and non-throwing - // swap technique. - TAO_Var_Var_T<T> tmp (p); - - T * old_ptr = this->ptr_; - this->ptr_ = tmp.ptr_; - tmp.ptr_ = old_ptr; + if (this != &p) + { + if (p.ptr_ == 0) + { + delete this->ptr_; + this->ptr_ = 0; + } + else + { + T *deep_copy = 0; + ACE_NEW_RETURN (deep_copy, + T (*p.ptr_), + *this); + + if (deep_copy != 0) + { + T * tmp = deep_copy; + deep_copy = this->ptr_; + this->ptr_ = tmp; + delete deep_copy; + } + } + } return *this; } -TAO_END_VERSIONED_NAMESPACE_DECL - -#endif /* TAO_VAROUT_T_CPP */ +#endif /* TAO_VAROUT_T_C */ |