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

Unified Diff: Source/bindings/v8/Optional.h

Issue 337343002: IDL: make optional arguments (without default) explicit sometimes Base URL: https://chromium.googlesource.com/chromium/blink.git@idl-default-arguments-next
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: Source/bindings/v8/Optional.h
diff --git a/Source/bindings/v8/Optional.h b/Source/bindings/v8/Optional.h
new file mode 100644
index 0000000000000000000000000000000000000000..4a1beee5fdeafdda9d79f84675be9e38cac2fc40
--- /dev/null
+++ b/Source/bindings/v8/Optional.h
@@ -0,0 +1,58 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef Optional_h
+#define Optional_h
+
+#include "wtf/Assertions.h"
+
+namespace WebCore {
+
+template <typename T>
+class Optional {
+public:
+ Optional(const T& value, bool isMissing)
+ : m_value(value)
+ , m_isMissing(isMissing) { }
+
+ Optional(const Optional& other)
+ : m_value(other.m_value)
+ , m_isMissing(other.m_isMissing) { }
+
+ template <typename U>
+ Optional(const Optional<U>& other)
Jens Widell 2014/06/17 09:53:37 This operator might be useful (or not work at all)
+ : m_value(other.m_value)
+ , m_isMissing(other.m_isMissing) { }
+
+ Optional& operator=(const Optional& other)
+ {
+ m_value = other.m_value;
+ m_isMissing = other.m_isMissing;
+ return *this;
+ }
+
+ T get() const { ASSERT(!m_isMissing); return m_value; }
+ bool isMissing() const { return m_isMissing; }
+
+ operator bool() const { return !m_isMissing && m_value; }
+
+ bool operator==(const Optional& other) const
+ {
+ return (m_isMissing && other.m_isMissing) || (!m_isMissing && !other.m_isMissing && m_value == other.m_value);
+ }
+
+private:
+ T m_value;
+ bool m_isMissing;
+};
+
+template <typename T>
+Optional<T> makeOptional(T value, bool isMissing)
+{
+ return Optional<T>(value, isMissing);
+}
+
+} // namespace WebCore
+
+#endif // Optional_h

Powered by Google App Engine
This is Rietveld 408576698