Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(634)

Side by Side Diff: third_party/inspector_protocol/lib/Maybe_h.template

Issue 2523583005: Roll third_party/inspector_protocol to 4ad35c45aca9834b67ec2cb152c816ea1b7ceb48 (Closed)
Patch Set: added default implementation Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 {{"_".join(config.protocol.namespace)}}_Maybe_h 5 #ifndef {{"_".join(config.protocol.namespace)}}_Maybe_h
6 #define {{"_".join(config.protocol.namespace)}}_Maybe_h 6 #define {{"_".join(config.protocol.namespace)}}_Maybe_h
7 7
8 //#include "Forward.h" 8 //#include "Forward.h"
9 9
10 {% for namespace in config.protocol.namespace %} 10 {% for namespace in config.protocol.namespace %}
11 namespace {{namespace}} { 11 namespace {{namespace}} {
12 {% endfor %} 12 {% endfor %}
13 13
14 template<typename T> 14 template<typename T>
15 class Maybe { 15 class Maybe {
16 public: 16 public:
17 Maybe() : m_value() { } 17 Maybe() : m_value() { }
18 Maybe(std::unique_ptr<T> value) : m_value(std::move(value)) { } 18 Maybe(std::unique_ptr<T> value) : m_value(std::move(value)) { }
19 Maybe(Maybe&& other) : m_value(std::move(other.m_value)) { } 19 Maybe(Maybe&& other) : m_value(std::move(other.m_value)) { }
20 void operator=(std::unique_ptr<T> value) { m_value = std::move(value); } 20 void operator=(std::unique_ptr<T> value) { m_value = std::move(value); }
21 T* fromJust() const { DCHECK(m_value); return m_value.get(); } 21 T* fromJust() const { DCHECK(m_value); return m_value.get(); }
22 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; }
23 bool isJust() const { return !!m_value; } 23 bool isJust() const { return !!m_value; }
24 std::unique_ptr<T> takeJust() { DCHECK(m_value); return m_value.release(); } 24 std::unique_ptr<T> takeJust() { DCHECK(m_value); return std::move(m_value); }
25 private: 25 private:
26 std::unique_ptr<T> m_value; 26 std::unique_ptr<T> m_value;
27 }; 27 };
28 28
29 template<typename T> 29 template<typename T>
30 class MaybeBase { 30 class MaybeBase {
31 public: 31 public:
32 MaybeBase() : m_isJust(false) { } 32 MaybeBase() : m_isJust(false) { }
33 MaybeBase(T value) : m_isJust(true), m_value(value) { } 33 MaybeBase(T value) : m_isJust(true), m_value(value) { }
34 MaybeBase(MaybeBase&& other) : m_isJust(other.m_isJust), m_value(std::move(o ther.m_value)) { } 34 MaybeBase(MaybeBase&& other) : m_isJust(other.m_isJust), m_value(std::move(o ther.m_value)) { }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 Maybe(const String& value) : MaybeBase(value) { } 77 Maybe(const String& value) : MaybeBase(value) { }
78 Maybe(Maybe&& other) : MaybeBase(std::move(other)) { } 78 Maybe(Maybe&& other) : MaybeBase(std::move(other)) { }
79 using MaybeBase::operator=; 79 using MaybeBase::operator=;
80 }; 80 };
81 81
82 {% for namespace in config.protocol.namespace %} 82 {% for namespace in config.protocol.namespace %}
83 } // namespace {{namespace}} 83 } // namespace {{namespace}}
84 {% endfor %} 84 {% endfor %}
85 85
86 #endif // !defined({{"_".join(config.protocol.namespace)}}_Maybe_h) 86 #endif // !defined({{"_".join(config.protocol.namespace)}}_Maybe_h)
OLDNEW
« no previous file with comments | « third_party/inspector_protocol/lib/FrontendChannel_h.template ('k') | third_party/inspector_protocol/lib/Object_cpp.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698