OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Provides a smart pointer class for intrusively reference-counted objects. | 5 // Provides a smart pointer class for intrusively reference-counted objects. |
6 | 6 |
7 #ifndef MOJO_EDK_UTIL_REF_PTR_H_ | 7 #ifndef MOJO_EDK_UTIL_REF_PTR_H_ |
8 #define MOJO_EDK_UTIL_REF_PTR_H_ | 8 #define MOJO_EDK_UTIL_REF_PTR_H_ |
9 | 9 |
10 #include <assert.h> | 10 #include <assert.h> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 // |U = T|, since the templated versions don't count as copy/move | 56 // |U = T|, since the templated versions don't count as copy/move |
57 // constructors/operator=s for the purposes of causing the default copy | 57 // constructors/operator=s for the purposes of causing the default copy |
58 // constructor/operator= to be deleted. E.g., if we didn't declare any | 58 // constructor/operator= to be deleted. E.g., if we didn't declare any |
59 // non-templated versions, we'd get the default copy constructor/operator= (we'd | 59 // non-templated versions, we'd get the default copy constructor/operator= (we'd |
60 // only not get the default move constructor/operator= by virtue of having a | 60 // only not get the default move constructor/operator= by virtue of having a |
61 // destructor)! (In fact, it'd suffice to only declare a non-templated move | 61 // destructor)! (In fact, it'd suffice to only declare a non-templated move |
62 // constructor or move operator=, which would cause the copy | 62 // constructor or move operator=, which would cause the copy |
63 // constructor/operator= to be deleted, but for clarity we include explicit | 63 // constructor/operator= to be deleted, but for clarity we include explicit |
64 // non-templated versions of everything.) | 64 // non-templated versions of everything.) |
65 template <typename T> | 65 template <typename T> |
66 class RefPtr { | 66 class RefPtr final { |
67 public: | 67 public: |
68 RefPtr() : ptr_(nullptr) {} | 68 RefPtr() : ptr_(nullptr) {} |
69 RefPtr(std::nullptr_t) : ptr_(nullptr) {} | 69 RefPtr(std::nullptr_t) : ptr_(nullptr) {} |
70 | 70 |
71 // Explicit constructor from a plain pointer (to an object that must have | 71 // Explicit constructor from a plain pointer (to an object that must have |
72 // already been adopted). (Note that in |T::T()|, references to |this| cannot | 72 // already been adopted). (Note that in |T::T()|, references to |this| cannot |
73 // be taken, since the object being constructed will not have been adopted | 73 // be taken, since the object being constructed will not have been adopted |
74 // yet.) | 74 // yet.) |
75 template <typename U> | 75 template <typename U> |
76 explicit RefPtr(U* p) | 76 explicit RefPtr(U* p) |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 template <typename T, typename... Args> | 224 template <typename T, typename... Args> |
225 RefPtr<T> MakeRefCounted(Args&&... args) { | 225 RefPtr<T> MakeRefCounted(Args&&... args) { |
226 return internal::MakeRefCountedHelper<T>::MakeRefCounted( | 226 return internal::MakeRefCountedHelper<T>::MakeRefCounted( |
227 std::forward<Args>(args)...); | 227 std::forward<Args>(args)...); |
228 } | 228 } |
229 | 229 |
230 } // namespace util | 230 } // namespace util |
231 } // namespace mojo | 231 } // namespace mojo |
232 | 232 |
233 #endif // MOJO_EDK_UTIL_REF_PTR_H_ | 233 #endif // MOJO_EDK_UTIL_REF_PTR_H_ |
OLD | NEW |