Chromium Code Reviews| 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 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 #endif | 43 #endif |
| 44 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(OwnPtr); | 44 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(OwnPtr); |
| 45 public: | 45 public: |
| 46 typedef typename RemovePointer<T>::Type ValueType; | 46 typedef typename RemovePointer<T>::Type ValueType; |
| 47 typedef ValueType* PtrType; | 47 typedef ValueType* PtrType; |
| 48 | 48 |
| 49 OwnPtr() : m_ptr(0) { } | 49 OwnPtr() : m_ptr(0) { } |
| 50 OwnPtr(std::nullptr_t) : m_ptr(0) { } | 50 OwnPtr(std::nullptr_t) : m_ptr(0) { } |
| 51 | 51 |
| 52 // See comment in PassOwnPtr.h for why this takes a const reference. | 52 // See comment in PassOwnPtr.h for why this takes a const reference. |
| 53 template<typename U> OwnPtr(const PassOwnPtr<U>& o); | 53 template<typename U> OwnPtr(const PassOwnPtr<U>&, EnsurePtrConvertibleAr gDecl(typename RemovePointer<U>::Type, ValueType)); |
| 54 | 54 |
| 55 #if !COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES) | 55 #if !COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES) |
| 56 // This copy constructor is used implicitly by gcc when it generates | 56 // This copy constructor is used implicitly by gcc when it generates |
| 57 // transients for assigning a PassOwnPtr<T> object to a stack-allocated | 57 // transients for assigning a PassOwnPtr<T> object to a stack-allocated |
| 58 // OwnPtr<T> object. It should never be called explicitly and gcc | 58 // OwnPtr<T> object. It should never be called explicitly and gcc |
| 59 // should optimize away the constructor when generating code. | 59 // should optimize away the constructor when generating code. |
| 60 OwnPtr(const OwnPtr<ValueType>&); | 60 OwnPtr(const OwnPtr<ValueType>&); |
| 61 #endif | 61 #endif |
| 62 | 62 |
| 63 ~OwnPtr() | 63 ~OwnPtr() |
|
Mikhail
2013/09/02 18:35:12
Weird I don't have this change locally.
| |
| 64 { | 64 { |
| 65 deleteOwnedPtr(m_ptr); | 65 deleteOwnedPtr(m_ptr); |
| 66 m_ptr = 0; | 66 m_ptr = 0; |
| 67 } | 67 } |
| 68 | 68 |
| 69 PtrType get() const { return m_ptr; } | 69 PtrType get() const { return m_ptr; } |
| 70 | 70 |
| 71 void clear(); | 71 void clear(); |
| 72 PassOwnPtr<T> release(); | 72 PassOwnPtr<T> release(); |
| 73 PtrType leakPtr() WARN_UNUSED_RETURN; | 73 PtrType leakPtr() WARN_UNUSED_RETURN; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 104 // We should never have two OwnPtrs for the same underlying object (othe rwise we'll get | 104 // We should never have two OwnPtrs for the same underlying object (othe rwise we'll get |
| 105 // double-destruction), so these equality operators should never be need ed. | 105 // double-destruction), so these equality operators should never be need ed. |
| 106 template<typename U> bool operator==(const OwnPtr<U>&) { COMPILE_ASSERT( !sizeof(U*), OwnPtrs_should_never_be_equal); return false; } | 106 template<typename U> bool operator==(const OwnPtr<U>&) { COMPILE_ASSERT( !sizeof(U*), OwnPtrs_should_never_be_equal); return false; } |
| 107 template<typename U> bool operator!=(const OwnPtr<U>&) { COMPILE_ASSERT( !sizeof(U*), OwnPtrs_should_never_be_equal); return false; } | 107 template<typename U> bool operator!=(const OwnPtr<U>&) { COMPILE_ASSERT( !sizeof(U*), OwnPtrs_should_never_be_equal); return false; } |
| 108 template<typename U> bool operator==(const PassOwnPtr<U>&) { COMPILE_ASS ERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } | 108 template<typename U> bool operator==(const PassOwnPtr<U>&) { COMPILE_ASS ERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } |
| 109 template<typename U> bool operator!=(const PassOwnPtr<U>&) { COMPILE_ASS ERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } | 109 template<typename U> bool operator!=(const PassOwnPtr<U>&) { COMPILE_ASS ERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } |
| 110 | 110 |
| 111 PtrType m_ptr; | 111 PtrType m_ptr; |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 template<typename T> template<typename U> inline OwnPtr<T>::OwnPtr(const Pas sOwnPtr<U>& o) | 114 template<typename T> template<typename U> inline OwnPtr<T>::OwnPtr(const Pas sOwnPtr<U>& o, EnsurePtrConvertibleArgDefn(typename RemovePointer<U>::Type, Valu eType)) |
| 115 : m_ptr(o.leakPtr()) | 115 : m_ptr(o.leakPtr()) |
| 116 { | 116 { |
| 117 } | 117 } |
| 118 | 118 |
| 119 template<typename T> inline void OwnPtr<T>::clear() | 119 template<typename T> inline void OwnPtr<T>::clear() |
| 120 { | 120 { |
| 121 PtrType ptr = m_ptr; | 121 PtrType ptr = m_ptr; |
| 122 m_ptr = 0; | 122 m_ptr = 0; |
| 123 deleteOwnedPtr(ptr); | 123 deleteOwnedPtr(ptr); |
| 124 } | 124 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 template<typename T> inline typename OwnPtr<T>::PtrType getPtr(const OwnPtr< T>& p) | 215 template<typename T> inline typename OwnPtr<T>::PtrType getPtr(const OwnPtr< T>& p) |
| 216 { | 216 { |
| 217 return p.get(); | 217 return p.get(); |
| 218 } | 218 } |
| 219 | 219 |
| 220 } // namespace WTF | 220 } // namespace WTF |
| 221 | 221 |
| 222 using WTF::OwnPtr; | 222 using WTF::OwnPtr; |
| 223 | 223 |
| 224 #endif // WTF_OwnPtr_h | 224 #endif // WTF_OwnPtr_h |
| OLD | NEW |