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

Unified Diff: mojo/public/cpp/bindings/map_traits_wtf.h

Issue 2034273002: Mojo C++ bindings: introduce mojo::WTFMap for blink bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed the code of adding enum key support to WTF::HashMap; which turned out to be non-trivial; wi… Created 4 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
« no previous file with comments | « mojo/public/cpp/bindings/map_traits_stl.h ('k') | mojo/public/cpp/bindings/tests/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/map_traits_wtf.h
diff --git a/mojo/public/cpp/bindings/map_traits_wtf.h b/mojo/public/cpp/bindings/map_traits_wtf.h
new file mode 100644
index 0000000000000000000000000000000000000000..805e4c987e374d35be122d5ddedc1bc2e2102172
--- /dev/null
+++ b/mojo/public/cpp/bindings/map_traits_wtf.h
@@ -0,0 +1,62 @@
+// 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_MAP_TRAITS_WTF_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_WTF_H_
+
+#include "base/logging.h"
+#include "mojo/public/cpp/bindings/map_traits.h"
+#include "mojo/public/cpp/bindings/wtf_map.h"
+
+namespace mojo {
+
+template <typename K, typename V>
+struct MapTraits<WTFMap<K, V>> {
+ using Key = K;
+ using Value = V;
+ using Iterator = typename WTFMap<K, V>::Iterator;
+ using ConstIterator = typename WTFMap<K, V>::ConstIterator;
+
+ static bool IsNull(const WTFMap<K, V>& input) { return input.is_null(); }
+ static void SetToNull(WTFMap<K, V>* output) { *output = nullptr; }
+
+ static size_t GetSize(const WTFMap<K, V>& input) { return input.size(); }
+
+ static ConstIterator GetBegin(const WTFMap<K, V>& input) {
+ return input.begin();
+ }
+ static Iterator GetBegin(WTFMap<K, V>& input) { return input.begin(); }
+
+ static void AdvanceIterator(ConstIterator& iterator) { ++iterator; }
+ static void AdvanceIterator(Iterator& iterator) { ++iterator; }
+
+ static const K& GetKey(Iterator& iterator) { return iterator->key; }
+ static const K& GetKey(ConstIterator& iterator) { return iterator->key; }
+
+ static V& GetValue(Iterator& iterator) { return iterator->value; }
+ static const V& GetValue(ConstIterator& iterator) { return iterator->value; }
+
+ static bool Insert(WTFMap<K, V>& input, const K& key, V&& value) {
+ if (!WTFMap<K, V>::IsValidKey(key)) {
+ LOG(ERROR) << "The key value is disallowed by WTF::HashMap: " << key;
+ return false;
+ }
+ input.insert(key, std::forward<V>(value));
+ return true;
+ }
+ static bool Insert(WTFMap<K, V>& input, const K& key, const V& value) {
+ if (!WTFMap<K, V>::IsValidKey(key)) {
+ LOG(ERROR) << "The key value is disallowed by WTF::HashMap: " << key;
+ return false;
+ }
+ input.insert(key, value);
+ return true;
+ }
+
+ static void SetToEmpty(WTFMap<K, V>* output) { output->SetToEmpty(); }
+};
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_WTF_H_
« no previous file with comments | « mojo/public/cpp/bindings/map_traits_stl.h ('k') | mojo/public/cpp/bindings/tests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698