| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009, 2010 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #ifndef WTF_PassOwnPtr_h | 26 #ifndef WTF_PassOwnPtr_h |
| 27 #define WTF_PassOwnPtr_h | 27 #define WTF_PassOwnPtr_h |
| 28 | 28 |
| 29 #include "wtf/Assertions.h" | 29 #include "wtf/Assertions.h" |
| 30 #include "wtf/NullPtr.h" | 30 #include "wtf/NullPtr.h" |
| 31 #include "wtf/OwnPtrCommon.h" | 31 #include "wtf/OwnPtrCommon.h" |
| 32 #include "wtf/TypeTraits.h" | 32 #include "wtf/TypeTraits.h" |
| 33 | 33 |
| 34 namespace WTF { | 34 namespace WTF { |
| 35 | 35 |
| 36 // Unlike most of our smart pointers, PassOwnPtr can take either the pointer
type or the pointed-to type. | |
| 37 | |
| 38 template<typename T> class OwnPtr; | 36 template<typename T> class OwnPtr; |
| 39 template<typename T> class PassOwnPtr; | 37 template<typename T> class PassOwnPtr; |
| 40 template<typename T> PassOwnPtr<T> adoptPtr(T*); | 38 template<typename T> PassOwnPtr<T> adoptPtr(T*); |
| 41 | 39 |
| 42 template<typename T> class PassOwnPtr { | 40 template<typename T> class PassOwnPtr { |
| 43 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(PassOwnPtr); | 41 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(PassOwnPtr); |
| 44 public: | 42 public: |
| 45 typedef typename RemovePointer<T>::Type ValueType; | 43 typedef T ValueType; |
| 46 typedef ValueType* PtrType; | 44 typedef ValueType* PtrType; |
| 47 | 45 |
| 48 PassOwnPtr() : m_ptr(0) { } | 46 PassOwnPtr() : m_ptr(0) { } |
| 49 PassOwnPtr(std::nullptr_t) : m_ptr(0) { } | 47 PassOwnPtr(std::nullptr_t) : m_ptr(0) { } |
| 50 | 48 |
| 51 // It somewhat breaks the type system to allow transfer of ownership out
of | 49 // It somewhat breaks the type system to allow transfer of ownership out
of |
| 52 // a const PassOwnPtr. However, it makes it much easier to work with Pas
sOwnPtr | 50 // a const PassOwnPtr. However, it makes it much easier to work with Pas
sOwnPtr |
| 53 // temporaries, and we don't have a need to use real const PassOwnPtrs a
nyway. | 51 // temporaries, and we don't have a need to use real const PassOwnPtrs a
nyway. |
| 54 PassOwnPtr(const PassOwnPtr& o) : m_ptr(o.leakPtr()) { } | 52 PassOwnPtr(const PassOwnPtr& o) : m_ptr(o.leakPtr()) { } |
| 55 template<typename U> PassOwnPtr(const PassOwnPtr<U>& o) : m_ptr(o.leakPt
r()) { } | 53 template<typename U> PassOwnPtr(const PassOwnPtr<U>& o) : m_ptr(o.leakPt
r()) { } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 } | 162 } |
| 165 | 163 |
| 166 } // namespace WTF | 164 } // namespace WTF |
| 167 | 165 |
| 168 using WTF::PassOwnPtr; | 166 using WTF::PassOwnPtr; |
| 169 using WTF::adoptPtr; | 167 using WTF::adoptPtr; |
| 170 using WTF::const_pointer_cast; | 168 using WTF::const_pointer_cast; |
| 171 using WTF::static_pointer_cast; | 169 using WTF::static_pointer_cast; |
| 172 | 170 |
| 173 #endif // WTF_PassOwnPtr_h | 171 #endif // WTF_PassOwnPtr_h |
| OLD | NEW |