OLD | NEW |
1 // Parts of this code have been copied from boost/smart_ptr/intrusive_ptr.hpp. | 1 // Parts of this code have been copied from boost/smart_ptr/intrusive_ptr.hpp. |
2 // | 2 // |
3 // Copyright (c) 2001, 2002 Peter Dimov | 3 // Copyright (c) 2001, 2002 Peter Dimov |
4 // | 4 // |
5 // Distributed under the Boost Software License, Version 1.0. (See | 5 // Distributed under the Boost Software License, Version 1.0. (See |
6 // accompanying file LICENSE_1_0.txt or copy at | 6 // accompanying file LICENSE_1_0.txt or copy at |
7 // http://www.boost.org/LICENSE_1_0.txt) | 7 // http://www.boost.org/LICENSE_1_0.txt) |
8 | 8 |
9 #pragma once | 9 #pragma once |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 template<typename T, | 46 template<typename T, |
47 class = typename std::enable_if<std::is_base_of<ref_counted,T>::value>::type
> | 47 class = typename std::enable_if<std::is_base_of<ref_counted,T>::value>::type
> |
48 class intrusive_ptr | 48 class intrusive_ptr |
49 { | 49 { |
50 public: | 50 public: |
51 explicit intrusive_ptr() | 51 explicit intrusive_ptr() |
52 : mPointer(nullptr) | 52 : mPointer(nullptr) |
53 { | 53 { |
54 } | 54 } |
55 | 55 |
56 explicit intrusive_ptr(T* pointer) | 56 explicit intrusive_ptr(T* pointer, bool addRef = true) |
57 : mPointer(pointer) | 57 : mPointer(pointer) |
58 { | 58 { |
59 // Raw pointers always had their reference count increased by whatever gave | 59 if (mPointer && addRef) |
60 // us the pointer so we don't need to do it here. | 60 mPointer->AddRef(); |
61 } | 61 } |
62 | 62 |
63 explicit intrusive_ptr(const intrusive_ptr& other) | 63 explicit intrusive_ptr(const intrusive_ptr& other) |
64 : mPointer(other.mPointer) | 64 : mPointer(other.mPointer) |
65 { | 65 { |
66 if (mPointer) | 66 if (mPointer) |
67 mPointer->AddRef(); | 67 mPointer->AddRef(); |
68 } | 68 } |
69 | 69 |
70 explicit intrusive_ptr(intrusive_ptr&& other) | 70 explicit intrusive_ptr(intrusive_ptr&& other) |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 inline bool operator==(const T* a, const intrusive_ptr<U>& b) | 191 inline bool operator==(const T* a, const intrusive_ptr<U>& b) |
192 { | 192 { |
193 return a == b.get(); | 193 return a == b.get(); |
194 } | 194 } |
195 | 195 |
196 template<typename T, typename U> | 196 template<typename T, typename U> |
197 inline bool operator!=(const T* a, intrusive_ptr<U> const& b) | 197 inline bool operator!=(const T* a, intrusive_ptr<U> const& b) |
198 { | 198 { |
199 return a != b.get(); | 199 return a != b.get(); |
200 } | 200 } |
OLD | NEW |