| 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 30 matching lines...) Expand all Loading... |
| 41 #endif | 41 #endif |
| 42 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(OwnPtr); | 42 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(OwnPtr); |
| 43 public: | 43 public: |
| 44 typedef T ValueType; | 44 typedef T ValueType; |
| 45 typedef ValueType* PtrType; | 45 typedef ValueType* PtrType; |
| 46 | 46 |
| 47 OwnPtr() : m_ptr(0) { } | 47 OwnPtr() : m_ptr(0) { } |
| 48 OwnPtr(std::nullptr_t) : m_ptr(0) { } | 48 OwnPtr(std::nullptr_t) : m_ptr(0) { } |
| 49 | 49 |
| 50 // See comment in PassOwnPtr.h for why this takes a const reference. | 50 // See comment in PassOwnPtr.h for why this takes a const reference. |
| 51 template<typename U> OwnPtr(const PassOwnPtr<U>& o); | 51 template<typename U> OwnPtr(const PassOwnPtr<U>&, EnsurePtrConvertibleAr
gDecl(U, T)); |
| 52 | 52 |
| 53 #if !COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES) | 53 #if !COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES) |
| 54 // This copy constructor is used implicitly by gcc when it generates | 54 // This copy constructor is used implicitly by gcc when it generates |
| 55 // transients for assigning a PassOwnPtr<T> object to a stack-allocated | 55 // transients for assigning a PassOwnPtr<T> object to a stack-allocated |
| 56 // OwnPtr<T> object. It should never be called explicitly and gcc | 56 // OwnPtr<T> object. It should never be called explicitly and gcc |
| 57 // should optimize away the constructor when generating code. | 57 // should optimize away the constructor when generating code. |
| 58 OwnPtr(const OwnPtr<ValueType>&); | 58 OwnPtr(const OwnPtr<ValueType>&); |
| 59 #endif | 59 #endif |
| 60 | 60 |
| 61 ~OwnPtr() | 61 ~OwnPtr() |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // We should never have two OwnPtrs for the same underlying object (othe
rwise we'll get | 102 // We should never have two OwnPtrs for the same underlying object (othe
rwise we'll get |
| 103 // double-destruction), so these equality operators should never be need
ed. | 103 // double-destruction), so these equality operators should never be need
ed. |
| 104 template<typename U> bool operator==(const OwnPtr<U>&) { COMPILE_ASSERT(
!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } | 104 template<typename U> bool operator==(const OwnPtr<U>&) { COMPILE_ASSERT(
!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } |
| 105 template<typename U> bool operator!=(const OwnPtr<U>&) { COMPILE_ASSERT(
!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } | 105 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 PassOwnPtr<U>&) { COMPILE_ASS
ERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } | 106 template<typename U> bool operator==(const PassOwnPtr<U>&) { COMPILE_ASS
ERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } |
| 107 template<typename U> bool operator!=(const PassOwnPtr<U>&) { COMPILE_ASS
ERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } | 107 template<typename U> bool operator!=(const PassOwnPtr<U>&) { COMPILE_ASS
ERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } |
| 108 | 108 |
| 109 PtrType m_ptr; | 109 PtrType m_ptr; |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 template<typename T> template<typename U> inline OwnPtr<T>::OwnPtr(const Pas
sOwnPtr<U>& o) | 112 template<typename T> template<typename U> inline OwnPtr<T>::OwnPtr(const Pas
sOwnPtr<U>& o, EnsurePtrConvertibleArgDefn(U, T)) |
| 113 : m_ptr(o.leakPtr()) | 113 : m_ptr(o.leakPtr()) |
| 114 { | 114 { |
| 115 } | 115 } |
| 116 | 116 |
| 117 template<typename T> inline void OwnPtr<T>::clear() | 117 template<typename T> inline void OwnPtr<T>::clear() |
| 118 { | 118 { |
| 119 PtrType ptr = m_ptr; | 119 PtrType ptr = m_ptr; |
| 120 m_ptr = 0; | 120 m_ptr = 0; |
| 121 deleteOwnedPtr(ptr); | 121 deleteOwnedPtr(ptr); |
| 122 } | 122 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 template<typename T> inline typename OwnPtr<T>::PtrType getPtr(const OwnPtr<
T>& p) | 213 template<typename T> inline typename OwnPtr<T>::PtrType getPtr(const OwnPtr<
T>& p) |
| 214 { | 214 { |
| 215 return p.get(); | 215 return p.get(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 } // namespace WTF | 218 } // namespace WTF |
| 219 | 219 |
| 220 using WTF::OwnPtr; | 220 using WTF::OwnPtr; |
| 221 | 221 |
| 222 #endif // WTF_OwnPtr_h | 222 #endif // WTF_OwnPtr_h |
| OLD | NEW |