ReactOS  0.4.14-dev-358-gbef841c
_auto_ptr.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1997-1999
3  * Silicon Graphics Computer Systems, Inc.
4  *
5  * Copyright (c) 1999
6  * Boris Fomitchev
7  *
8  * This material is provided "as is", with absolutely no warranty expressed
9  * or implied. Any use is at your own risk.
10  *
11  * Permission to use or copy this software for any purpose is hereby granted
12  * without fee, provided the above notices are retained on all copies.
13  * Permission to modify the code and to distribute modified code is granted,
14  * provided the above notices are retained, and a notice that the code was
15  * modified is included with the above copyright notice.
16  *
17  */
18 
19 #ifndef _STLP_AUTO_PTR_H
20 #define _STLP_AUTO_PTR_H
21 
23 // implementation primitive
24 class __ptr_base {
25 public:
26  void* _M_p;
27  void __set(const volatile void* p) { _M_p = __CONST_CAST(void*,p); }
28  void __set(void* p) { _M_p = p; }
29 };
30 
31 template <class _Tp>
32 class auto_ptr_ref {
33 public:
35  _Tp* const _M_p;
36 
37  auto_ptr_ref(__ptr_base& __r, _Tp* __p) : _M_r(__r), _M_p(__p) { }
38 
39  _Tp* release() const { _M_r.__set(__STATIC_CAST(void*, 0)); return _M_p; }
40 
41 private:
42  //explicitely defined as private to avoid warnings:
44  _Self& operator = (_Self const&);
45 };
46 
47 template<class _Tp>
48 class auto_ptr : public __ptr_base {
49 public:
50  typedef _Tp element_type;
52 
54  _Tp* __px = this->get();
55  this->_M_p = 0;
56  return __px;
57  }
58 
59  void reset(_Tp* __px = 0) _STLP_NOTHROW {
60  _Tp* __pt = this->get();
61  if (__px != __pt)
62  delete __pt;
63  this->__set(__px);
64  }
65 
67 #if !defined (__GNUC__) || (__GNUC__ > 2)
68  { return __STATIC_CAST(_Tp*, _M_p); }
69 #else
70  { return __REINTERPRET_CAST(_Tp*, _M_p); }
71 #endif
72 
73 #if !defined (_STLP_NO_ARROW_OPERATOR)
75  _STLP_VERBOSE_ASSERT(get() != 0, _StlMsg_AUTO_PTR_NULL)
76  return get();
77  }
78 #endif
80  _STLP_VERBOSE_ASSERT(get() != 0, _StlMsg_AUTO_PTR_NULL)
81  return *get();
82  }
83 
84  explicit auto_ptr(_Tp* __px = 0) _STLP_NOTHROW { this->__set(__px); }
85 
86 #if defined (_STLP_MEMBER_TEMPLATES)
87 # if !defined (_STLP_NO_TEMPLATE_CONVERSIONS)
88  template<class _Tp1> auto_ptr(auto_ptr<_Tp1>& __r) _STLP_NOTHROW {
89  _Tp* __conversionCheck = __r.release();
90  this->__set(__conversionCheck);
91  }
92 # endif
93  template<class _Tp1> auto_ptr<_Tp>& operator=(auto_ptr<_Tp1>& __r) _STLP_NOTHROW {
94  _Tp* __conversionCheck = __r.release();
95  reset(__conversionCheck);
96  return *this;
97  }
98 #endif
99 
100  auto_ptr(_Self& __r) _STLP_NOTHROW { this->__set(__r.release()); }
101 
103  reset(__r.release());
104  return *this;
105  }
106 
107  ~auto_ptr() _STLP_NOTHROW { /* boris : reset(0) might be better */ delete this->get(); }
108 
110  { this->__set(__r.release()); }
111 
113  reset(__r.release());
114  return *this;
115  }
116 
117 #if defined(_STLP_MEMBER_TEMPLATES) && !defined(_STLP_NO_TEMPLATE_CONVERSIONS)
118  template<class _Tp1> operator auto_ptr_ref<_Tp1>() _STLP_NOTHROW
119  { return auto_ptr_ref<_Tp1>(*this, this->get()); }
120  template<class _Tp1> operator auto_ptr<_Tp1>() _STLP_NOTHROW
121  { return auto_ptr<_Tp1>(release()); }
122 #else
124  { return auto_ptr_ref<_Tp>(*this, this->get()); }
125 #endif
126 };
128 
129 #endif /* _STLP_AUTO_PTR_H */
130 
131 // Local Variables:
132 // mode:C++
133 // End:
#define __STATIC_CAST(__x, __y)
Definition: features.h:585
auto_ptr(_Self &__r) _STLP_NOTHROW
Definition: _auto_ptr.h:100
auto_ptr_ref< _Tp > _Self
Definition: _auto_ptr.h:43
auto_ptr(_Tp *__px=0) _STLP_NOTHROW
Definition: _auto_ptr.h:84
_Self & operator=(_Self const &)
void __set(void *p)
Definition: _auto_ptr.h:28
_Tp *const _M_p
Definition: _auto_ptr.h:35
void * _M_p
Definition: _auto_ptr.h:26
void reset(_Tp *__px=0) _STLP_NOTHROW
Definition: _auto_ptr.h:59
_Tp & operator *() const _STLP_NOTHROW
Definition: _auto_ptr.h:79
_Tp * release() _STLP_NOTHROW
Definition: _auto_ptr.h:53
auto_ptr_ref(__ptr_base &__r, _Tp *__p)
Definition: _auto_ptr.h:37
_Tp * release() const
Definition: _auto_ptr.h:39
_Tp * get() const _STLP_NOTHROW
Definition: _auto_ptr.h:66
_Self & operator=(_Self &__r) _STLP_NOTHROW
Definition: _auto_ptr.h:102
_Tp element_type
Definition: _auto_ptr.h:50
_Self & operator=(auto_ptr_ref< _Tp > __r) _STLP_NOTHROW
Definition: _auto_ptr.h:112
_Tp * operator->() const _STLP_NOTHROW
Definition: _auto_ptr.h:74
auto_ptr(auto_ptr_ref< _Tp > __r) _STLP_NOTHROW
Definition: _auto_ptr.h:109
~auto_ptr() _STLP_NOTHROW
Definition: _auto_ptr.h:107
#define __REINTERPRET_CAST(__x, __y)
Definition: features.h:586
__ptr_base & _M_r
Definition: _auto_ptr.h:34
auto_ptr< _Tp > _Self
Definition: _auto_ptr.h:51
#define __CONST_CAST(__x, __y)
Definition: features.h:584
void __set(const volatile void *p)
Definition: _auto_ptr.h:27
#define _STLP_END_NAMESPACE
Definition: features.h:503
#define const
Definition: zconf.h:230
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
#define _STLP_NOTHROW
Definition: _intel.h:35
GLfloat GLfloat p
Definition: glext.h:8902
#define _STLP_VERBOSE_ASSERT(expr, diagnostic)
Definition: _debug.h:439