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" |
| 10 #include "wtf/TypeTraits.h" |
9 | 11 |
10 namespace WebCore { | 12 namespace WebCore { |
11 | 13 |
12 template <typename T> | 14 template <typename T> |
13 class Nullable { | 15 class Nullable { |
| 16 DISALLOW_ALLOCATION(); |
14 public: | 17 public: |
15 Nullable() | 18 Nullable() |
16 : m_value() | 19 : m_value() |
17 , m_isNull(true) { } | 20 , m_isNull(true) { } |
18 | 21 |
19 Nullable(const T& value) | 22 Nullable(const T& value) |
20 : m_value(value) | 23 : m_value(value) |
21 , m_isNull(false) { } | 24 , m_isNull(false) { } |
22 | 25 |
23 Nullable(const Nullable& other) | 26 Nullable(const Nullable& other) |
(...skipping 10 matching lines...) Expand all Loading... |
34 T get() const { ASSERT(!m_isNull); return m_value; } | 37 T get() const { ASSERT(!m_isNull); return m_value; } |
35 bool isNull() const { return m_isNull; } | 38 bool isNull() const { return m_isNull; } |
36 | 39 |
37 operator bool() const { return !m_isNull && m_value; } | 40 operator bool() const { return !m_isNull && m_value; } |
38 | 41 |
39 bool operator==(const Nullable& other) const | 42 bool operator==(const Nullable& other) const |
40 { | 43 { |
41 return (m_isNull && other.m_isNull) || (!m_isNull && !other.m_isNull &&
m_value == other.m_value); | 44 return (m_isNull && other.m_isNull) || (!m_isNull && !other.m_isNull &&
m_value == other.m_value); |
42 } | 45 } |
43 | 46 |
| 47 template<typename U = T> |
| 48 typename WTF::EnableIf<WTF::NeedsTracing<U>::value, void>::Type trace(Visito
r* visitor) |
| 49 { |
| 50 visitor->trace(m_value); |
| 51 } |
| 52 |
44 private: | 53 private: |
| 54 // FIXME: Oilpan: the static analyser isn't (yet) able to |
| 55 // spot the above trace() function template. When Nullable<> |
| 56 // instantiations over traceable values are then processed, |
| 57 // it'll report an error. A false negative; the trace() method |
| 58 // is instantiated. |
| 59 GC_PLUGIN_IGNORE("393465") |
45 T m_value; | 60 T m_value; |
46 bool m_isNull; | 61 bool m_isNull; |
47 }; | 62 }; |
48 | 63 |
49 } // namespace WebCore | 64 } // namespace WebCore |
50 | 65 |
51 #endif // Nullable_h | 66 #endif // Nullable_h |
OLD | NEW |