Auto_Ptr.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Auto_Ptr.h
00006  *
00007  *  Auto_Ptr.h,v 4.41 2006/01/11 19:54:41 ossama Exp
00008  *
00009  *  @author Doug Schmidt <schmidt@uci.edu>
00010  *  @author Irfan Pyarali <irfan@cs.wustl.edu>
00011  *  @author Jack Reeves <jack@fx.com>
00012  *  @author Dr. Harald M. Mueller <mueller@garwein.hai.siemens.co.at>
00013  */
00014 //=============================================================================
00015 
00016 #ifndef ACE_AUTO_PTR_H
00017 #define ACE_AUTO_PTR_H
00018 #include /**/ "ace/pre.h"
00019 
00020 #include "ace/config-all.h"
00021 
00022 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00023 # pragma once
00024 #endif /* ACE_LACKS_PRAGMA_ONCE */
00025 
00026 #if defined (_MSC_VER)
00027 // Suppress warning e.g. "return type for
00028 // 'ACE_Auto_Array_Pointer<type>::operator ->' is 'type *' (i.e., not a UDT
00029 // or reference to a UDT.  Will produce errors if applied using infix
00030 // notation)"
00031 #  pragma warning(push)
00032 #  pragma warning(disable: 4284)
00033 #endif /* _MSC_VER */
00034 
00035 
00036 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00037 
00038 /**
00039  * @class ACE_Auto_Basic_Ptr
00040  *
00041  * @brief Implements the draft C++ standard auto_ptr abstraction.
00042  * This class allows one to work on non-object (basic) types
00043  */
00044 template <class X>
00045 class ACE_Auto_Basic_Ptr
00046 {
00047 public:
00048   // = Initialization and termination methods
00049   explicit ACE_Auto_Basic_Ptr (X *p = 0) : p_ (p) {}
00050 
00051   ACE_Auto_Basic_Ptr (ACE_Auto_Basic_Ptr<X> &ap);
00052   ACE_Auto_Basic_Ptr<X> &operator= (ACE_Auto_Basic_Ptr<X> &rhs);
00053   ~ACE_Auto_Basic_Ptr (void);
00054 
00055   // = Accessor methods.
00056   X &operator *() const;
00057   X *get (void) const;
00058   X *release (void);
00059   void reset (X *p = 0);
00060 
00061   /// Dump the state of an object.
00062   void dump (void) const;
00063 
00064   /// Declare the dynamic allocation hooks.
00065   ACE_ALLOC_HOOK_DECLARE;
00066 
00067 protected:
00068   X *p_;
00069 };
00070 
00071 ACE_END_VERSIONED_NAMESPACE_DECL
00072 
00073 #if !defined (ACE_LACKS_AUTO_PTR) && \
00074      defined (ACE_HAS_STANDARD_CPP_LIBRARY) && \
00075             (ACE_HAS_STANDARD_CPP_LIBRARY != 0)
00076 #include <memory>
00077 #if defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB) && \
00078             (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB != 0)
00079 using std::auto_ptr;
00080 #endif /* ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB */
00081 #else /* ACE_HAS_STANDARD_CPP_LIBRARY */
00082 
00083 /**
00084  * @class auto_ptr
00085  *
00086  * @brief Implements the draft C++ standard auto_ptr abstraction.
00087  */
00088 template <class X>
00089 class auto_ptr : public ACE_Auto_Basic_Ptr <X>
00090 {
00091 public:
00092   // = Initialization and termination methods
00093   explicit auto_ptr (X *p = 0) : ACE_Auto_Basic_Ptr<X> (p) {}
00094   auto_ptr (auto_ptr<X> &ap) : ACE_Auto_Basic_Ptr<X> (ap.release()) {}
00095 
00096   X *operator-> () const;
00097 };
00098 
00099 #endif /* ACE_HAS_STANDARD_CPP_LIBRARY */
00100 
00101 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00102 
00103 /**
00104  * @brief Implements the draft C++ standard auto_ptr abstraction.
00105  * This version can be used instead of auto_ptr<T>, and obviates
00106  * the need for the ACE_AUTO_PTR_RESET macro on platforms like
00107  * VC6 where the auto_ptr<T> is broken.
00108  */
00109 template <class X>
00110 class ACE_Auto_Ptr : public ACE_Auto_Basic_Ptr <X>
00111 {
00112 public:
00113   // = Initialization and termination methods
00114   explicit ACE_Auto_Ptr (X *p = 0) : ACE_Auto_Basic_Ptr<X> (p) {}
00115 
00116   X *operator-> () const;
00117 };
00118 
00119 /**
00120  * @class ACE_Auto_Basic_Array_Ptr
00121  *
00122  * @brief Implements an extension to the draft C++ standard auto_ptr
00123  * abstraction.  This class allows one to work on non-object
00124  * (basic) types that must be treated as an array, e.g.,
00125  * deallocated via "delete [] foo".
00126  */
00127 template<class X>
00128 class ACE_Auto_Basic_Array_Ptr
00129 {
00130 public:
00131   // = Initialization and termination methods.
00132   explicit ACE_Auto_Basic_Array_Ptr (X *p = 0) : p_ (p) {}
00133 
00134   ACE_Auto_Basic_Array_Ptr (ACE_Auto_Basic_Array_Ptr<X> &ap);
00135   ACE_Auto_Basic_Array_Ptr<X> &operator= (ACE_Auto_Basic_Array_Ptr<X> &rhs);
00136   ~ACE_Auto_Basic_Array_Ptr (void);
00137 
00138   // = Accessor methods.
00139   X &operator* () const;
00140   X &operator[] (int i) const;
00141   X *get (void) const;
00142   X *release (void);
00143   void reset (X *p = 0);
00144 
00145   /// Dump the state of an object.
00146   void dump (void) const;
00147 
00148   /// Declare the dynamic allocation hooks.
00149   ACE_ALLOC_HOOK_DECLARE;
00150 
00151 protected:
00152   X *p_;
00153 };
00154 
00155 /**
00156  * @class ACE_Auto_Array_Ptr
00157  *
00158  * @brief Implements an extension to the draft C++ standard auto_ptr
00159  * abstraction.
00160  */
00161 template<class X>
00162 class ACE_Auto_Array_Ptr : public ACE_Auto_Basic_Array_Ptr<X>
00163 {
00164 public:
00165   // = Initialization and termination methods.
00166   explicit ACE_Auto_Array_Ptr (X *p = 0)
00167     : ACE_Auto_Basic_Array_Ptr<X> (p) {}
00168 
00169   X *operator-> () const;
00170 };
00171 
00172 ACE_END_VERSIONED_NAMESPACE_DECL
00173 
00174 // Some platforms have an older version of auto_ptr
00175 // support, which lacks reset, and cannot be disabled
00176 // easily.  Portability to these platforms requires
00177 // use of the following ACE_AUTO_PTR_RESET macro.
00178 //
00179 // Note that this macro correctly handles the case where NEWPTR may be
00180 // a call to operator new(), e.g. "new foo", by making sure it is only
00181 // evaluated once.
00182 # if defined (ACE_AUTO_PTR_LACKS_RESET)
00183 #   define ACE_AUTO_PTR_RESET(AUTOPTR,NEWPTR,TYPE) \
00184       do { \
00185         TYPE * tmp_ptr = NEWPTR; \
00186         if (tmp_ptr != AUTOPTR.get ()) \
00187           { \
00188             delete AUTOPTR.release (); \
00189             AUTOPTR = auto_ptr<TYPE> (tmp_ptr); \
00190           } \
00191       } while (0)
00192 # else /* ! ACE_AUTO_PTR_LACKS_RESET */
00193 #   define ACE_AUTO_PTR_RESET(AUTOPTR,NEWPTR,TYPE) \
00194       do { \
00195          AUTOPTR.reset (NEWPTR); \
00196       } while (0)
00197 # endif /* ACE_AUTO_PTR_LACKS_RESET */
00198 
00199 #if defined (__ACE_INLINE__)
00200 #include "ace/Auto_Ptr.inl"
00201 #endif /* __ACE_INLINE__ */
00202 
00203 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00204 #include "ace/Auto_Ptr.cpp"
00205 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00206 
00207 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00208 #pragma implementation ("Auto_Ptr.cpp")
00209 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00210 
00211 #if defined (_MSC_VER)
00212 // Restore the warning state to what it was before entry.
00213 #  pragma warning(pop)
00214 #endif /* _MSC_VER */
00215 
00216 #include /**/ "ace/post.h"
00217 #endif /* ACE_AUTO_PTR_H */

Generated on Thu Nov 9 09:41:46 2006 for ACE by doxygen 1.3.6