InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Hacked_AutoPtr.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner:
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // ADOBE CONFIDENTIAL
16 //
17 // Copyright 2019 Adobe Systems Incorporated. All rights reserved.
18 //
19 // NOTICE: All information contained herein is, and remains
20 // the property of Adobe Systems Incorporated and its suppliers,
21 // if any. The intellectual and technical concepts contained
22 // herein are proprietary to Adobe Systems Incorporated and its
23 // suppliers and may be covered by U.S. and Foreign Patents,
24 // patents in process, and are protected by trade secret or copyright law.
25 // Dissemination of this information or reproduction of this material
26 // is strictly forbidden unless prior written permission is obtained
27 // from Adobe Systems Incorporated.
28 //
29 //
30 //========================================================================================
31 
32 #ifndef __HACKED_AUTO_PTR__
33 #define __HACKED_AUTO_PTR__
34 
35 #ifdef __cplusplus
36 namespace indesign
37 {
38  template <class _Tp>
39  struct hacked_auto_ptr_ref
40  {
41  _Tp* ptr_;
42  };
43 
44  template<class _Tp>
45  class hacked_auto_ptr
46  {
47  private:
48  _Tp* ptr_;
49  public:
50  typedef _Tp element_type;
51 
52  explicit hacked_auto_ptr(_Tp* p = 0) throw() : ptr_(p) {}
53  hacked_auto_ptr(hacked_auto_ptr& p) throw() : ptr_(p.release()) {}
54  template<class _Up> hacked_auto_ptr(hacked_auto_ptr<_Up>& p) throw()
55  : ptr_(p.release()) {}
56  hacked_auto_ptr& operator=(hacked_auto_ptr& p) throw()
57  {reset(p.release()); return *this;}
58  template<class _Up> hacked_auto_ptr& operator=(hacked_auto_ptr<_Up>& p) throw()
59  {reset(p.release()); return *this;}
60  hacked_auto_ptr& operator=(hacked_auto_ptr_ref<_Tp> p) throw()
61  {reset(p.ptr_); return *this;}
62  ~hacked_auto_ptr() throw() {delete ptr_;}
63 
64  _Tp& operator*() const throw()
65  {return *ptr_;}
66  _Tp* operator->() const throw() {return ptr_;}
67  _Tp* get() const throw() {return ptr_;}
68  _Tp* release() throw()
69  {
70  _Tp* t = ptr_;
71  ptr_ = 0;
72  return t;
73  }
74  void reset(_Tp* p = 0) throw()
75  {
76  if (ptr_ != p)
77  delete ptr_;
78  ptr_ = p;
79  }
80 
81  hacked_auto_ptr(hacked_auto_ptr_ref<_Tp> p) throw() : ptr_(p.ptr_) {}
82  template<class _Up> operator hacked_auto_ptr_ref<_Up>() throw()
83  {hacked_auto_ptr_ref<_Up> t; t.ptr_ = release(); return t;}
84  template<class _Up> operator hacked_auto_ptr<_Up>() throw()
85  {return hacked_auto_ptr<_Up>(release());}
86  };
87 
88  template <>
89  class hacked_auto_ptr<void>
90  {
91  public:
92  typedef void element_type;
93  };
94 
95 }
96 
97 #endif
98 
99 #endif // __HACKED_AUTO_PTR__
100 
101