2 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
3 * Copyright (c) 1997-1999
4 * Silicon Graphics Computer Systems, Inc.
9 * This material is provided "as is", with absolutely no warranty expressed
10 * or implied. Any use is at your own risk.
12 * Permission to use or copy this software for any purpose is hereby granted
13 * without fee, provided the above notices are retained on all copies.
14 * Permission to modify the code and to distribute modified code is granted,
15 * provided the above notices are retained, and a notice that the code was
16 * modified is included with the above copyright notice.
20 #ifndef _STLP_AUTO_PTR_H
21 # define _STLP_AUTO_PTR_H
24 // implementation primitive
28 void __set(const void* __p) { _M_p = __CONST_CAST(void*,__p); }
29 void __set(void* __p) { _M_p = __p; }
32 template <class _Tp> class auto_ptr_ref {
37 auto_ptr_ref(__ptr_base& __r, _Tp* __p) : _M_r(__r), _M_p(__p) { }
39 _Tp* release() const { _M_r.__set((void*)0); return _M_p; }
43 template<class _Tp> class auto_ptr : public __ptr_base {
45 typedef _Tp element_type;
46 typedef auto_ptr<_Tp> _Self;
49 _Tp* __px = this->get();
54 void reset(_Tp* __px=0) {
55 _Tp* __pt = this->get();
61 _Tp* get() const { return __REINTERPRET_CAST(_Tp*,__CONST_CAST(void*,_M_p)); }
63 # if !defined (_STLP_NO_ARROW_OPERATOR)
64 _Tp* operator->() const {
65 _STLP_VERBOSE_ASSERT(get()!=0, _StlMsg_AUTO_PTR_NULL)
69 _Tp& operator*() const {
70 _STLP_VERBOSE_ASSERT(get()!=0, _StlMsg_AUTO_PTR_NULL)
76 # ifdef _STLP_USE_TRAP_LEAVE
77 CleanupStack::PushL(TCleanupItem(Close, (void*)this));
81 explicit auto_ptr(_Tp* __px) {
83 # ifdef _STLP_USE_TRAP_LEAVE
84 CleanupStack::PushL(TCleanupItem(Close, (void*)this));
88 #if defined (_STLP_MEMBER_TEMPLATES)
89 # if !defined (_STLP_NO_TEMPLATE_CONVERSIONS)
90 template<class _Tp1> auto_ptr(auto_ptr<_Tp1>& __r) {
91 _Tp* __conversionCheck = __r.release();
92 this->__set(__conversionCheck);
93 # ifdef _STLP_USE_TRAP_LEAVE
94 CleanupStack::PushL(TCleanupItem(Close, (void*)this));
98 template<class _Tp1> auto_ptr<_Tp>& operator=(auto_ptr<_Tp1>& __r) {
99 _Tp* __conversionCheck = __r.release();
100 reset(__conversionCheck);
103 #endif /* _STLP_MEMBER_TEMPLATES */
106 { this->__set(__r.release());
107 # ifdef _STLP_USE_TRAP_LEAVE
108 CleanupStack::PushL(TCleanupItem(Close, (void*)this));
112 _Self& operator=(_Self& __r) {
113 reset(__r.release());
117 ~auto_ptr() { _STLP_POP_ITEM reset(0); }
119 auto_ptr(auto_ptr_ref<_Tp> __r) {
120 this->__set(__r.release());
121 # ifdef _STLP_USE_TRAP_LEAVE
122 CleanupStack::PushL(TCleanupItem(Close, (void*)this));
126 _Self& operator=(auto_ptr_ref<_Tp> __r) {
127 reset(__r.release());
132 _Self& operator=(_Tp* __px) {
139 # if defined(_STLP_MEMBER_TEMPLATES) && !defined(_STLP_NO_TEMPLATE_CONVERSIONS)
140 template<class _Tp1> operator auto_ptr_ref<_Tp1>() {
141 return auto_ptr_ref<_Tp1>(*this, this->get());
143 template<class _Tp1> operator auto_ptr<_Tp1>() {
144 return auto_ptr<_Tp1>(release());
147 operator auto_ptr_ref<_Tp>()
148 { return auto_ptr_ref<_Tp>(*this, this->get()); }
151 # ifdef _STLP_USE_TRAP_LEAVE
152 static void Close(void* aPtr);
157 # ifdef _STLP_USE_TRAP_LEAVE
160 auto_ptr<_Tp>::Close(void* aPtr)
162 auto_ptr<_Tp>* self = (auto_ptr<_Tp>*)aPtr;
170 #endif /* _STLP_AUTO_PTR_H */