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/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
9 #include "wtf/text/WTFString.h" | |
10 | 9 |
11 namespace blink { | 10 namespace blink { |
12 namespace protocol { | 11 namespace protocol { |
13 | 12 |
| 13 class String16; |
| 14 |
14 template<typename T> | 15 template<typename T> |
15 class Maybe { | 16 class Maybe { |
16 public: | 17 public: |
17 Maybe() { } | 18 Maybe() { } |
18 Maybe(PassOwnPtr<T> value) : m_value(value) { } | 19 Maybe(PassOwnPtr<T> value) : m_value(value) { } |
19 void operator=(PassOwnPtr<T> value) { m_value = value; } | 20 void operator=(PassOwnPtr<T> value) { m_value = value; } |
20 T* fromJust() const { ASSERT(m_value); return m_value.get(); } | 21 T* fromJust() const { ASSERT(m_value); return m_value.get(); } |
21 T* fromMaybe(T* defaultValue) const { return m_value ? m_value.get() : defau
ltValue; } | 22 T* fromMaybe(T* defaultValue) const { return m_value ? m_value.get() : defau
ltValue; } |
22 bool isJust() const { return !!m_value; } | 23 bool isJust() const { return !!m_value; } |
23 PassOwnPtr<T> takeJust() { ASSERT(m_value); return m_value.release(); } | 24 PassOwnPtr<T> takeJust() { ASSERT(m_value); return m_value.release(); } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 Maybe() { } | 64 Maybe() { } |
64 Maybe(double value) : MaybeBase(value) { } | 65 Maybe(double value) : MaybeBase(value) { } |
65 using MaybeBase::operator=; | 66 using MaybeBase::operator=; |
66 }; | 67 }; |
67 | 68 |
68 template<> | 69 template<> |
69 class Maybe<String> : public MaybeBase<String> { | 70 class Maybe<String> : public MaybeBase<String> { |
70 public: | 71 public: |
71 Maybe() { } | 72 Maybe() { } |
72 Maybe(const String& value) : MaybeBase(value) { } | 73 Maybe(const String& value) : MaybeBase(value) { } |
73 Maybe(const AtomicString& value) : MaybeBase(value) { } | |
74 using MaybeBase::operator=; | 74 using MaybeBase::operator=; |
75 }; | 75 }; |
76 | 76 |
| 77 template<> |
| 78 class Maybe<String16> : public MaybeBase<String16> { |
| 79 public: |
| 80 Maybe() { } |
| 81 Maybe(const String16& value) : MaybeBase(value) { } |
| 82 using MaybeBase::operator=; |
| 83 }; |
| 84 |
77 } // namespace platform | 85 } // namespace platform |
78 } // namespace blink | 86 } // namespace blink |
79 | 87 |
80 #endif // !defined(Maybe_h) | 88 #endif // !defined(Maybe_h) |
OLD | NEW |