epoc32/include/tools/stlport/stl/_auto_ptr.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@4
     1
/*
williamr@4
     2
 * Copyright (c) 1997-1999
williamr@4
     3
 * Silicon Graphics Computer Systems, Inc.
williamr@4
     4
 *
williamr@4
     5
 * Copyright (c) 1999
williamr@4
     6
 * Boris Fomitchev
williamr@4
     7
 *
williamr@4
     8
 * This material is provided "as is", with absolutely no warranty expressed
williamr@4
     9
 * or implied. Any use is at your own risk.
williamr@4
    10
 *
williamr@4
    11
 * Permission to use or copy this software for any purpose is hereby granted
williamr@4
    12
 * without fee, provided the above notices are retained on all copies.
williamr@4
    13
 * Permission to modify the code and to distribute modified code is granted,
williamr@4
    14
 * provided the above notices are retained, and a notice that the code was
williamr@4
    15
 * modified is included with the above copyright notice.
williamr@4
    16
 *
williamr@4
    17
 */
williamr@4
    18
williamr@4
    19
#ifndef _STLP_AUTO_PTR_H
williamr@4
    20
# define _STLP_AUTO_PTR_H
williamr@4
    21
williamr@4
    22
_STLP_BEGIN_NAMESPACE
williamr@4
    23
// implementation primitive
williamr@4
    24
class __ptr_base {
williamr@4
    25
public:
williamr@4
    26
  void* _M_p;
williamr@4
    27
  void  __set(const void* p) { _M_p = __CONST_CAST(void*,p); }
williamr@4
    28
  void  __set(void* p) { _M_p = p; }
williamr@4
    29
};
williamr@4
    30
williamr@4
    31
template <class _Tp>
williamr@4
    32
class auto_ptr_ref {
williamr@4
    33
public:
williamr@4
    34
  __ptr_base& _M_r;
williamr@4
    35
  _Tp* const _M_p;
williamr@4
    36
williamr@4
    37
  auto_ptr_ref(__ptr_base& __r, _Tp* __p) : _M_r(__r), _M_p(__p) {  }
williamr@4
    38
williamr@4
    39
  _Tp* release() const { _M_r.__set((void*)0); return _M_p; }
williamr@4
    40
williamr@4
    41
private:
williamr@4
    42
  //explicitely defined as private to avoid warnings:
williamr@4
    43
  typedef auto_ptr_ref<_Tp> _Self;
williamr@4
    44
  _Self& operator = (_Self const&);
williamr@4
    45
};
williamr@4
    46
williamr@4
    47
template<class _Tp>
williamr@4
    48
class auto_ptr :  public __ptr_base {
williamr@4
    49
public:
williamr@4
    50
  typedef _Tp element_type;
williamr@4
    51
  typedef auto_ptr<_Tp> _Self;
williamr@4
    52
williamr@4
    53
  _Tp* release() _STLP_NOTHROW {
williamr@4
    54
    _Tp* __px = this->get();
williamr@4
    55
    this->_M_p = 0;
williamr@4
    56
    return __px;
williamr@4
    57
  }
williamr@4
    58
williamr@4
    59
  void reset(_Tp* __px = 0) _STLP_NOTHROW {
williamr@4
    60
    _Tp* __pt = this->get();
williamr@4
    61
    if (__px != __pt)
williamr@4
    62
      delete __pt;
williamr@4
    63
    this->__set(__px);
williamr@4
    64
  }
williamr@4
    65
williamr@4
    66
  _Tp* get() const _STLP_NOTHROW
williamr@4
    67
  { return __REINTERPRET_CAST(_Tp*,__CONST_CAST(void*,_M_p)); }
williamr@4
    68
williamr@4
    69
#if !defined (_STLP_NO_ARROW_OPERATOR)
williamr@4
    70
  _Tp* operator->() const _STLP_NOTHROW {
williamr@4
    71
    _STLP_VERBOSE_ASSERT(get()!=0, _StlMsg_AUTO_PTR_NULL)
williamr@4
    72
    return get();
williamr@4
    73
  }
williamr@4
    74
#endif
williamr@4
    75
  _Tp& operator*() const _STLP_NOTHROW {
williamr@4
    76
    _STLP_VERBOSE_ASSERT(get()!= 0, _StlMsg_AUTO_PTR_NULL)
williamr@4
    77
    return *get();
williamr@4
    78
  }
williamr@4
    79
williamr@4
    80
  explicit auto_ptr(_Tp* __px = 0) _STLP_NOTHROW { this->__set(__px); }
williamr@4
    81
williamr@4
    82
#if defined (_STLP_MEMBER_TEMPLATES)
williamr@4
    83
#  if !defined (_STLP_NO_TEMPLATE_CONVERSIONS)
williamr@4
    84
  template<class _Tp1> auto_ptr(auto_ptr<_Tp1>& __r) _STLP_NOTHROW {
williamr@4
    85
    _Tp* __conversionCheck = __r.release();
williamr@4
    86
    this->__set(__conversionCheck);
williamr@4
    87
  }
williamr@4
    88
#  endif
williamr@4
    89
  template<class _Tp1> auto_ptr<_Tp>& operator=(auto_ptr<_Tp1>& __r) _STLP_NOTHROW {
williamr@4
    90
    _Tp* __conversionCheck = __r.release();
williamr@4
    91
    reset(__conversionCheck);
williamr@4
    92
    return *this;
williamr@4
    93
  }
williamr@4
    94
#endif
williamr@4
    95
williamr@4
    96
  auto_ptr(_Self& __r) _STLP_NOTHROW { this->__set(__r.release()); }
williamr@4
    97
williamr@4
    98
  _Self& operator=(_Self& __r) _STLP_NOTHROW {
williamr@4
    99
    reset(__r.release());
williamr@4
   100
    return *this;
williamr@4
   101
  }
williamr@4
   102
williamr@4
   103
  ~auto_ptr() _STLP_NOTHROW { /* boris : reset(0) might be better */ delete this->get(); }
williamr@4
   104
williamr@4
   105
  auto_ptr(auto_ptr_ref<_Tp> __r) _STLP_NOTHROW
williamr@4
   106
  { this->__set(__r.release()); }
williamr@4
   107
williamr@4
   108
  _Self& operator=(auto_ptr_ref<_Tp> __r) _STLP_NOTHROW {
williamr@4
   109
    reset(__r.release());
williamr@4
   110
    return *this;
williamr@4
   111
  }
williamr@4
   112
williamr@4
   113
#if defined(_STLP_MEMBER_TEMPLATES) && !defined(_STLP_NO_TEMPLATE_CONVERSIONS)
williamr@4
   114
  template<class _Tp1> operator auto_ptr_ref<_Tp1>() _STLP_NOTHROW
williamr@4
   115
  { return auto_ptr_ref<_Tp1>(*this, this->get()); }
williamr@4
   116
  template<class _Tp1> operator auto_ptr<_Tp1>() _STLP_NOTHROW
williamr@4
   117
  { return auto_ptr<_Tp1>(release()); }
williamr@4
   118
#else
williamr@4
   119
  operator auto_ptr_ref<_Tp>() _STLP_NOTHROW
williamr@4
   120
  { return auto_ptr_ref<_Tp>(*this, this->get()); }
williamr@4
   121
#endif
williamr@4
   122
};
williamr@4
   123
_STLP_END_NAMESPACE
williamr@4
   124
williamr@4
   125
#endif /* _STLP_AUTO_PTR_H */
williamr@4
   126
williamr@4
   127
// Local Variables:
williamr@4
   128
// mode:C++
williamr@4
   129
// End: