| Index: Source/wtf/NonNullPtr.h
|
| diff --git a/Source/wtf/NonNullPtr.h b/Source/wtf/NonNullPtr.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e42a425065fa1bad8b0765fb1955ac9b1cb09209
|
| --- /dev/null
|
| +++ b/Source/wtf/NonNullPtr.h
|
| @@ -0,0 +1,39 @@
|
| +#ifndef NonNullPtr_h
|
| +#define NonNullPtr_h
|
| +
|
| +#include "wtf/Assertions.h"
|
| +
|
| +namespace WTF {
|
| +
|
| +template<typename T> class NonNullPtr {
|
| +public:
|
| + NonNullPtr(T* ptr) : m_ptr(ptr) { ASSERT(m_ptr); }
|
| + NonNullPtr(const NonNullPtr& other) : m_ptr(other.m_ptr) { ASSERT(m_ptr); }
|
| + // For non-const -> const conversion, derived class -> base class conversion.
|
| + template<typename U> NonNullPtr(const NonNullPtr<U>& other) : m_ptr(other.get()) { ASSERT(m_ptr); }
|
| + T* operator->() const { return m_ptr; }
|
| + T* get() const { return m_ptr; }
|
| + NonNullPtr& operator=(T* ptr)
|
| + {
|
| + ASSERT(ptr);
|
| + m_ptr = ptr;
|
| + }
|
| +
|
| +private:
|
| + T* m_ptr;
|
| +};
|
| +
|
| +
|
| +template<typename T, typename U> inline bool operator==(const NonNullPtr<T>& a, const NonNullPtr<U>& b) { return a.get() == b.get(); }
|
| +template<typename T, typename U> inline bool operator!=(const NonNullPtr<T>& a, const NonNullPtr<U>& b) { return a.get() != b.get(); }
|
| +template<typename T, typename U> inline bool operator==(const NonNullPtr<T>& a, U* b) { return a.get() == b; }
|
| +template<typename T, typename U> inline bool operator!=(const NonNullPtr<T>& a, U* b) { return a.get() != b; }
|
| +template<typename T, typename U> inline bool operator==(T* a, const NonNullPtr<U>& b) { return a == b.get(); }
|
| +template<typename T, typename U> inline bool operator!=(T* a, const NonNullPtr<U>& b) { return a != b.get(); }
|
| +
|
| +
|
| +}
|
| +
|
| +using WTF::NonNullPtr;
|
| +
|
| +#endif
|
|
|