| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Scopers help you manage ownership of a pointer, helping you easily manage a | 5 // Scopers help you manage ownership of a pointer, helping you easily manage a |
| 6 // pointer within a scope, and automatically destroying the pointer at the end | 6 // pointer within a scope, and automatically destroying the pointer at the end |
| 7 // of a scope. There are two main classes you will use, which correspond to the | 7 // of a scope. There are two main classes you will use, which correspond to the |
| 8 // operators new/delete and new[]/delete[]. | 8 // operators new/delete and new[]/delete[]. |
| 9 // | 9 // |
| 10 // Example usage (scoped_ptr<T>): | 10 // Example usage (scoped_ptr<T>): |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 #include <iosfwd> | 96 #include <iosfwd> |
| 97 #include <memory> | 97 #include <memory> |
| 98 #include <type_traits> | 98 #include <type_traits> |
| 99 #include <utility> | 99 #include <utility> |
| 100 | 100 |
| 101 #include "base/compiler_specific.h" | 101 #include "base/compiler_specific.h" |
| 102 #include "base/logging.h" | 102 #include "base/logging.h" |
| 103 #include "base/macros.h" | 103 #include "base/macros.h" |
| 104 #include "base/move.h" | 104 #include "base/move.h" |
| 105 #include "base/template_util.h" | |
| 106 #include "build/build_config.h" | 105 #include "build/build_config.h" |
| 107 | 106 |
| 108 namespace base { | 107 namespace base { |
| 109 | 108 |
| 110 // Function object which invokes 'free' on its parameter, which must be | 109 // Function object which invokes 'free' on its parameter, which must be |
| 111 // a pointer. Can be used to store malloc-allocated pointers in scoped_ptr: | 110 // a pointer. Can be used to store malloc-allocated pointers in scoped_ptr: |
| 112 // | 111 // |
| 113 // scoped_ptr<int, base::FreeDeleter> foo_ptr( | 112 // scoped_ptr<int, base::FreeDeleter> foo_ptr( |
| 114 // static_cast<int*>(malloc(sizeof(int)))); | 113 // static_cast<int*>(malloc(sizeof(int)))); |
| 115 struct FreeDeleter { | 114 struct FreeDeleter { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 171 |
| 173 namespace subtle { | 172 namespace subtle { |
| 174 class RefCountedBase; | 173 class RefCountedBase; |
| 175 class RefCountedThreadSafeBase; | 174 class RefCountedThreadSafeBase; |
| 176 } // namespace subtle | 175 } // namespace subtle |
| 177 | 176 |
| 178 namespace internal { | 177 namespace internal { |
| 179 | 178 |
| 180 template <typename T> struct IsNotRefCounted { | 179 template <typename T> struct IsNotRefCounted { |
| 181 enum { | 180 enum { |
| 182 value = !base::is_convertible<T*, base::subtle::RefCountedBase*>::value && | 181 value = !std::is_convertible<T*, base::subtle::RefCountedBase*>::value && |
| 183 !base::is_convertible<T*, base::subtle::RefCountedThreadSafeBase*>:: | 182 !std::is_convertible<T*, base::subtle::RefCountedThreadSafeBase*>:: |
| 184 value | 183 value |
| 185 }; | 184 }; |
| 186 }; | 185 }; |
| 187 | 186 |
| 188 // Minimal implementation of the core logic of scoped_ptr, suitable for | 187 // Minimal implementation of the core logic of scoped_ptr, suitable for |
| 189 // reuse in both scoped_ptr and its specializations. | 188 // reuse in both scoped_ptr and its specializations. |
| 190 template <class T, class D> | 189 template <class T, class D> |
| 191 class scoped_ptr_impl { | 190 class scoped_ptr_impl { |
| 192 public: | 191 public: |
| 193 explicit scoped_ptr_impl(T* p) : data_(p) {} | 192 explicit scoped_ptr_impl(T* p) : data_(p) {} |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 | 670 |
| 672 // A function to convert T* into scoped_ptr<T> | 671 // A function to convert T* into scoped_ptr<T> |
| 673 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation | 672 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation |
| 674 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) | 673 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) |
| 675 template <typename T> | 674 template <typename T> |
| 676 scoped_ptr<T> make_scoped_ptr(T* ptr) { | 675 scoped_ptr<T> make_scoped_ptr(T* ptr) { |
| 677 return scoped_ptr<T>(ptr); | 676 return scoped_ptr<T>(ptr); |
| 678 } | 677 } |
| 679 | 678 |
| 680 #endif // BASE_MEMORY_SCOPED_PTR_H_ | 679 #endif // BASE_MEMORY_SCOPED_PTR_H_ |
| OLD | NEW |