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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 | 130 |
| 131 template<typename T> inline typename OwnPtr<T>::PtrType OwnPtr<T>::leakPtr() | 131 template<typename T> inline typename OwnPtr<T>::PtrType OwnPtr<T>::leakPtr() |
| 132 { | 132 { |
| 133 PtrType ptr = m_ptr; | 133 PtrType ptr = m_ptr; |
| 134 m_ptr = 0; | 134 m_ptr = 0; |
| 135 return ptr; | 135 return ptr; |
| 136 } | 136 } |
| 137 | 137 |
| 138 template<typename T> inline OwnPtr<T>& OwnPtr<T>::operator=(const PassOwnPtr <T>& o) | 138 template<typename T> inline OwnPtr<T>& OwnPtr<T>::operator=(const PassOwnPtr <T>& o) |
| 139 { | 139 { |
| 140 PtrType ptr = m_ptr; | 140 ASSERT(!o || o != m_ptr); |
| 141 m_ptr = o.leakPtr(); | 141 OwnPtr ptr = o; |
| 142 ASSERT(!ptr || m_ptr != ptr); | 142 swap(ptr); |
| 143 deleteOwnedPtr(ptr); | |
| 144 return *this; | 143 return *this; |
| 145 } | 144 } |
| 146 | 145 |
| 147 template<typename T> template<typename U> inline OwnPtr<T>& OwnPtr<T>::opera tor=(const PassOwnPtr<U>& o) | 146 template<typename T> template<typename U> inline OwnPtr<T>& OwnPtr<T>::opera tor=(const PassOwnPtr<U>& o) |
| 148 { | 147 { |
| 149 PtrType ptr = m_ptr; | 148 ASSERT(!o || o != m_ptr); |
| 150 m_ptr = o.leakPtr(); | 149 OwnPtr ptr = o; |
| 151 ASSERT(!ptr || m_ptr != ptr); | 150 swap(ptr); |
| 152 deleteOwnedPtr(ptr); | |
| 153 return *this; | 151 return *this; |
| 154 } | 152 } |
| 155 | 153 |
| 156 #if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES) | 154 #if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES) |
| 157 template<typename T> inline OwnPtr<T>::OwnPtr(OwnPtr<T>&& o) | 155 template<typename T> inline OwnPtr<T>::OwnPtr(OwnPtr<T>&& o) |
| 158 : m_ptr(o.leakPtr()) | 156 : m_ptr(o.leakPtr()) |
| 159 { | 157 { |
| 160 } | 158 } |
| 161 | 159 |
| 162 template<typename T> template<typename U> inline OwnPtr<T>::OwnPtr(OwnPtr<U> && o) | 160 template<typename T> template<typename U> inline OwnPtr<T>::OwnPtr(OwnPtr<U> && o) |
| 163 : m_ptr(o.leakPtr()) | 161 : m_ptr(o.leakPtr()) |
| 164 { | 162 { |
| 165 } | 163 } |
| 166 | 164 |
| 167 template<typename T> inline OwnPtr<T>& OwnPtr<T>::operator=(OwnPtr<T>&& o) | 165 template<typename T> inline OwnPtr<T>& OwnPtr<T>::operator=(OwnPtr<T>&& o) |
| 168 { | 166 { |
| 169 PtrType ptr = m_ptr; | 167 ASSERT(!o || o != m_ptr); |
| 170 m_ptr = o.leakPtr(); | 168 OwnPtr ptr = std::move(o); |
|
Nico
2013/09/11 18:00:36
As mentioned several times, we can't use C++11 lib
| |
| 171 ASSERT(!ptr || m_ptr != ptr); | 169 swap(ptr); |
| 172 deleteOwnedPtr(ptr); | |
| 173 | |
| 174 return *this; | 170 return *this; |
| 175 } | 171 } |
| 176 | 172 |
| 177 template<typename T> template<typename U> inline OwnPtr<T>& OwnPtr<T>::opera tor=(OwnPtr<U>&& o) | 173 template<typename T> template<typename U> inline OwnPtr<T>& OwnPtr<T>::opera tor=(OwnPtr<U>&& o) |
| 178 { | 174 { |
| 179 PtrType ptr = m_ptr; | 175 ASSERT(!o || o != m_ptr); |
| 180 m_ptr = o.leakPtr(); | 176 OwnPtr ptr = std::move(o); |
| 181 ASSERT(!ptr || m_ptr != ptr); | 177 swap(ptr); |
| 182 deleteOwnedPtr(ptr); | |
| 183 | |
| 184 return *this; | 178 return *this; |
| 185 } | 179 } |
| 186 #endif | 180 #endif |
| 187 | 181 |
| 188 template<typename T> inline void swap(OwnPtr<T>& a, OwnPtr<T>& b) | 182 template<typename T> inline void swap(OwnPtr<T>& a, OwnPtr<T>& b) |
| 189 { | 183 { |
| 190 a.swap(b); | 184 a.swap(b); |
| 191 } | 185 } |
| 192 | 186 |
| 193 template<typename T, typename U> inline bool operator==(const OwnPtr<T>& a, U* b) | 187 template<typename T, typename U> inline bool operator==(const OwnPtr<T>& a, U* b) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 213 template<typename T> inline typename OwnPtr<T>::PtrType getPtr(const OwnPtr< T>& p) | 207 template<typename T> inline typename OwnPtr<T>::PtrType getPtr(const OwnPtr< T>& p) |
| 214 { | 208 { |
| 215 return p.get(); | 209 return p.get(); |
| 216 } | 210 } |
| 217 | 211 |
| 218 } // namespace WTF | 212 } // namespace WTF |
| 219 | 213 |
| 220 using WTF::OwnPtr; | 214 using WTF::OwnPtr; |
| 221 | 215 |
| 222 #endif // WTF_OwnPtr_h | 216 #endif // WTF_OwnPtr_h |
| OLD | NEW |