00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00026 #ifndef OW32_auto_array_ptr_h
00027 #define OW32_auto_array_ptr_h
00028
00029 namespace OW32
00030 {
00031
00032 template<class _Tp1> struct auto_array_ptr_ref {
00033 _Tp1* _M_ptr;
00034 auto_array_ptr_ref(_Tp1* __p) : _M_ptr(__p) {}
00035 };
00036
00040 template <class _Tp> class auto_array_ptr {
00041 private:
00042 _Tp* _M_ptr;
00043
00044 public:
00045 typedef _Tp element_type;
00046
00047 explicit auto_array_ptr(_Tp* __p = 0) throw() : _M_ptr(__p) {}
00048 auto_array_ptr(auto_array_ptr& __a) throw() : _M_ptr(__a.release()) {}
00049
00050 #if 0 // member templates not supported
00051 template <class _Tp1> auto_array_ptr(auto_array_ptr<_Tp1>& __a) throw()
00052 : _M_ptr(__a.release()) {}
00053 #endif
00054
00055 auto_array_ptr& operator=(auto_array_ptr& __a) throw() {
00056 if (&__a != this) {
00057 delete [] _M_ptr;
00058 _M_ptr = __a.release();
00059 }
00060 return *this;
00061 }
00062
00063 #if 0 // member templates not supported
00064 template <class _Tp1>
00065 auto_array_ptr& operator=(auto_array_ptr<_Tp1>& __a) throw() {
00066 if (__a.get() != this->get()) {
00067 delete [] _M_ptr;
00068 _M_ptr = __a.release();
00069 }
00070 return *this;
00071 }
00072 #endif
00073
00074
00075
00076
00077
00078 ~auto_array_ptr() { delete [] _M_ptr; }
00079
00080 _Tp& operator*() const throw() {
00081 return *_M_ptr;
00082 }
00083 _Tp& operator[](size_t index) throw() {
00084 return _M_ptr[index];
00085 }
00086 const _Tp& operator[](size_t index) const throw() {
00087 return _M_ptr[index];
00088 }
00089
00090
00091
00092 _Tp* get() const throw() {
00093 return _M_ptr;
00094 }
00095 _Tp* release() throw() {
00096 _Tp* __tmp = _M_ptr;
00097 _M_ptr = 0;
00098 return __tmp;
00099 }
00100 void reset(_Tp* __p = 0) throw() {
00101 if (__p != _M_ptr) {
00102 delete [] _M_ptr;
00103 _M_ptr = __p;
00104 }
00105 }
00106
00107
00108
00109
00110
00111
00112 #if 0 // member templates not supported
00113 public:
00114 auto_array_ptr(auto_array_ptr_ref<_Tp> __ref) throw()
00115 : _M_ptr(__ref._M_ptr) {}
00116
00117 auto_array_ptr& operator=(auto_array_ptr_ref<_Tp> __ref) throw() {
00118 if (__ref._M_ptr != this->get()) {
00119 delete [] _M_ptr;
00120 _M_ptr = __ref._M_ptr;
00121 }
00122 return *this;
00123 }
00124
00125 template <class _Tp1> operator auto_array_ptr_ref<_Tp1>() throw()
00126 { return auto_array_ptr_ref<_Tp1>(this->release()); }
00127 template <class _Tp1> operator auto_array_ptr<_Tp1>() throw()
00128 { return auto_array_ptr<_Tp1>(this->release()); }
00129 #endif
00130 };
00131
00132 }
00133
00134 #endif // OW32_auto_array_ptr_h