1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/_auto_ptr.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,129 @@
1.4 +/*
1.5 + * Copyright (c) 1997-1999
1.6 + * Silicon Graphics Computer Systems, Inc.
1.7 + *
1.8 + * Copyright (c) 1999
1.9 + * Boris Fomitchev
1.10 + *
1.11 + * This material is provided "as is", with absolutely no warranty expressed
1.12 + * or implied. Any use is at your own risk.
1.13 + *
1.14 + * Permission to use or copy this software for any purpose is hereby granted
1.15 + * without fee, provided the above notices are retained on all copies.
1.16 + * Permission to modify the code and to distribute modified code is granted,
1.17 + * provided the above notices are retained, and a notice that the code was
1.18 + * modified is included with the above copyright notice.
1.19 + *
1.20 + */
1.21 +
1.22 +#ifndef _STLP_AUTO_PTR_H
1.23 +# define _STLP_AUTO_PTR_H
1.24 +
1.25 +_STLP_BEGIN_NAMESPACE
1.26 +// implementation primitive
1.27 +class __ptr_base {
1.28 +public:
1.29 + void* _M_p;
1.30 + void __set(const void* p) { _M_p = __CONST_CAST(void*,p); }
1.31 + void __set(void* p) { _M_p = p; }
1.32 +};
1.33 +
1.34 +template <class _Tp>
1.35 +class auto_ptr_ref {
1.36 +public:
1.37 + __ptr_base& _M_r;
1.38 + _Tp* const _M_p;
1.39 +
1.40 + auto_ptr_ref(__ptr_base& __r, _Tp* __p) : _M_r(__r), _M_p(__p) { }
1.41 +
1.42 + _Tp* release() const { _M_r.__set((void*)0); return _M_p; }
1.43 +
1.44 +private:
1.45 + //explicitely defined as private to avoid warnings:
1.46 + typedef auto_ptr_ref<_Tp> _Self;
1.47 + _Self& operator = (_Self const&);
1.48 +};
1.49 +
1.50 +template<class _Tp>
1.51 +class auto_ptr : public __ptr_base {
1.52 +public:
1.53 + typedef _Tp element_type;
1.54 + typedef auto_ptr<_Tp> _Self;
1.55 +
1.56 + _Tp* release() _STLP_NOTHROW {
1.57 + _Tp* __px = this->get();
1.58 + this->_M_p = 0;
1.59 + return __px;
1.60 + }
1.61 +
1.62 + void reset(_Tp* __px = 0) _STLP_NOTHROW {
1.63 + _Tp* __pt = this->get();
1.64 + if (__px != __pt)
1.65 + delete __pt;
1.66 + this->__set(__px);
1.67 + }
1.68 +
1.69 + _Tp* get() const _STLP_NOTHROW
1.70 + { return __REINTERPRET_CAST(_Tp*,__CONST_CAST(void*,_M_p)); }
1.71 +
1.72 +#if !defined (_STLP_NO_ARROW_OPERATOR)
1.73 + _Tp* operator->() const _STLP_NOTHROW {
1.74 + _STLP_VERBOSE_ASSERT(get()!=0, _StlMsg_AUTO_PTR_NULL)
1.75 + return get();
1.76 + }
1.77 +#endif
1.78 + _Tp& operator*() const _STLP_NOTHROW {
1.79 + _STLP_VERBOSE_ASSERT(get()!= 0, _StlMsg_AUTO_PTR_NULL)
1.80 + return *get();
1.81 + }
1.82 +
1.83 + explicit auto_ptr(_Tp* __px = 0) _STLP_NOTHROW { this->__set(__px); }
1.84 +
1.85 +#if defined (_STLP_MEMBER_TEMPLATES)
1.86 +# if !defined (_STLP_NO_TEMPLATE_CONVERSIONS)
1.87 + template<class _Tp1> auto_ptr(auto_ptr<_Tp1>& __r) _STLP_NOTHROW {
1.88 + _Tp* __conversionCheck = __r.release();
1.89 + this->__set(__conversionCheck);
1.90 + }
1.91 +# endif
1.92 + template<class _Tp1> auto_ptr<_Tp>& operator=(auto_ptr<_Tp1>& __r) _STLP_NOTHROW {
1.93 + _Tp* __conversionCheck = __r.release();
1.94 + reset(__conversionCheck);
1.95 + return *this;
1.96 + }
1.97 +#endif
1.98 +
1.99 + auto_ptr(_Self& __r) _STLP_NOTHROW { this->__set(__r.release()); }
1.100 +
1.101 + _Self& operator=(_Self& __r) _STLP_NOTHROW {
1.102 + reset(__r.release());
1.103 + return *this;
1.104 + }
1.105 +
1.106 + ~auto_ptr() _STLP_NOTHROW { /* boris : reset(0) might be better */ delete this->get(); }
1.107 +
1.108 + auto_ptr(auto_ptr_ref<_Tp> __r) _STLP_NOTHROW
1.109 + { this->__set(__r.release()); }
1.110 +
1.111 + _Self& operator=(auto_ptr_ref<_Tp> __r) _STLP_NOTHROW {
1.112 + reset(__r.release());
1.113 + return *this;
1.114 + }
1.115 +
1.116 +#if defined(_STLP_MEMBER_TEMPLATES) && !defined(_STLP_NO_TEMPLATE_CONVERSIONS)
1.117 + template<class _Tp1> operator auto_ptr_ref<_Tp1>() _STLP_NOTHROW
1.118 + { return auto_ptr_ref<_Tp1>(*this, this->get()); }
1.119 + template<class _Tp1> operator auto_ptr<_Tp1>() _STLP_NOTHROW
1.120 + { return auto_ptr<_Tp1>(release()); }
1.121 +#else
1.122 + operator auto_ptr_ref<_Tp>() _STLP_NOTHROW
1.123 + { return auto_ptr_ref<_Tp>(*this, this->get()); }
1.124 +#endif
1.125 +};
1.126 +_STLP_END_NAMESPACE
1.127 +
1.128 +#endif /* _STLP_AUTO_PTR_H */
1.129 +
1.130 +// Local Variables:
1.131 +// mode:C++
1.132 +// End: