Chromium Code Reviews| 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 "wtf/Assertions.h" | 9 #include "wtf/Assertions.h" |
| 9 | 10 |
| 10 namespace WebCore { | 11 namespace WebCore { |
| 11 | 12 |
| 12 template <typename T> | 13 template <typename T> |
| 13 class Nullable { | 14 class Nullable { |
| 15 DISALLOW_ALLOCATION(); | |
| 14 public: | 16 public: |
| 15 Nullable() | 17 Nullable() |
| 16 : m_value() | 18 : m_value() |
| 17 , m_isNull(true) { } | 19 , m_isNull(true) { } |
| 18 | 20 |
| 19 Nullable(const T& value) | 21 Nullable(const T& value) |
| 20 : m_value(value) | 22 : m_value(value) |
| 21 , m_isNull(false) { } | 23 , m_isNull(false) { } |
| 22 | 24 |
| 23 Nullable(const Nullable& other) | 25 Nullable(const Nullable& other) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 34 T get() const { ASSERT(!m_isNull); return m_value; } | 36 T get() const { ASSERT(!m_isNull); return m_value; } |
| 35 bool isNull() const { return m_isNull; } | 37 bool isNull() const { return m_isNull; } |
| 36 | 38 |
| 37 operator bool() const { return !m_isNull && m_value; } | 39 operator bool() const { return !m_isNull && m_value; } |
| 38 | 40 |
| 39 bool operator==(const Nullable& other) const | 41 bool operator==(const Nullable& other) const |
| 40 { | 42 { |
| 41 return (m_isNull && other.m_isNull) || (!m_isNull && !other.m_isNull && m_value == other.m_value); | 43 return (m_isNull && other.m_isNull) || (!m_isNull && !other.m_isNull && m_value == other.m_value); |
| 42 } | 44 } |
| 43 | 45 |
| 46 void trace(Visitor*) | |
| 47 { | |
| 48 // FIXME: candidate for EnableIf<> and NeedsTracing<>, somehow ? | |
|
sof
2014/07/12 07:22:09
When rebasing past r177935's addition of Nullable<
| |
| 49 (void)m_value; | |
| 50 } | |
| 51 | |
| 44 private: | 52 private: |
| 45 T m_value; | 53 T m_value; |
| 46 bool m_isNull; | 54 bool m_isNull; |
| 47 }; | 55 }; |
| 48 | 56 |
| 49 } // namespace WebCore | 57 } // namespace WebCore |
| 50 | 58 |
| 51 #endif // Nullable_h | 59 #endif // Nullable_h |
| OLD | NEW |