| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Intel Corporation. All rights reserved. | 3 * Copyright (C) 2013 Intel Corporation. All rights reserved. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 bool isHashTableDeletedValue() const { return m_ptr == hashTableDeletedValue
(); } | 52 bool isHashTableDeletedValue() const { return m_ptr == hashTableDeletedValue
(); } |
| 53 | 53 |
| 54 ~OwnPtr() | 54 ~OwnPtr() |
| 55 { | 55 { |
| 56 OwnedPtrDeleter<T>::deletePtr(m_ptr); | 56 OwnedPtrDeleter<T>::deletePtr(m_ptr); |
| 57 m_ptr = nullptr; | 57 m_ptr = nullptr; |
| 58 } | 58 } |
| 59 | 59 |
| 60 PtrType get() const { return m_ptr; } | 60 PtrType get() const { return m_ptr; } |
| 61 | 61 |
| 62 // Note: clear() will soon get renamed to reset() as a part of OwnPtr -> std
::unique_ptr transition. | 62 void reset(); |
| 63 // For now, both are allowed to facilitate the rename process. See also: htt
p://crbug.com/611661 | |
| 64 void clear(); | |
| 65 void reset() { clear(); } | |
| 66 | 63 |
| 67 PtrType leakPtr() WARN_UNUSED_RETURN; | 64 PtrType leakPtr() WARN_UNUSED_RETURN; |
| 68 | 65 |
| 69 ValueType& operator*() const { ASSERT(m_ptr); return *m_ptr; } | 66 ValueType& operator*() const { ASSERT(m_ptr); return *m_ptr; } |
| 70 PtrType operator->() const { ASSERT(m_ptr); return m_ptr; } | 67 PtrType operator->() const { ASSERT(m_ptr); return m_ptr; } |
| 71 | 68 |
| 72 ValueType& operator[](std::ptrdiff_t i) const; | 69 ValueType& operator[](std::ptrdiff_t i) const; |
| 73 | 70 |
| 74 bool operator!() const { return !m_ptr; } | 71 bool operator!() const { return !m_ptr; } |
| 75 explicit operator bool() const { return m_ptr; } | 72 explicit operator bool() const { return m_ptr; } |
| 76 | 73 |
| 77 OwnPtr& operator=(std::nullptr_t) { clear(); return *this; } | 74 OwnPtr& operator=(std::nullptr_t) { reset(); return *this; } |
| 78 | 75 |
| 79 OwnPtr(OwnPtr&&); | 76 OwnPtr(OwnPtr&&); |
| 80 template <typename U, typename = typename std::enable_if<std::is_convertible
<U*, T*>::value>::type> OwnPtr(OwnPtr<U>&&); | 77 template <typename U, typename = typename std::enable_if<std::is_convertible
<U*, T*>::value>::type> OwnPtr(OwnPtr<U>&&); |
| 81 | 78 |
| 82 OwnPtr& operator=(OwnPtr&&); | 79 OwnPtr& operator=(OwnPtr&&); |
| 83 template <typename U> OwnPtr& operator=(OwnPtr<U>&&); | 80 template <typename U> OwnPtr& operator=(OwnPtr<U>&&); |
| 84 | 81 |
| 85 void swap(OwnPtr& o) { std::swap(m_ptr, o.m_ptr); } | 82 void swap(OwnPtr& o) { std::swap(m_ptr, o.m_ptr); } |
| 86 | 83 |
| 87 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } | 84 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 99 } | 96 } |
| 100 template <typename U> bool operator!=(const OwnPtr<U>&) const | 97 template <typename U> bool operator!=(const OwnPtr<U>&) const |
| 101 { | 98 { |
| 102 static_assert(!sizeof(U*), "OwnPtrs should never be equal"); | 99 static_assert(!sizeof(U*), "OwnPtrs should never be equal"); |
| 103 return false; | 100 return false; |
| 104 } | 101 } |
| 105 | 102 |
| 106 PtrType m_ptr; | 103 PtrType m_ptr; |
| 107 }; | 104 }; |
| 108 | 105 |
| 109 template <typename T> inline void OwnPtr<T>::clear() | 106 template <typename T> inline void OwnPtr<T>::reset() |
| 110 { | 107 { |
| 111 PtrType ptr = m_ptr; | 108 PtrType ptr = m_ptr; |
| 112 m_ptr = nullptr; | 109 m_ptr = nullptr; |
| 113 OwnedPtrDeleter<T>::deletePtr(ptr); | 110 OwnedPtrDeleter<T>::deletePtr(ptr); |
| 114 } | 111 } |
| 115 | 112 |
| 116 template <typename T> inline typename OwnPtr<T>::PtrType OwnPtr<T>::leakPtr() | 113 template <typename T> inline typename OwnPtr<T>::PtrType OwnPtr<T>::leakPtr() |
| 117 { | 114 { |
| 118 PtrType ptr = m_ptr; | 115 PtrType ptr = m_ptr; |
| 119 m_ptr = nullptr; | 116 m_ptr = nullptr; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 template <typename T> inline typename OwnPtr<T>::PtrType getPtr(const OwnPtr<T>&
p) | 187 template <typename T> inline typename OwnPtr<T>::PtrType getPtr(const OwnPtr<T>&
p) |
| 191 { | 188 { |
| 192 return p.get(); | 189 return p.get(); |
| 193 } | 190 } |
| 194 | 191 |
| 195 } // namespace WTF | 192 } // namespace WTF |
| 196 | 193 |
| 197 using WTF::OwnPtr; | 194 using WTF::OwnPtr; |
| 198 | 195 |
| 199 #endif // WTF_OwnPtr_h | 196 #endif // WTF_OwnPtr_h |
| OLD | NEW |