diff options
author | Ossama Othman <ossama-othman@users.noreply.github.com> | 2006-10-25 23:43:38 +0000 |
---|---|---|
committer | Ossama Othman <ossama-othman@users.noreply.github.com> | 2006-10-25 23:43:38 +0000 |
commit | 98c3453c7a9cd05646863fea38dddfc9afc09c19 (patch) | |
tree | 588e17fb0fa42c3d57b62b8953fd5a3204f9773c | |
parent | d28774dc49e367dab02e7a61c89ce0de6f6f97d6 (diff) | |
download | ATCD-98c3453c7a9cd05646863fea38dddfc9afc09c19.tar.gz |
ChangeLogTag:Wed Oct 26 00:31:56 UTC 2006 Ossama Othman <ossama_othman at symantec dot com>
-rw-r--r-- | ACE/ChangeLog | 22 | ||||
-rw-r--r-- | ACE/ace/Auto_Ptr.h | 106 |
2 files changed, 87 insertions, 41 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog index 493b4200c46..67d78c86c1d 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,25 @@ +Wed Oct 26 00:31:56 UTC 2006 Ossama Othman <ossama_othman at symantec dot com> + + * ace/Auto_Ptr.h: + + Added missing "element_type" typedef. + + (ACE_auto_ptr_reset): + + Introduced this new function template to simplify the + ACE_AUTO_PTR_RESET macro implementation, to support + ACE's other auto_ptr-like class templates + (e.g. ACE_Auto_Array_Ptr<>), and to make auto_ptr + reset() operations convenient and easy for those needing the + ACE_AUTO_PTR_RESET functionality to. Users now need only + perform a call like: + + ACE_auto_ptr_reset (my_auto_ptr_instance, new foo); + + This build failures on platforms that define + ACE_LACKS_AUTO_PTR_RESET and in code that expects to use + ACE_AUTO_PTR_RESET on ACE_Auto_{Basic_}_Array<> instances. + Wed Oct 25 22:42:03 UTC 2006 Ossama Othman <ossama_othman at symantec dot com> * tests/Integer_Truncate_Test.cpp: diff --git a/ACE/ace/Auto_Ptr.h b/ACE/ace/Auto_Ptr.h index 3047079691e..c23cde8b826 100644 --- a/ACE/ace/Auto_Ptr.h +++ b/ACE/ace/Auto_Ptr.h @@ -41,22 +41,24 @@ ACE_BEGIN_VERSIONED_NAMESPACE_DECL * @brief Implements the draft C++ standard auto_ptr abstraction. * This class allows one to work on non-object (basic) types */ -template <class X> +template <typename X> class ACE_Auto_Basic_Ptr { public: + typedef X element_type; + // = Initialization and termination methods - explicit ACE_Auto_Basic_Ptr (X *p = 0) : p_ (p) {} + explicit ACE_Auto_Basic_Ptr (X * p = 0) : p_ (p) {} - ACE_Auto_Basic_Ptr (ACE_Auto_Basic_Ptr<X> &ap); - ACE_Auto_Basic_Ptr<X> &operator= (ACE_Auto_Basic_Ptr<X> &rhs); + ACE_Auto_Basic_Ptr (ACE_Auto_Basic_Ptr<X> & ap); + ACE_Auto_Basic_Ptr<X> &operator= (ACE_Auto_Basic_Ptr<X> & rhs); ~ACE_Auto_Basic_Ptr (void); // = Accessor methods. X &operator *() const; X *get (void) const; X *release (void); - void reset (X *p = 0); + void reset (X * p = 0); /// Dump the state of an object. void dump (void) const; @@ -85,13 +87,15 @@ using std::auto_ptr; * * @brief Implements the draft C++ standard auto_ptr abstraction. */ -template <class X> -class auto_ptr : public ACE_Auto_Basic_Ptr <X> +template <typename X> +class auto_ptr : public ACE_Auto_Basic_Ptr<X> { public: + typedef X element_type; + // = Initialization and termination methods - explicit auto_ptr (X *p = 0) : ACE_Auto_Basic_Ptr<X> (p) {} - auto_ptr (auto_ptr<X> &ap) : ACE_Auto_Basic_Ptr<X> (ap.release()) {} + explicit auto_ptr (X * p = 0) : ACE_Auto_Basic_Ptr<X> (p) {} + auto_ptr (auto_ptr<X> & ap) : ACE_Auto_Basic_Ptr<X> (ap.release ()) {} X *operator-> () const; }; @@ -106,12 +110,14 @@ ACE_BEGIN_VERSIONED_NAMESPACE_DECL * the need for the ACE_AUTO_PTR_RESET macro on platforms like * VC6 where the auto_ptr<T> is broken. */ -template <class X> +template <typename X> class ACE_Auto_Ptr : public ACE_Auto_Basic_Ptr <X> { public: + typedef X element_type; + // = Initialization and termination methods - explicit ACE_Auto_Ptr (X *p = 0) : ACE_Auto_Basic_Ptr<X> (p) {} + explicit ACE_Auto_Ptr (X * p = 0) : ACE_Auto_Basic_Ptr<X> (p) {} X *operator-> () const; }; @@ -124,23 +130,25 @@ public: * (basic) types that must be treated as an array, e.g., * deallocated via "delete [] foo". */ -template<class X> +template<typename X> class ACE_Auto_Basic_Array_Ptr { public: + typedef X element_type; + // = Initialization and termination methods. - explicit ACE_Auto_Basic_Array_Ptr (X *p = 0) : p_ (p) {} + explicit ACE_Auto_Basic_Array_Ptr (X * p = 0) : p_ (p) {} - ACE_Auto_Basic_Array_Ptr (ACE_Auto_Basic_Array_Ptr<X> &ap); - ACE_Auto_Basic_Array_Ptr<X> &operator= (ACE_Auto_Basic_Array_Ptr<X> &rhs); + ACE_Auto_Basic_Array_Ptr (ACE_Auto_Basic_Array_Ptr<X> & ap); + ACE_Auto_Basic_Array_Ptr<X> &operator= (ACE_Auto_Basic_Array_Ptr<X> & rhs); ~ACE_Auto_Basic_Array_Ptr (void); // = Accessor methods. - X &operator* () const; - X &operator[] (int i) const; - X *get (void) const; - X *release (void); - void reset (X *p = 0); + X & operator* () const; + X & operator[] (int i) const; + X * get (void) const; + X * release (void); + void reset (X * p = 0); /// Dump the state of an object. void dump (void) const; @@ -149,7 +157,7 @@ public: ACE_ALLOC_HOOK_DECLARE; protected: - X *p_; + X * p_; }; /** @@ -158,10 +166,12 @@ protected: * @brief Implements an extension to the draft C++ standard auto_ptr * abstraction. */ -template<class X> +template<typename X> class ACE_Auto_Array_Ptr : public ACE_Auto_Basic_Array_Ptr<X> { public: + typedef X element_type; + // = Initialization and termination methods. explicit ACE_Auto_Array_Ptr (X *p = 0) : ACE_Auto_Basic_Array_Ptr<X> (p) {} @@ -169,6 +179,33 @@ public: X *operator-> () const; }; + +/** + * @function + * + * @brief + * + * Some platforms have an older version of auto_ptr support, which + * lacks reset, and cannot be disabled easily. Portability to these + * platforms requires use of this function template. This function + * template also works for the @c ACE_Auto_{Basic_}Array_Ptr class + * template, as well. + */ +template<typename AUTO_PTR_TYPE> +inline void +ACE_auto_ptr_reset (AUTO_PTR_TYPE & ap, + typename AUTO_PTR_TYPE::element_type * p) +{ +#if defined (ACE_AUTO_PTR_LACKS_RESET) + if (p != ap.get ()) + { + ap = AUTO_PTR_TYPE (p); + } +#else + ap.reset (p); +#endif /* ACE_AUTO_PTR_LACKS_RESET */ +} + ACE_END_VERSIONED_NAMESPACE_DECL // Some platforms have an older version of auto_ptr @@ -176,25 +213,12 @@ ACE_END_VERSIONED_NAMESPACE_DECL // easily. Portability to these platforms requires // use of the following ACE_AUTO_PTR_RESET macro. // -// Note that this macro correctly handles the case where NEWPTR may be -// a call to operator new(), e.g. "new foo", by making sure it is only -// evaluated once. -# if defined (ACE_AUTO_PTR_LACKS_RESET) -# define ACE_AUTO_PTR_RESET(AUTOPTR,NEWPTR,TYPE) \ - do { \ - TYPE * tmp_ptr = NEWPTR; \ - if (tmp_ptr != AUTOPTR.get ()) \ - { \ - delete AUTOPTR.release (); \ - AUTOPTR = auto_ptr<TYPE> (tmp_ptr); \ - } \ - } while (0) -# else /* ! ACE_AUTO_PTR_LACKS_RESET */ -# define ACE_AUTO_PTR_RESET(AUTOPTR,NEWPTR,TYPE) \ - do { \ - AUTOPTR.reset (NEWPTR); \ - } while (0) -# endif /* ACE_AUTO_PTR_LACKS_RESET */ +// The TYPE macro parameter is no longer necessary but we leave it +// around for backward compatibility. This is also the reason why the +// ACE_auto_ptr_reset function template is not called +// ACE_AUTO_PTR_RESET. +# define ACE_AUTO_PTR_RESET(AUTOPTR,NEWPTR,TYPE) \ + ACE_auto_ptr_reset (AUTOPTR, NEWPTR); #if defined (__ACE_INLINE__) #include "ace/Auto_Ptr.inl" |