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

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/Maybe.h

Issue 2098523002: Fix some issues found by coverity scans on Node.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/inspector_protocol/String16STL.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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
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)
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/inspector_protocol/String16STL.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698