OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 template<typename T, | 63 template<typename T, |
64 class = typename std::enable_if<std::is_base_of<ref_counted,T>::value>::type
> | 64 class = typename std::enable_if<std::is_base_of<ref_counted,T>::value>::type
> |
65 class intrusive_ptr | 65 class intrusive_ptr |
66 { | 66 { |
67 public: | 67 public: |
68 explicit intrusive_ptr() | 68 explicit intrusive_ptr() |
69 : mPointer(nullptr) | 69 : mPointer(nullptr) |
70 { | 70 { |
71 } | 71 } |
72 | 72 |
73 explicit intrusive_ptr(T* pointer) | 73 explicit intrusive_ptr(T* pointer, bool addRef = true) |
74 : mPointer(pointer) | 74 : mPointer(pointer) |
75 { | 75 { |
76 // Raw pointers always had their reference count increased by whatever gave | 76 if (mPointer && addRef) |
77 // us the pointer so we don't need to do it here. | 77 mPointer->AddRef(); |
78 } | 78 } |
79 | 79 |
80 intrusive_ptr(const intrusive_ptr& other) | 80 intrusive_ptr(const intrusive_ptr& other) |
81 : mPointer(other.mPointer) | 81 : mPointer(other.mPointer) |
82 { | 82 { |
83 if (mPointer) | 83 if (mPointer) |
84 mPointer->AddRef(); | 84 mPointer->AddRef(); |
85 } | 85 } |
86 | 86 |
87 intrusive_ptr(intrusive_ptr&& other) | 87 intrusive_ptr(intrusive_ptr&& other) |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 inline bool operator==(const T* a, const intrusive_ptr<U>& b) | 208 inline bool operator==(const T* a, const intrusive_ptr<U>& b) |
209 { | 209 { |
210 return a == b.get(); | 210 return a == b.get(); |
211 } | 211 } |
212 | 212 |
213 template<typename T, typename U> | 213 template<typename T, typename U> |
214 inline bool operator!=(const T* a, intrusive_ptr<U> const& b) | 214 inline bool operator!=(const T* a, intrusive_ptr<U> const& b) |
215 { | 215 { |
216 return a != b.get(); | 216 return a != b.get(); |
217 } | 217 } |
OLD | NEW |