Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygen_auto_ptr.h
Go to the documentation of this file.
00001 /* 00002 * Copyright (c) 1997-1999 00003 * Silicon Graphics Computer Systems, Inc. 00004 * 00005 * Copyright (c) 1999 00006 * Boris Fomitchev 00007 * 00008 * This material is provided "as is", with absolutely no warranty expressed 00009 * or implied. Any use is at your own risk. 00010 * 00011 * Permission to use or copy this software for any purpose is hereby granted 00012 * without fee, provided the above notices are retained on all copies. 00013 * Permission to modify the code and to distribute modified code is granted, 00014 * provided the above notices are retained, and a notice that the code was 00015 * modified is included with the above copyright notice. 00016 * 00017 */ 00018 00019 #ifndef _STLP_AUTO_PTR_H 00020 #define _STLP_AUTO_PTR_H 00021 00022 _STLP_BEGIN_NAMESPACE 00023 // implementation primitive 00024 class __ptr_base { 00025 public: 00026 void* _M_p; 00027 void __set(const volatile void* p) { _M_p = __CONST_CAST(void*,p); } 00028 void __set(void* p) { _M_p = p; } 00029 }; 00030 00031 template <class _Tp> 00032 class auto_ptr_ref { 00033 public: 00034 __ptr_base& _M_r; 00035 _Tp* const _M_p; 00036 00037 auto_ptr_ref(__ptr_base& __r, _Tp* __p) : _M_r(__r), _M_p(__p) { } 00038 00039 _Tp* release() const { _M_r.__set(__STATIC_CAST(void*, 0)); return _M_p; } 00040 00041 private: 00042 //explicitely defined as private to avoid warnings: 00043 typedef auto_ptr_ref<_Tp> _Self; 00044 _Self& operator = (_Self const&); 00045 }; 00046 00047 template<class _Tp> 00048 class auto_ptr : public __ptr_base { 00049 public: 00050 typedef _Tp element_type; 00051 typedef auto_ptr<_Tp> _Self; 00052 00053 _Tp* release() _STLP_NOTHROW { 00054 _Tp* __px = this->get(); 00055 this->_M_p = 0; 00056 return __px; 00057 } 00058 00059 void reset(_Tp* __px = 0) _STLP_NOTHROW { 00060 _Tp* __pt = this->get(); 00061 if (__px != __pt) 00062 delete __pt; 00063 this->__set(__px); 00064 } 00065 00066 _Tp* get() const _STLP_NOTHROW 00067 #if !defined (__GNUC__) || (__GNUC__ > 2) 00068 { return __STATIC_CAST(_Tp*, _M_p); } 00069 #else 00070 { return __REINTERPRET_CAST(_Tp*, _M_p); } 00071 #endif 00072 00073 #if !defined (_STLP_NO_ARROW_OPERATOR) 00074 _Tp* operator->() const _STLP_NOTHROW { 00075 _STLP_VERBOSE_ASSERT(get() != 0, _StlMsg_AUTO_PTR_NULL) 00076 return get(); 00077 } 00078 #endif 00079 _Tp& operator*() const _STLP_NOTHROW { 00080 _STLP_VERBOSE_ASSERT(get() != 0, _StlMsg_AUTO_PTR_NULL) 00081 return *get(); 00082 } 00083 00084 explicit auto_ptr(_Tp* __px = 0) _STLP_NOTHROW { this->__set(__px); } 00085 00086 #if defined (_STLP_MEMBER_TEMPLATES) 00087 # if !defined (_STLP_NO_TEMPLATE_CONVERSIONS) 00088 template<class _Tp1> auto_ptr(auto_ptr<_Tp1>& __r) _STLP_NOTHROW { 00089 _Tp* __conversionCheck = __r.release(); 00090 this->__set(__conversionCheck); 00091 } 00092 # endif 00093 template<class _Tp1> auto_ptr<_Tp>& operator=(auto_ptr<_Tp1>& __r) _STLP_NOTHROW { 00094 _Tp* __conversionCheck = __r.release(); 00095 reset(__conversionCheck); 00096 return *this; 00097 } 00098 #endif 00099 00100 auto_ptr(_Self& __r) _STLP_NOTHROW { this->__set(__r.release()); } 00101 00102 _Self& operator=(_Self& __r) _STLP_NOTHROW { 00103 reset(__r.release()); 00104 return *this; 00105 } 00106 00107 ~auto_ptr() _STLP_NOTHROW { /* boris : reset(0) might be better */ delete this->get(); } 00108 00109 auto_ptr(auto_ptr_ref<_Tp> __r) _STLP_NOTHROW 00110 { this->__set(__r.release()); } 00111 00112 _Self& operator=(auto_ptr_ref<_Tp> __r) _STLP_NOTHROW { 00113 reset(__r.release()); 00114 return *this; 00115 } 00116 00117 #if defined(_STLP_MEMBER_TEMPLATES) && !defined(_STLP_NO_TEMPLATE_CONVERSIONS) 00118 template<class _Tp1> operator auto_ptr_ref<_Tp1>() _STLP_NOTHROW 00119 { return auto_ptr_ref<_Tp1>(*this, this->get()); } 00120 template<class _Tp1> operator auto_ptr<_Tp1>() _STLP_NOTHROW 00121 { return auto_ptr<_Tp1>(release()); } 00122 #else 00123 operator auto_ptr_ref<_Tp>() _STLP_NOTHROW 00124 { return auto_ptr_ref<_Tp>(*this, this->get()); } 00125 #endif 00126 }; 00127 _STLP_END_NAMESPACE 00128 00129 #endif /* _STLP_AUTO_PTR_H */ 00130 00131 // Local Variables: 00132 // mode:C++ 00133 // End: Generated on Sat May 26 2012 04:27:29 for ReactOS by
1.7.6.1
|