| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef WTF_RawPtr_h | 31 #ifndef WTF_RawPtr_h |
| 32 #define WTF_RawPtr_h | 32 #define WTF_RawPtr_h |
| 33 | 33 |
| 34 #include <algorithm> | 34 #include <algorithm> |
| 35 #include <stdint.h> | 35 #include <stdint.h> |
| 36 | 36 |
| 37 #include "wtf/HashTableDeletedValueType.h" | 37 #include "wtf/HashTableDeletedValueType.h" |
| 38 #include "wtf/TypeTraits.h" |
| 38 | 39 |
| 39 // RawPtr is a simple wrapper for a raw pointer that provides the | 40 // RawPtr is a simple wrapper for a raw pointer that provides the |
| 40 // interface (get, clear) of other pointer types such as RefPtr, | 41 // interface (get, clear) of other pointer types such as RefPtr, |
| 41 // Persistent and Member. This is used for the Blink garbage | 42 // Persistent and Member. This is used for the Blink garbage |
| 42 // collection work in order to be able to write shared code that will | 43 // collection work in order to be able to write shared code that will |
| 43 // use reference counting or garbage collection based on a | 44 // use reference counting or garbage collection based on a |
| 44 // compile-time flag. | 45 // compile-time flag. |
| 45 | 46 |
| 46 namespace WTF { | 47 namespace WTF { |
| 47 | 48 |
| 48 template<typename T> | 49 template<typename T> |
| 49 class RawPtr { | 50 class RawPtr { |
| 50 public: | 51 public: |
| 51 RawPtr() | 52 RawPtr() |
| 52 { | 53 { |
| 53 #if ENABLE(ASSERT) | 54 #if ENABLE(ASSERT) |
| 54 m_ptr = reinterpret_cast<T*>(rawPtrZapValue); | 55 m_ptr = reinterpret_cast<T*>(rawPtrZapValue); |
| 55 #endif | 56 #endif |
| 56 } | 57 } |
| 57 RawPtr(std::nullptr_t) : m_ptr(0) { } | 58 RawPtr(std::nullptr_t) : m_ptr(0) { } |
| 58 RawPtr(T* ptr) : m_ptr(ptr) { } | 59 RawPtr(T* ptr) : m_ptr(ptr) { } |
| 59 explicit RawPtr(T& reference) : m_ptr(&reference) { } | 60 explicit RawPtr(T& reference) : m_ptr(&reference) { } |
| 60 RawPtr(const RawPtr& other) | 61 RawPtr(const RawPtr& other) |
| 61 : m_ptr(other.get()) | 62 : m_ptr(other.get()) |
| 62 { | 63 { |
| 63 } | 64 } |
| 64 | 65 |
| 65 template<typename U> | 66 template<typename U> |
| 66 RawPtr(const RawPtr<U>& other) | 67 RawPtr(const RawPtr<U>& other, EnsurePtrConvertibleArgDecl(U, T)) |
| 67 : m_ptr(other.get()) | 68 : m_ptr(other.get()) |
| 68 { | 69 { |
| 69 } | 70 } |
| 70 | 71 |
| 71 // Hash table deleted values, which are only constructed and never copied or
destroyed. | 72 // Hash table deleted values, which are only constructed and never copied or
destroyed. |
| 72 RawPtr(HashTableDeletedValueType) : m_ptr(hashTableDeletedValue()) { } | 73 RawPtr(HashTableDeletedValueType) : m_ptr(hashTableDeletedValue()) { } |
| 73 bool isHashTableDeletedValue() const { return m_ptr == hashTableDeletedValue
(); } | 74 bool isHashTableDeletedValue() const { return m_ptr == hashTableDeletedValue
(); } |
| 74 | 75 |
| 75 T* get() const { return m_ptr; } | 76 T* get() const { return m_ptr; } |
| 76 void clear() { m_ptr = 0; } | 77 void clear() { m_ptr = 0; } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 template<typename T> inline T* getPtr(const RawPtr<T>& p) | 140 template<typename T> inline T* getPtr(const RawPtr<T>& p) |
| 140 { | 141 { |
| 141 return p.get(); | 142 return p.get(); |
| 142 } | 143 } |
| 143 | 144 |
| 144 } // namespace WTF | 145 } // namespace WTF |
| 145 | 146 |
| 146 using WTF::RawPtr; | 147 using WTF::RawPtr; |
| 147 | 148 |
| 148 #endif | 149 #endif |
| OLD | NEW |