OLD | NEW |
(Empty) | |
| 1 #ifndef NonNullPtr_h |
| 2 #define NonNullPtr_h |
| 3 |
| 4 #include "wtf/Assertions.h" |
| 5 |
| 6 namespace WTF { |
| 7 |
| 8 template<typename T> class NonNullPtr { |
| 9 public: |
| 10 NonNullPtr(T* ptr) : m_ptr(ptr) { ASSERT(m_ptr); } |
| 11 NonNullPtr(const NonNullPtr& other) : m_ptr(other.m_ptr) { ASSERT(m_ptr); } |
| 12 // For non-const -> const conversion, derived class -> base class conversion
. |
| 13 template<typename U> NonNullPtr(const NonNullPtr<U>& other) : m_ptr(other.ge
t()) { ASSERT(m_ptr); } |
| 14 T* operator->() const { return m_ptr; } |
| 15 T* get() const { return m_ptr; } |
| 16 NonNullPtr& operator=(T* ptr) |
| 17 { |
| 18 ASSERT(ptr); |
| 19 m_ptr = ptr; |
| 20 } |
| 21 |
| 22 private: |
| 23 T* m_ptr; |
| 24 }; |
| 25 |
| 26 |
| 27 template<typename T, typename U> inline bool operator==(const NonNullPtr<T>& a,
const NonNullPtr<U>& b) { return a.get() == b.get(); } |
| 28 template<typename T, typename U> inline bool operator!=(const NonNullPtr<T>& a,
const NonNullPtr<U>& b) { return a.get() != b.get(); } |
| 29 template<typename T, typename U> inline bool operator==(const NonNullPtr<T>& a,
U* b) { return a.get() == b; } |
| 30 template<typename T, typename U> inline bool operator!=(const NonNullPtr<T>& a,
U* b) { return a.get() != b; } |
| 31 template<typename T, typename U> inline bool operator==(T* a, const NonNullPtr<U
>& b) { return a == b.get(); } |
| 32 template<typename T, typename U> inline bool operator!=(T* a, const NonNullPtr<U
>& b) { return a != b.get(); } |
| 33 |
| 34 |
| 35 } |
| 36 |
| 37 using WTF::NonNullPtr; |
| 38 |
| 39 #endif |
OLD | NEW |