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 blink { | 11 namespace blink { |
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* visitor) |
| 47 { |
| 48 TraceIfNeeded<T>::trace(visitor, &m_value); |
| 49 } |
| 50 |
44 private: | 51 private: |
45 T m_value; | 52 T m_value; |
46 bool m_isNull; | 53 bool m_isNull; |
47 }; | 54 }; |
48 | 55 |
49 } // namespace blink | 56 } // namespace blink |
50 | 57 |
51 #endif // Nullable_h | 58 #endif // Nullable_h |
OLD | NEW |