| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef Nullable_h | 5 #ifndef Nullable_h |
| 6 #define Nullable_h | 6 #define Nullable_h |
| 7 | 7 |
| 8 #include "platform/heap/Handle.h" | 8 #include "platform/heap/Handle.h" |
| 9 #include "wtf/Assertions.h" | 9 #include "wtf/Assertions.h" |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 void set(std::nullptr_t) | 58 void set(std::nullptr_t) |
| 59 { | 59 { |
| 60 m_value = T(); | 60 m_value = T(); |
| 61 m_isNull = true; | 61 m_isNull = true; |
| 62 } | 62 } |
| 63 | 63 |
| 64 const T& get() const { ASSERT(!m_isNull); return m_value; } | 64 const T& get() const { ASSERT(!m_isNull); return m_value; } |
| 65 T& get() { ASSERT(!m_isNull); return m_value; } | 65 T& get() { ASSERT(!m_isNull); return m_value; } |
| 66 bool isNull() const { return m_isNull; } | 66 bool isNull() const { return m_isNull; } |
| 67 | 67 |
| 68 // See comment in RefPtr.h about what UnspecifiedBoolType is. | 68 explicit operator bool() const { return !m_isNull; } |
| 69 typedef const T* UnspecifiedBoolType; | |
| 70 operator UnspecifiedBoolType() const { return m_isNull ? 0 : &m_value; } | |
| 71 | 69 |
| 72 bool operator==(const Nullable& other) const | 70 bool operator==(const Nullable& other) const |
| 73 { | 71 { |
| 74 return (m_isNull && other.m_isNull) || (!m_isNull && !other.m_isNull &&
m_value == other.m_value); | 72 return (m_isNull && other.m_isNull) || (!m_isNull && !other.m_isNull &&
m_value == other.m_value); |
| 75 } | 73 } |
| 76 | 74 |
| 77 DEFINE_INLINE_TRACE() | 75 DEFINE_INLINE_TRACE() |
| 78 { | 76 { |
| 79 TraceIfNeeded<T>::trace(visitor, m_value); | 77 TraceIfNeeded<T>::trace(visitor, m_value); |
| 80 } | 78 } |
| 81 | 79 |
| 82 private: | 80 private: |
| 83 T m_value; | 81 T m_value; |
| 84 bool m_isNull; | 82 bool m_isNull; |
| 85 }; | 83 }; |
| 86 | 84 |
| 87 } // namespace blink | 85 } // namespace blink |
| 88 | 86 |
| 89 #endif // Nullable_h | 87 #endif // Nullable_h |
| OLD | NEW |