| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 Maybe_h | 5 #ifndef Maybe_h |
| 6 #define Maybe_h | 6 #define Maybe_h |
| 7 | 7 |
| 8 #include "platform/inspector_protocol/Platform.h" | 8 #include "platform/inspector_protocol/Platform.h" |
| 9 #include "platform/inspector_protocol/String16.h" | 9 #include "platform/inspector_protocol/String16.h" |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 namespace protocol { | 14 namespace protocol { |
| 15 | 15 |
| 16 class String16; | 16 class String16; |
| 17 | 17 |
| 18 template<typename T> | 18 template<typename T> |
| 19 class Maybe { | 19 class Maybe { |
| 20 public: | 20 public: |
| 21 Maybe() { } | 21 Maybe() : m_value() { } |
| 22 Maybe(std::unique_ptr<T> value) : m_value(std::move(value)) { } | 22 Maybe(std::unique_ptr<T> value) : m_value(std::move(value)) { } |
| 23 void operator=(std::unique_ptr<T> value) { m_value = std::move(value); } | 23 void operator=(std::unique_ptr<T> value) { m_value = std::move(value); } |
| 24 T* fromJust() const { DCHECK(m_value); return m_value.get(); } | 24 T* fromJust() const { DCHECK(m_value); return m_value.get(); } |
| 25 T* fromMaybe(T* defaultValue) const { return m_value ? m_value.get() : defau
ltValue; } | 25 T* fromMaybe(T* defaultValue) const { return m_value ? m_value.get() : defau
ltValue; } |
| 26 bool isJust() const { return !!m_value; } | 26 bool isJust() const { return !!m_value; } |
| 27 std::unique_ptr<T> takeJust() { DCHECK(m_value); return m_value.release(); } | 27 std::unique_ptr<T> takeJust() { DCHECK(m_value); return m_value.release(); } |
| 28 private: | 28 private: |
| 29 std::unique_ptr<T> m_value; | 29 std::unique_ptr<T> m_value; |
| 30 }; | 30 }; |
| 31 | 31 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 public: | 82 public: |
| 83 Maybe() { } | 83 Maybe() { } |
| 84 Maybe(const String16& value) : MaybeBase(value) { } | 84 Maybe(const String16& value) : MaybeBase(value) { } |
| 85 using MaybeBase::operator=; | 85 using MaybeBase::operator=; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 } // namespace platform | 88 } // namespace platform |
| 89 } // namespace blink | 89 } // namespace blink |
| 90 | 90 |
| 91 #endif // !defined(Maybe_h) | 91 #endif // !defined(Maybe_h) |
| OLD | NEW |