| 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; | |
| 17 | |
| 18 template<typename T> | 16 template<typename T> |
| 19 class Maybe { | 17 class Maybe { |
| 20 public: | 18 public: |
| 21 Maybe() : m_value() { } | 19 Maybe() : m_value() { } |
| 22 Maybe(std::unique_ptr<T> value) : m_value(std::move(value)) { } | 20 Maybe(std::unique_ptr<T> value) : m_value(std::move(value)) { } |
| 23 void operator=(std::unique_ptr<T> value) { m_value = std::move(value); } | 21 void operator=(std::unique_ptr<T> value) { m_value = std::move(value); } |
| 24 T* fromJust() const { DCHECK(m_value); return m_value.get(); } | 22 T* fromJust() const { DCHECK(m_value); return m_value.get(); } |
| 25 T* fromMaybe(T* defaultValue) const { return m_value ? m_value.get() : defau
ltValue; } | 23 T* fromMaybe(T* defaultValue) const { return m_value ? m_value.get() : defau
ltValue; } |
| 26 bool isJust() const { return !!m_value; } | 24 bool isJust() const { return !!m_value; } |
| 27 std::unique_ptr<T> takeJust() { DCHECK(m_value); return m_value.release(); } | 25 std::unique_ptr<T> takeJust() { DCHECK(m_value); return m_value.release(); } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 61 |
| 64 template<> | 62 template<> |
| 65 class Maybe<double> : public MaybeBase<double> { | 63 class Maybe<double> : public MaybeBase<double> { |
| 66 public: | 64 public: |
| 67 Maybe() { } | 65 Maybe() { } |
| 68 Maybe(double value) : MaybeBase(value) { } | 66 Maybe(double value) : MaybeBase(value) { } |
| 69 using MaybeBase::operator=; | 67 using MaybeBase::operator=; |
| 70 }; | 68 }; |
| 71 | 69 |
| 72 template<> | 70 template<> |
| 73 class Maybe<String> : public MaybeBase<String> { | 71 class Maybe<InspectorProtocolConvenienceStringType> : public MaybeBase<Inspector
ProtocolConvenienceStringType> { |
| 74 public: | 72 public: |
| 75 Maybe() { } | 73 Maybe() { } |
| 76 Maybe(const String& value) : MaybeBase(value) { } | 74 Maybe(const InspectorProtocolConvenienceStringType& value) : MaybeBase(value
) { } |
| 77 using MaybeBase::operator=; | 75 using MaybeBase::operator=; |
| 78 }; | 76 }; |
| 79 | 77 |
| 80 template<> | 78 template<> |
| 81 class Maybe<String16> : public MaybeBase<String16> { | 79 class Maybe<String16> : public MaybeBase<String16> { |
| 82 public: | 80 public: |
| 83 Maybe() { } | 81 Maybe() { } |
| 84 Maybe(const String16& value) : MaybeBase(value) { } | 82 Maybe(const String16& value) : MaybeBase(value) { } |
| 85 using MaybeBase::operator=; | 83 using MaybeBase::operator=; |
| 86 }; | 84 }; |
| 87 | 85 |
| 88 } // namespace platform | 86 } // namespace platform |
| 89 } // namespace blink | 87 } // namespace blink |
| 90 | 88 |
| 91 #endif // !defined(Maybe_h) | 89 #endif // !defined(Maybe_h) |
| OLD | NEW |