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

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

Issue 2001893002: DevTools: expose raw pointers in protocol collections, s/ASSERT/DCHECK/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
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/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 9
10 namespace blink { 10 namespace blink {
11 namespace protocol { 11 namespace protocol {
12 12
13 class String16; 13 class String16;
14 14
15 template<typename T> 15 template<typename T>
16 class Maybe { 16 class Maybe {
17 public: 17 public:
18 Maybe() { } 18 Maybe() { }
19 Maybe(PassOwnPtr<T> value) : m_value(std::move(value)) { } 19 Maybe(PassOwnPtr<T> value) : m_value(std::move(value)) { }
20 void operator=(PassOwnPtr<T> value) { m_value = std::move(value); } 20 void operator=(PassOwnPtr<T> value) { m_value = std::move(value); }
21 T* fromJust() const { ASSERT(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 PassOwnPtr<T> takeJust() { ASSERT(m_value); return m_value.release(); } 24 PassOwnPtr<T> takeJust() { DCHECK(m_value); return m_value.release(); }
25 private: 25 private:
26 OwnPtr<T> m_value; 26 OwnPtr<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 void operator=(T value) { m_value = value; m_isJust = true; } 34 void operator=(T value) { m_value = value; m_isJust = true; }
35 T fromJust() const { ASSERT(m_isJust); return m_value; } 35 T fromJust() const { DCHECK(m_isJust); return m_value; }
36 T fromMaybe(const T& defaultValue) const { return m_isJust ? m_value : defau ltValue; } 36 T fromMaybe(const T& defaultValue) const { return m_isJust ? m_value : defau ltValue; }
37 bool isJust() const { return m_isJust; } 37 bool isJust() const { return m_isJust; }
38 T takeJust() { ASSERT(m_isJust); return m_value; } 38 T takeJust() { DCHECK(m_isJust); return m_value; }
39 39
40 protected: 40 protected:
41 bool m_isJust; 41 bool m_isJust;
42 T m_value; 42 T m_value;
43 }; 43 };
44 44
45 template<> 45 template<>
46 class Maybe<bool> : public MaybeBase<bool> { 46 class Maybe<bool> : public MaybeBase<bool> {
47 public: 47 public:
48 Maybe() { } 48 Maybe() { }
(...skipping 30 matching lines...) Expand all
79 public: 79 public:
80 Maybe() { } 80 Maybe() { }
81 Maybe(const String16& value) : MaybeBase(value) { } 81 Maybe(const String16& value) : MaybeBase(value) { }
82 using MaybeBase::operator=; 82 using MaybeBase::operator=;
83 }; 83 };
84 84
85 } // namespace platform 85 } // namespace platform
86 } // namespace blink 86 } // namespace blink
87 87
88 #endif // !defined(Maybe_h) 88 #endif // !defined(Maybe_h)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698