00001 /* -*- C++ -*- */ 00002 00003 //============================================================================= 00004 /** 00005 * @file Auto_Ptr.h 00006 * 00007 * $Id: Auto_Ptr.h 77304 2007-02-21 22:29:49Z ossama $ 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 <typename X> 00045 class ACE_Auto_Basic_Ptr 00046 { 00047 public: 00048 typedef X element_type; 00049 00050 // = Initialization and termination methods 00051 explicit ACE_Auto_Basic_Ptr (X * p = 0) : p_ (p) {} 00052 00053 ACE_Auto_Basic_Ptr (ACE_Auto_Basic_Ptr<X> & ap); 00054 ACE_Auto_Basic_Ptr<X> &operator= (ACE_Auto_Basic_Ptr<X> & rhs); 00055 ~ACE_Auto_Basic_Ptr (void); 00056 00057 // = Accessor methods. 00058 X &operator *() const; 00059 X *get (void) const; 00060 X *release (void); 00061 void reset (X * p = 0); 00062 00063 /// Dump the state of an object. 00064 void dump (void) const; 00065 00066 /// Declare the dynamic allocation hooks. 00067 ACE_ALLOC_HOOK_DECLARE; 00068 00069 protected: 00070 X *p_; 00071 }; 00072 00073 ACE_END_VERSIONED_NAMESPACE_DECL 00074 00075 #if !defined (ACE_LACKS_AUTO_PTR) && \ 00076 defined (ACE_HAS_STANDARD_CPP_LIBRARY) && \ 00077 (ACE_HAS_STANDARD_CPP_LIBRARY != 0) 00078 #include <memory> 00079 #if defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB) && \ 00080 (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB != 0) 00081 using std::auto_ptr; 00082 #endif /* ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB */ 00083 #else /* ACE_HAS_STANDARD_CPP_LIBRARY */ 00084 00085 /** 00086 * @class auto_ptr 00087 * 00088 * @brief Implements the draft C++ standard auto_ptr abstraction. 00089 */ 00090 template <typename X> 00091 class auto_ptr : public ACE_Auto_Basic_Ptr<X> 00092 { 00093 public: 00094 typedef X element_type; 00095 00096 // = Initialization and termination methods 00097 explicit auto_ptr (X * p = 0) : ACE_Auto_Basic_Ptr<X> (p) {} 00098 auto_ptr (auto_ptr<X> & ap) : ACE_Auto_Basic_Ptr<X> (ap.release ()) {} 00099 00100 X *operator-> () const; 00101 }; 00102 00103 #endif /* ACE_HAS_STANDARD_CPP_LIBRARY */ 00104 00105 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00106 00107 /** 00108 * @brief Implements the draft C++ standard auto_ptr abstraction. 00109 * This version can be used instead of auto_ptr<T>, and obviates 00110 * the need for the ACE_AUTO_PTR_RESET macro on platforms like 00111 * VC6 where the auto_ptr<T> is broken. 00112 */ 00113 template <typename X> 00114 class ACE_Auto_Ptr : public ACE_Auto_Basic_Ptr <X> 00115 { 00116 public: 00117 typedef X element_type; 00118 00119 // = Initialization and termination methods 00120 explicit ACE_Auto_Ptr (X * p = 0) : ACE_Auto_Basic_Ptr<X> (p) {} 00121 00122 X *operator-> () const; 00123 }; 00124 00125 /** 00126 * @class ACE_Auto_Basic_Array_Ptr 00127 * 00128 * @brief Implements an extension to the draft C++ standard auto_ptr 00129 * abstraction. This class allows one to work on non-object 00130 * (basic) types that must be treated as an array, e.g., 00131 * deallocated via "delete [] foo". 00132 */ 00133 template<typename X> 00134 class ACE_Auto_Basic_Array_Ptr 00135 { 00136 public: 00137 typedef X element_type; 00138 00139 // = Initialization and termination methods. 00140 explicit ACE_Auto_Basic_Array_Ptr (X * p = 0) : p_ (p) {} 00141 00142 ACE_Auto_Basic_Array_Ptr (ACE_Auto_Basic_Array_Ptr<X> & ap); 00143 ACE_Auto_Basic_Array_Ptr<X> &operator= (ACE_Auto_Basic_Array_Ptr<X> & rhs); 00144 ~ACE_Auto_Basic_Array_Ptr (void); 00145 00146 // = Accessor methods. 00147 X & operator* () const; 00148 X & operator[] (int i) const; 00149 X * get (void) const; 00150 X * release (void); 00151 void reset (X * p = 0); 00152 00153 /// Dump the state of an object. 00154 void dump (void) const; 00155 00156 /// Declare the dynamic allocation hooks. 00157 ACE_ALLOC_HOOK_DECLARE; 00158 00159 protected: 00160 X * p_; 00161 }; 00162 00163 /** 00164 * @class ACE_Auto_Array_Ptr 00165 * 00166 * @brief Implements an extension to the draft C++ standard auto_ptr 00167 * abstraction. 00168 */ 00169 template<typename X> 00170 class ACE_Auto_Array_Ptr : public ACE_Auto_Basic_Array_Ptr<X> 00171 { 00172 public: 00173 typedef X element_type; 00174 00175 // = Initialization and termination methods. 00176 explicit ACE_Auto_Array_Ptr (X *p = 0) 00177 : ACE_Auto_Basic_Array_Ptr<X> (p) {} 00178 00179 X *operator-> () const; 00180 }; 00181 00182 00183 /** 00184 * @brief Reset given @c auto_ptr element to new element. 00185 * 00186 * Some platforms have an older version of auto_ptr support, which 00187 * lacks reset, and cannot be disabled easily. Portability to these 00188 * platforms requires use of this function template. This function 00189 * template also works for the @c ACE_Auto_{Basic_}Array_Ptr class 00190 * template, as well. 00191 */ 00192 template<typename AUTO_PTR_TYPE, typename PTR_TYPE> 00193 inline void 00194 ACE_auto_ptr_reset (AUTO_PTR_TYPE & ap, 00195 PTR_TYPE * p) 00196 { 00197 #if defined (ACE_AUTO_PTR_LACKS_RESET) 00198 // Allow compiler to adjust pointer to potential base class pointer 00199 // of element type found in auto_ptr. 00200 typename AUTO_PTR_TYPE::element_type * const tp = p; 00201 if (tp != ap.get ()) 00202 { 00203 ap = AUTO_PTR_TYPE (tp); 00204 } 00205 #else 00206 ap.reset (p); 00207 #endif /* ACE_AUTO_PTR_LACKS_RESET */ 00208 } 00209 00210 ACE_END_VERSIONED_NAMESPACE_DECL 00211 00212 // Some platforms have an older version of auto_ptr 00213 // support, which lacks reset, and cannot be disabled 00214 // easily. Portability to these platforms requires 00215 // use of the following ACE_AUTO_PTR_RESET macro. 00216 // 00217 // The TYPE macro parameter is no longer necessary but we leave it 00218 // around for backward compatibility. This is also the reason why the 00219 // ACE_auto_ptr_reset function template is not called 00220 // ACE_AUTO_PTR_RESET. 00221 # define ACE_AUTO_PTR_RESET(AUTOPTR,NEWPTR,TYPE) \ 00222 ACE_auto_ptr_reset (AUTOPTR, NEWPTR); 00223 00224 #if defined (__ACE_INLINE__) 00225 #include "ace/Auto_Ptr.inl" 00226 #endif /* __ACE_INLINE__ */ 00227 00228 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00229 #include "ace/Auto_Ptr.cpp" 00230 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00231 00232 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00233 #pragma implementation ("Auto_Ptr.cpp") 00234 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00235 00236 #if defined (_MSC_VER) 00237 // Restore the warning state to what it was before entry. 00238 # pragma warning(pop) 00239 #endif /* _MSC_VER */ 00240 00241 #include /**/ "ace/post.h" 00242 #endif /* ACE_AUTO_PTR_H */