| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // A "smart" pointer type with reference tracking. Every pointer to a | 5 // A "smart" pointer type with reference tracking. Every pointer to a |
| 6 // particular object is kept on a circular linked list. When the last pointer | 6 // particular object is kept on a circular linked list. When the last pointer |
| 7 // to an object is destroyed or reassigned, the object is deleted. | 7 // to an object is destroyed or reassigned, the object is deleted. |
| 8 // | 8 // |
| 9 // Used properly, this deletes the object when the last reference goes away. | 9 // Used properly, this deletes the object when the last reference goes away. |
| 10 // There are several caveats: | 10 // There are several caveats: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // A linked_ptr is NOT thread safe. Copying a linked_ptr object is | 29 // A linked_ptr is NOT thread safe. Copying a linked_ptr object is |
| 30 // effectively a read-write operation. | 30 // effectively a read-write operation. |
| 31 // | 31 // |
| 32 // Alternative: to linked_ptr is shared_ptr, which | 32 // Alternative: to linked_ptr is shared_ptr, which |
| 33 // - is also two pointers in size (8 bytes for 32 bit addresses) | 33 // - is also two pointers in size (8 bytes for 32 bit addresses) |
| 34 // - is thread safe for copying and deletion | 34 // - is thread safe for copying and deletion |
| 35 // - supports weak_ptrs | 35 // - supports weak_ptrs |
| 36 | 36 |
| 37 #ifndef BASE_MEMORY_LINKED_PTR_H_ | 37 #ifndef BASE_MEMORY_LINKED_PTR_H_ |
| 38 #define BASE_MEMORY_LINKED_PTR_H_ | 38 #define BASE_MEMORY_LINKED_PTR_H_ |
| 39 #pragma once | |
| 40 | 39 |
| 41 #include "base/logging.h" // for CHECK macros | 40 #include "base/logging.h" // for CHECK macros |
| 42 | 41 |
| 43 // This is used internally by all instances of linked_ptr<>. It needs to be | 42 // This is used internally by all instances of linked_ptr<>. It needs to be |
| 44 // a non-template class because different types of linked_ptr<> can refer to | 43 // a non-template class because different types of linked_ptr<> can refer to |
| 45 // the same object (linked_ptr<Superclass>(obj) vs linked_ptr<Subclass>(obj)). | 44 // the same object (linked_ptr<Superclass>(obj) vs linked_ptr<Subclass>(obj)). |
| 46 // So, it needs to be possible for different types of linked_ptr to participate | 45 // So, it needs to be possible for different types of linked_ptr to participate |
| 47 // in the same circular linked list, so we need a single class type here. | 46 // in the same circular linked list, so we need a single class type here. |
| 48 // | 47 // |
| 49 // DO NOT USE THIS CLASS DIRECTLY YOURSELF. Use linked_ptr<T>. | 48 // DO NOT USE THIS CLASS DIRECTLY YOURSELF. Use linked_ptr<T>. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 172 |
| 174 // A function to convert T* into linked_ptr<T> | 173 // A function to convert T* into linked_ptr<T> |
| 175 // Doing e.g. make_linked_ptr(new FooBarBaz<type>(arg)) is a shorter notation | 174 // Doing e.g. make_linked_ptr(new FooBarBaz<type>(arg)) is a shorter notation |
| 176 // for linked_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) | 175 // for linked_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) |
| 177 template <typename T> | 176 template <typename T> |
| 178 linked_ptr<T> make_linked_ptr(T* ptr) { | 177 linked_ptr<T> make_linked_ptr(T* ptr) { |
| 179 return linked_ptr<T>(ptr); | 178 return linked_ptr<T>(ptr); |
| 180 } | 179 } |
| 181 | 180 |
| 182 #endif // BASE_MEMORY_LINKED_PTR_H_ | 181 #endif // BASE_MEMORY_LINKED_PTR_H_ |
| OLD | NEW |