epoc32/include/stdapis/stlport/stl/_auto_ptr.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
     1.1 --- a/epoc32/include/stdapis/stlport/stl/_auto_ptr.h	Tue Nov 24 13:55:44 2009 +0000
     1.2 +++ b/epoc32/include/stdapis/stlport/stl/_auto_ptr.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -1,1 +1,175 @@
     1.4 -_auto_ptr.h
     1.5 +/*
     1.6 + * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
     1.7 + * Copyright (c) 1997-1999
     1.8 + * Silicon Graphics Computer Systems, Inc.
     1.9 + *
    1.10 + * Copyright (c) 1999
    1.11 + * Boris Fomitchev
    1.12 + *
    1.13 + * This material is provided "as is", with absolutely no warranty expressed
    1.14 + * or implied. Any use is at your own risk.
    1.15 + *
    1.16 + * Permission to use or copy this software for any purpose is hereby granted
    1.17 + * without fee, provided the above notices are retained on all copies.
    1.18 + * Permission to modify the code and to distribute modified code is granted,
    1.19 + * provided the above notices are retained, and a notice that the code was
    1.20 + * modified is included with the above copyright notice.
    1.21 + *
    1.22 + */
    1.23 +
    1.24 +#ifndef _STLP_AUTO_PTR_H
    1.25 +# define _STLP_AUTO_PTR_H
    1.26 +
    1.27 +_STLP_BEGIN_NAMESPACE
    1.28 +// implementation primitive
    1.29 +class __ptr_base {
    1.30 +public:
    1.31 +  void* _M_p;
    1.32 +  void  __set(const void* __p) { _M_p = __CONST_CAST(void*,__p); }
    1.33 +  void  __set(void* __p) { _M_p = __p; }
    1.34 +};
    1.35 +
    1.36 +template <class _Tp> class auto_ptr_ref {
    1.37 +public:
    1.38 +  __ptr_base& _M_r;
    1.39 +  _Tp* const _M_p;
    1.40 +
    1.41 +  auto_ptr_ref(__ptr_base& __r, _Tp* __p) : _M_r(__r), _M_p(__p) {  }
    1.42 +
    1.43 +  _Tp* release() const { _M_r.__set((void*)0); return _M_p; }
    1.44 +
    1.45 +};
    1.46 +
    1.47 +template<class _Tp> class auto_ptr :  public __ptr_base {
    1.48 +public:
    1.49 +  typedef _Tp element_type;
    1.50 +  typedef auto_ptr<_Tp>           _Self;
    1.51 +
    1.52 +  _Tp* release() {
    1.53 +    _Tp* __px = this->get();
    1.54 +    this->_M_p = 0;
    1.55 +    return __px;
    1.56 +  }
    1.57 +
    1.58 +  void reset(_Tp* __px=0) {
    1.59 +    _Tp* __pt = this->get();
    1.60 +    if (__px != __pt)
    1.61 +      delete __pt;
    1.62 +    this->__set(__px);
    1.63 +  }
    1.64 +
    1.65 +  _Tp* get() const { return __REINTERPRET_CAST(_Tp*,__CONST_CAST(void*,_M_p)); }
    1.66 +
    1.67 +# if !defined (_STLP_NO_ARROW_OPERATOR)
    1.68 +  _Tp* operator->() const {
    1.69 +    _STLP_VERBOSE_ASSERT(get()!=0, _StlMsg_AUTO_PTR_NULL)
    1.70 +    return get();
    1.71 +  }
    1.72 +# endif
    1.73 +  _Tp& operator*() const  {
    1.74 +    _STLP_VERBOSE_ASSERT(get()!=0, _StlMsg_AUTO_PTR_NULL)
    1.75 +    return *get();
    1.76 +  }
    1.77 +
    1.78 +  auto_ptr() {
    1.79 +    this->_M_p = 0;
    1.80 +# ifdef _STLP_USE_TRAP_LEAVE
    1.81 +    CleanupStack::PushL(TCleanupItem(Close, (void*)this));
    1.82 +# endif
    1.83 +  }
    1.84 +
    1.85 +  explicit auto_ptr(_Tp* __px) {
    1.86 +    this->__set(__px);
    1.87 +# ifdef _STLP_USE_TRAP_LEAVE
    1.88 +    CleanupStack::PushL(TCleanupItem(Close, (void*)this));
    1.89 +# endif
    1.90 +  }
    1.91 +
    1.92 +#if defined (_STLP_MEMBER_TEMPLATES)
    1.93 +# if !defined (_STLP_NO_TEMPLATE_CONVERSIONS)
    1.94 +  template<class _Tp1> auto_ptr(auto_ptr<_Tp1>& __r) {
    1.95 +    _Tp* __conversionCheck = __r.release();
    1.96 +    this->__set(__conversionCheck);
    1.97 +# ifdef _STLP_USE_TRAP_LEAVE
    1.98 +    CleanupStack::PushL(TCleanupItem(Close, (void*)this));
    1.99 +# endif
   1.100 +  }
   1.101 +# endif
   1.102 +  template<class _Tp1> auto_ptr<_Tp>& operator=(auto_ptr<_Tp1>& __r) {
   1.103 +    _Tp* __conversionCheck = __r.release();
   1.104 +    reset(__conversionCheck);
   1.105 +    return *this;
   1.106 +  }
   1.107 +#endif /* _STLP_MEMBER_TEMPLATES */
   1.108 +
   1.109 +  auto_ptr(_Self& __r)
   1.110 +  { this->__set(__r.release());
   1.111 +# ifdef _STLP_USE_TRAP_LEAVE
   1.112 +    CleanupStack::PushL(TCleanupItem(Close, (void*)this));
   1.113 +# endif
   1.114 +  }
   1.115 +
   1.116 +  _Self& operator=(_Self& __r)  {
   1.117 +    reset(__r.release());
   1.118 +    return *this;
   1.119 +  }
   1.120 +
   1.121 +  ~auto_ptr() { _STLP_POP_ITEM reset(0); }
   1.122 +
   1.123 +  auto_ptr(auto_ptr_ref<_Tp> __r) {
   1.124 +    this->__set(__r.release());
   1.125 +# ifdef _STLP_USE_TRAP_LEAVE
   1.126 +    CleanupStack::PushL(TCleanupItem(Close, (void*)this));
   1.127 +# endif
   1.128 +  }
   1.129 +
   1.130 +  _Self& operator=(auto_ptr_ref<_Tp> __r) {
   1.131 +    reset(__r.release());
   1.132 +    return *this;
   1.133 +  }
   1.134 +
   1.135 +
   1.136 +  _Self& operator=(_Tp* __px) {
   1.137 +  	reset(__px);
   1.138 +    return *this;
   1.139 +  }
   1.140 +
   1.141 +
   1.142 +
   1.143 +# if defined(_STLP_MEMBER_TEMPLATES) && !defined(_STLP_NO_TEMPLATE_CONVERSIONS)
   1.144 +  template<class _Tp1> operator auto_ptr_ref<_Tp1>() {
   1.145 +    return auto_ptr_ref<_Tp1>(*this, this->get());
   1.146 +  }
   1.147 +  template<class _Tp1> operator auto_ptr<_Tp1>() {
   1.148 +    return auto_ptr<_Tp1>(release());
   1.149 +  }
   1.150 +# else
   1.151 +  operator auto_ptr_ref<_Tp>()
   1.152 +  { return auto_ptr_ref<_Tp>(*this, this->get()); }
   1.153 +# endif
   1.154 +
   1.155 +# ifdef _STLP_USE_TRAP_LEAVE
   1.156 +  static void Close(void* aPtr);
   1.157 +# endif
   1.158 +
   1.159 +};
   1.160 +
   1.161 +# ifdef _STLP_USE_TRAP_LEAVE
   1.162 +template <class _Tp>
   1.163 +void
   1.164 +auto_ptr<_Tp>::Close(void* aPtr)
   1.165 +{
   1.166 +  auto_ptr<_Tp>* self = (auto_ptr<_Tp>*)aPtr;
   1.167 +  self->reset(0);
   1.168 +}
   1.169 +# endif
   1.170 +
   1.171 +
   1.172 +_STLP_END_NAMESPACE
   1.173 +
   1.174 +#endif /* _STLP_AUTO_PTR_H */
   1.175 +
   1.176 +// Local Variables:
   1.177 +// mode:C++
   1.178 +// End:
   1.179 +