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

Unified Diff: mojo/public/cpp/bindings/map_traits_wtf_hash_map.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/map_traits_stl.h ('k') | mojo/public/cpp/bindings/native_enum.h » ('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_hash_map.h
diff --git a/mojo/public/cpp/bindings/map_traits_wtf_hash_map.h b/mojo/public/cpp/bindings/map_traits_wtf_hash_map.h
new file mode 100644
index 0000000000000000000000000000000000000000..439220130e85874fd98379d7a1bc9b9fce494b0f
--- /dev/null
+++ b/mojo/public/cpp/bindings/map_traits_wtf_hash_map.h
@@ -0,0 +1,71 @@
+// 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_HASH_MAP_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_WTF_HASH_MAP_H_
+
+#include "base/logging.h"
+#include "mojo/public/cpp/bindings/map_traits.h"
+#include "third_party/WebKit/Source/wtf/HashMap.h"
+
+namespace mojo {
+
+template <typename K, typename V>
+struct MapTraits<WTF::HashMap<K, V>> {
+ using Key = K;
+ using Value = V;
+ using Iterator = typename WTF::HashMap<K, V>::iterator;
+ using ConstIterator = typename WTF::HashMap<K, V>::const_iterator;
+
+ static bool IsNull(const WTF::HashMap<K, V>& input) {
+ // WTF::HashMap<> is always converted to non-null mojom map.
+ return false;
+ }
+
+ static void SetToNull(WTF::HashMap<K, V>* output) {
+ // WTF::HashMap<> doesn't support null state. Set it to empty instead.
+ output->clear();
+ }
+
+ static size_t GetSize(const WTF::HashMap<K, V>& input) {
+ return input.size();
+ }
+
+ static ConstIterator GetBegin(const WTF::HashMap<K, V>& input) {
+ return input.begin();
+ }
+ static Iterator GetBegin(WTF::HashMap<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(WTF::HashMap<K, V>& input, const K& key, V&& value) {
+ if (!WTF::HashMap<K, V>::isValidKey(key)) {
+ LOG(ERROR) << "The key value is disallowed by WTF::HashMap: " << key;
+ return false;
+ }
+ input.add(key, std::forward<V>(value));
+ return true;
+ }
+ static bool Insert(WTF::HashMap<K, V>& input, const K& key, const V& value) {
+ if (!WTF::HashMap<K, V>::isValidKey(key)) {
+ LOG(ERROR) << "The key value is disallowed by WTF::HashMap: " << key;
+ return false;
+ }
+ input.add(key, value);
+ return true;
+ }
+
+ static void SetToEmpty(WTF::HashMap<K, V>* output) { output->clear(); }
+};
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_WTF_HASH_MAP_H_
« no previous file with comments | « mojo/public/cpp/bindings/map_traits_stl.h ('k') | mojo/public/cpp/bindings/native_enum.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698