Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Auto_Ptr.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Auto_Ptr.h
00006  *
00007  *  $Id: Auto_Ptr.h,v 1.1.1.4 2003/02/21 18:36:32 chad 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 #include "ace/Trace.h"
00027 
00028 #if defined (_MSC_VER)
00029 // Suppress warning e.g. "return type for
00030 // 'ACE_Auto_Array_Pointer<type>::operator ->' is 'type *' (i.e., not a UDT
00031 // or reference to a UDT.  Will produce errors if applied using infix
00032 // notation)"
00033 #  pragma warning(push)
00034 #  pragma warning(disable: 4284)
00035 #endif /* _MSC_VER */
00036 
00037 /**
00038  * @class ACE_Auto_Basic_Ptr
00039  *
00040  * @brief Implements the draft C++ standard auto_ptr abstraction.
00041  * This class allows one to work on non-object (basic) types
00042  */
00043 template <class X>
00044 class ACE_Auto_Basic_Ptr
00045 {
00046 public:
00047   // = Initialization and termination methods
00048   ACE_EXPLICIT ACE_Auto_Basic_Ptr (X *p = 0) : p_ (p) {}
00049 
00050   ACE_Auto_Basic_Ptr (ACE_Auto_Basic_Ptr<X> &ap);
00051   ACE_Auto_Basic_Ptr<X> &operator= (ACE_Auto_Basic_Ptr<X> &rhs);
00052   ~ACE_Auto_Basic_Ptr (void);
00053 
00054   // = Accessor methods.
00055   X &operator *() const;
00056   X *get (void) const;
00057   X *release (void);
00058   void reset (X *p = 0);
00059 
00060   /// Dump the state of an object.
00061   void dump (void) const;
00062 
00063   /// Declare the dynamic allocation hooks.
00064   ACE_ALLOC_HOOK_DECLARE;
00065 
00066 protected:
00067   X *p_;
00068 };
00069 
00070 #if !defined (ACE_LACKS_AUTO_PTR) && \
00071      defined (ACE_HAS_STANDARD_CPP_LIBRARY) && \
00072             (ACE_HAS_STANDARD_CPP_LIBRARY != 0)
00073 #include <memory>
00074 #if defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB) && \
00075             (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB != 0)
00076 using std::auto_ptr;
00077 #endif /* ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB */
00078 #else /* ACE_HAS_STANDARD_CPP_LIBRARY */
00079 
00080 /**
00081  * @class auto_ptr
00082  *
00083  * @brief Implements the draft C++ standard auto_ptr abstraction.
00084  */
00085 template <class X>
00086 class auto_ptr : public ACE_Auto_Basic_Ptr <X>
00087 {
00088 public:
00089   // = Initialization and termination methods
00090   ACE_EXPLICIT auto_ptr (X *p = 0) : ACE_Auto_Basic_Ptr<X> (p) {}
00091 
00092   X *operator-> () const;
00093 };
00094 
00095 #endif /* ACE_HAS_STANDARD_CPP_LIBRARY */
00096 
00097 /**
00098  * @class ACE_Auto_Basic_Array_Ptr
00099  *
00100  * @brief Implements an extension to the draft C++ standard auto_ptr
00101  * abstraction.  This class allows one to work on non-object
00102  * (basic) types that must be treated as an array, e.g.,
00103  * deallocated via "delete [] foo".
00104  */
00105 template<class X>
00106 class ACE_Auto_Basic_Array_Ptr
00107 {
00108 public:
00109   // = Initialization and termination methods.
00110   ACE_EXPLICIT ACE_Auto_Basic_Array_Ptr (X *p = 0) : p_ (p) {}
00111 
00112   ACE_Auto_Basic_Array_Ptr (ACE_Auto_Basic_Array_Ptr<X> &ap);
00113   ACE_Auto_Basic_Array_Ptr<X> &operator= (ACE_Auto_Basic_Array_Ptr<X> &rhs);
00114   ~ACE_Auto_Basic_Array_Ptr (void);
00115 
00116   // = Accessor methods.
00117   X &operator* () const;
00118   X &operator[] (int i) const;
00119   X *get (void) const;
00120   X *release (void);
00121   void reset (X *p = 0);
00122 
00123   /// Dump the state of an object.
00124   void dump (void) const;
00125 
00126   /// Declare the dynamic allocation hooks.
00127   ACE_ALLOC_HOOK_DECLARE;
00128 
00129 protected:
00130   X *p_;
00131 };
00132 
00133 /**
00134  * @class ACE_Auto_Array_Ptr
00135  *
00136  * @brief Implements an extension to the draft C++ standard auto_ptr
00137  * abstraction.
00138  */
00139 template<class X>
00140 class ACE_Auto_Array_Ptr : public ACE_Auto_Basic_Array_Ptr<X>
00141 {
00142 public:
00143   // = Initialization and termination methods.
00144   ACE_EXPLICIT ACE_Auto_Array_Ptr (X *p = 0)
00145     : ACE_Auto_Basic_Array_Ptr<X> (p) {}
00146 
00147   X *operator-> () const;
00148 };
00149 
00150 // Some platforms have an older version of auto_ptr
00151 // support, which lacks reset, and cannot be disabled
00152 // easily.  Portability to these platforms requires
00153 // use of the following ACE_AUTO_PTR_RESET macro.
00154 # if defined (ACE_AUTO_PTR_LACKS_RESET)
00155 #   define ACE_AUTO_PTR_RESET(X,Y,Z) \
00156       do { \
00157         if (Y != X.get ()) \
00158           { \
00159             X.release (); \
00160             X = auto_ptr<Z> (Y); \
00161           } \
00162       } while (0)
00163 # else /* ! ACE_AUTO_PTR_LACKS_RESET */
00164 #   define ACE_AUTO_PTR_RESET(X,Y,Z) \
00165       do { \
00166          X.reset (Y); \
00167       } while (0)
00168 # endif /* ACE_AUTO_PTR_LACKS_RESET */
00169 
00170 #if defined (__ACE_INLINE__)
00171 #include "ace/Auto_Ptr.i"
00172 #endif /* __ACE_INLINE__ */
00173 
00174 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00175 #include "ace/Auto_Ptr.cpp"
00176 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00177 
00178 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00179 #pragma implementation ("Auto_Ptr.cpp")
00180 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00181 
00182 #if defined (_MSC_VER)
00183 // Restore the warning state to what it was before entry.
00184 #  pragma warning(pop)
00185 #endif /* _MSC_VER */
00186 
00187 #include "ace/post.h"
00188 #endif /* ACE_AUTO_PTR_H */

Generated on Mon Jun 16 11:19:11 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002