diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2021-12-27 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-03-18 15:35:13 +0500 |
commit | f19f813537c7aea1c20749c914e756b54a9c3cf5 (patch) | |
tree | 816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /CPP/Common/AutoPtr.h | |
parent | 98e06a519b63b81986abe76d28887f6984a7732b (diff) | |
download | 7zip-21.07.tar.gz 7zip-21.07.tar.bz2 7zip-21.07.zip |
'21.07'21.07
Diffstat (limited to 'CPP/Common/AutoPtr.h')
-rw-r--r-- | CPP/Common/AutoPtr.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/CPP/Common/AutoPtr.h b/CPP/Common/AutoPtr.h new file mode 100644 index 0000000..006d315 --- /dev/null +++ b/CPP/Common/AutoPtr.h | |||
@@ -0,0 +1,35 @@ | |||
1 | // Common/AutoPtr.h | ||
2 | |||
3 | #ifndef __COMMON_AUTOPTR_H | ||
4 | #define __COMMON_AUTOPTR_H | ||
5 | |||
6 | template<class T> class CMyAutoPtr | ||
7 | { | ||
8 | T *_p; | ||
9 | public: | ||
10 | CMyAutoPtr(T *p = 0) : _p(p) {} | ||
11 | CMyAutoPtr(CMyAutoPtr<T>& p): _p(p.release()) {} | ||
12 | CMyAutoPtr<T>& operator=(CMyAutoPtr<T>& p) | ||
13 | { | ||
14 | reset(p.release()); | ||
15 | return (*this); | ||
16 | } | ||
17 | ~CMyAutoPtr() { delete _p; } | ||
18 | T& operator*() const { return *_p; } | ||
19 | // T* operator->() const { return (&**this); } | ||
20 | T* get() const { return _p; } | ||
21 | T* release() | ||
22 | { | ||
23 | T *tmp = _p; | ||
24 | _p = 0; | ||
25 | return tmp; | ||
26 | } | ||
27 | void reset(T* p = 0) | ||
28 | { | ||
29 | if (p != _p) | ||
30 | delete _p; | ||
31 | _p = p; | ||
32 | } | ||
33 | }; | ||
34 | |||
35 | #endif | ||