diff options
-rw-r--r-- | hkutil/recptr.h | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/hkutil/recptr.h b/hkutil/recptr.h index c39e9d8..09c3113 100644 --- a/hkutil/recptr.h +++ b/hkutil/recptr.h | |||
@@ -14,6 +14,8 @@ namespace hatkirby { | |||
14 | class recptr { | 14 | class recptr { |
15 | public: | 15 | public: |
16 | 16 | ||
17 | recptr() = default; | ||
18 | |||
17 | recptr(T* ptr) : ptr_(ptr) | 19 | recptr(T* ptr) : ptr_(ptr) |
18 | { | 20 | { |
19 | } | 21 | } |
@@ -24,8 +26,11 @@ namespace hatkirby { | |||
24 | } | 26 | } |
25 | 27 | ||
26 | recptr(const recptr& other) | 28 | recptr(const recptr& other) |
27 | : ptr_(new T(*other.ptr_)) | ||
28 | { | 29 | { |
30 | if (other.ptr_) | ||
31 | { | ||
32 | ptr_ = new T(*other.ptr_); | ||
33 | } | ||
29 | } | 34 | } |
30 | 35 | ||
31 | recptr(recptr&& other) | 36 | recptr(recptr&& other) |
@@ -38,9 +43,14 @@ namespace hatkirby { | |||
38 | if (ptr_) | 43 | if (ptr_) |
39 | { | 44 | { |
40 | delete ptr_; | 45 | delete ptr_; |
46 | |||
47 | ptr_ = nullptr; | ||
41 | } | 48 | } |
42 | 49 | ||
43 | ptr_ = new T(*other.ptr_); | 50 | if (other.ptr_) |
51 | { | ||
52 | ptr_ = new T(*other.ptr_); | ||
53 | } | ||
44 | 54 | ||
45 | return *this; | 55 | return *this; |
46 | } | 56 | } |
@@ -79,6 +89,11 @@ namespace hatkirby { | |||
79 | return ptr_; | 89 | return ptr_; |
80 | } | 90 | } |
81 | 91 | ||
92 | operator bool() const | ||
93 | { | ||
94 | return (ptr_ != nullptr); | ||
95 | } | ||
96 | |||
82 | private: | 97 | private: |
83 | 98 | ||
84 | T* ptr_ = nullptr; | 99 | T* ptr_ = nullptr; |