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

Unified Diff: mojo/public/cpp/bindings/lib/wtf_clone_equals_util.h

Issue 2136733002: Mojo C++ bindings: add a new mode to generator to use native STL/WTF types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@67_new
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/template_util.h ('k') | mojo/public/cpp/bindings/lib/wtf_serialization.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/wtf_clone_equals_util.h
diff --git a/mojo/public/cpp/bindings/lib/wtf_clone_equals_util.h b/mojo/public/cpp/bindings/lib/wtf_clone_equals_util.h
new file mode 100644
index 0000000000000000000000000000000000000000..edbf27b7d3059e0a1f1429af64a2a62f68688ae3
--- /dev/null
+++ b/mojo/public/cpp/bindings/lib/wtf_clone_equals_util.h
@@ -0,0 +1,76 @@
+// Copyright 2016 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 MOJO_PUBLIC_CPP_BINDINGS_LIB_WTF_CLONE_EQUALS_UTIL_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_LIB_WTF_CLONE_EQUALS_UTIL_H_
+
+#include <type_traits>
+
+#include "mojo/public/cpp/bindings/lib/clone_equals_util.h"
+#include "third_party/WebKit/Source/wtf/HashMap.h"
+#include "third_party/WebKit/Source/wtf/Optional.h"
+#include "third_party/WebKit/Source/wtf/Vector.h"
+#include "third_party/WebKit/Source/wtf/text/WTFString.h"
+
+namespace mojo {
+namespace internal {
+
+template <typename T>
+struct CloneTraits<WTF::Vector<T>, false> {
+ static WTF::Vector<T> Clone(const WTF::Vector<T>& input) {
+ WTF::Vector<T> result;
+ result.reserveCapacity(input.size());
+ for (const auto& element : input)
+ result.append(internal::Clone(element));
+
+ return result;
+ }
+};
+
+template <typename K, typename V>
+struct CloneTraits<WTF::HashMap<K, V>, false> {
+ static WTF::HashMap<K, V> Clone(const WTF::HashMap<K, V>& input) {
+ WTF::HashMap<K, V> result;
+ auto input_end = input.end();
+ for (auto it = input.begin(); it != input_end; ++it)
+ result.add(internal::Clone(it->key), internal::Clone(it->value));
+ return result;
+ }
+};
+
+template <typename T>
+struct EqualsTraits<WTF::Vector<T>, false> {
+ static bool Equals(const WTF::Vector<T>& a, const WTF::Vector<T>& b) {
+ if (a.size() != b.size())
+ return false;
+ for (size_t i = 0; i < a.size(); ++i) {
+ if (!internal::Equals(a[i], b[i]))
+ return false;
+ }
+ return true;
+ }
+};
+
+template <typename K, typename V>
+struct EqualsTraits<WTF::HashMap<K, V>, false> {
+ static bool Equals(const WTF::HashMap<K, V>& a, const WTF::HashMap<K, V>& b) {
+ if (a.size() != b.size())
+ return false;
+
+ auto a_end = a.end();
+ auto b_end = b.end();
+
+ for (auto iter = a.begin(); iter != a_end; ++iter) {
+ auto b_iter = b.find(iter->key);
+ if (b_iter == b_end || !internal::Equals(iter->value, b_iter->value))
+ return false;
+ }
+ return true;
+ }
+};
+
+} // namespace internal
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_WTF_CLONE_EQUALS_UTIL_H_
« no previous file with comments | « mojo/public/cpp/bindings/lib/template_util.h ('k') | mojo/public/cpp/bindings/lib/wtf_serialization.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698