| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SKY_ENGINE_BINDINGS_CORE_V8_NULLABLE_H_ | |
| 6 #define SKY_ENGINE_BINDINGS_CORE_V8_NULLABLE_H_ | |
| 7 | |
| 8 #include "sky/engine/platform/heap/Handle.h" | |
| 9 #include "sky/engine/wtf/Assertions.h" | |
| 10 | |
| 11 namespace blink { | |
| 12 | |
| 13 template <typename T> | |
| 14 class Nullable { | |
| 15 DISALLOW_ALLOCATION(); | |
| 16 public: | |
| 17 Nullable() | |
| 18 : m_value() | |
| 19 , m_isNull(true) { } | |
| 20 | |
| 21 Nullable(const T& value) | |
| 22 : m_value(value) | |
| 23 , m_isNull(false) { } | |
| 24 | |
| 25 Nullable(const Nullable& other) | |
| 26 : m_value(other.m_value) | |
| 27 , m_isNull(other.m_isNull) { } | |
| 28 | |
| 29 Nullable& operator=(const Nullable& other) | |
| 30 { | |
| 31 m_value = other.m_value; | |
| 32 m_isNull = other.m_isNull; | |
| 33 return *this; | |
| 34 } | |
| 35 | |
| 36 void set(const T& value) | |
| 37 { | |
| 38 m_value = value; | |
| 39 m_isNull = false; | |
| 40 } | |
| 41 const T& get() const { ASSERT(!m_isNull); return m_value; } | |
| 42 T& get() { ASSERT(!m_isNull); return m_value; } | |
| 43 bool isNull() const { return m_isNull; } | |
| 44 | |
| 45 // See comment in RefPtr.h about what UnspecifiedBoolType is. | |
| 46 typedef const T* UnspecifiedBoolType; | |
| 47 operator UnspecifiedBoolType() const { return m_isNull ? 0 : &m_value; } | |
| 48 | |
| 49 bool operator==(const Nullable& other) const | |
| 50 { | |
| 51 return (m_isNull && other.m_isNull) || (!m_isNull && !other.m_isNull &&
m_value == other.m_value); | |
| 52 } | |
| 53 | |
| 54 private: | |
| 55 T m_value; | |
| 56 bool m_isNull; | |
| 57 }; | |
| 58 | |
| 59 } // namespace blink | |
| 60 | |
| 61 #endif // SKY_ENGINE_BINDINGS_CORE_V8_NULLABLE_H_ | |
| OLD | NEW |