| 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_BINDINGS2_NULLABLE_H_ |
| 6 #define SKY_ENGINE_BINDINGS2_NULLABLE_H_ |
| 7 |
| 8 #include "base/logging.h" |
| 9 |
| 10 namespace blink { |
| 11 |
| 12 template <typename T> |
| 13 class Nullable { |
| 14 public: |
| 15 Nullable() : value_(), is_null_(true) {} |
| 16 Nullable(const T& value) : value_(value), is_null_(false) {} |
| 17 Nullable(const Nullable& other) |
| 18 : value_(other.value_), is_null_(other.is_null_) {} |
| 19 |
| 20 Nullable& operator=(const Nullable& other) = default; |
| 21 |
| 22 void set(const T& value) { |
| 23 value_ = value; |
| 24 is_null_ = false; |
| 25 } |
| 26 |
| 27 const T& get() const { |
| 28 DCHECK(!is_null_); |
| 29 return value_; |
| 30 } |
| 31 T& get() { |
| 32 DCHECK(!is_null_); |
| 33 return value_; |
| 34 } |
| 35 |
| 36 bool is_null() const { return is_null_; } |
| 37 |
| 38 // See comment in RefPtr.h about what UnspecifiedBoolType is. |
| 39 typedef const T* UnspecifiedBoolType; |
| 40 operator UnspecifiedBoolType() const { return is_null_ ? 0 : &value_; } |
| 41 |
| 42 bool operator==(const Nullable& other) const { |
| 43 return (is_null_ && other.is_null_) || |
| 44 (!is_null_ && !other.is_null_ && value_ == other.value_); |
| 45 } |
| 46 |
| 47 private: |
| 48 T value_; |
| 49 bool is_null_; |
| 50 }; |
| 51 |
| 52 } // namespace blink |
| 53 |
| 54 #endif // SKY_ENGINE_BINDINGS2_NULLABLE_H_ |
| OLD | NEW |