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

Unified Diff: mojo/public/cpp/bindings/map_traits_stl.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.h ('k') | mojo/public/cpp/bindings/map_traits_wtf_hash_map.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_stl.h
diff --git a/mojo/public/cpp/bindings/map_traits_stl.h b/mojo/public/cpp/bindings/map_traits_stl.h
index 2d5c137ff355d1526a7561d6b64bb6d010309865..ff79a200d3e87bbf229f92206930db6af8c62bd9 100644
--- a/mojo/public/cpp/bindings/map_traits_stl.h
+++ b/mojo/public/cpp/bindings/map_traits_stl.h
@@ -6,6 +6,7 @@
#define MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_STL_H_
#include <map>
+#include <unordered_map>
#include "mojo/public/cpp/bindings/map_traits.h"
@@ -56,6 +57,57 @@ struct MapTraits<std::map<K, V>> {
static void SetToEmpty(std::map<K, V>* output) { output->clear(); }
};
+template <typename K, typename V>
+struct MapTraits<std::unordered_map<K, V>> {
+ using Key = K;
+ using Value = V;
+ using Iterator = typename std::unordered_map<K, V>::iterator;
+ using ConstIterator = typename std::unordered_map<K, V>::const_iterator;
+
+ static bool IsNull(const std::unordered_map<K, V>& input) {
+ // std::unordered_map<> is always converted to non-null mojom map.
+ return false;
+ }
+
+ static void SetToNull(std::unordered_map<K, V>* output) {
+ // std::unordered_map<> doesn't support null state. Set it to empty instead.
+ output->clear();
+ }
+
+ static size_t GetSize(const std::unordered_map<K, V>& input) {
+ return input.size();
+ }
+
+ static ConstIterator GetBegin(const std::unordered_map<K, V>& input) {
+ return input.begin();
+ }
+ static Iterator GetBegin(std::unordered_map<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->first; }
+ static const K& GetKey(ConstIterator& iterator) { return iterator->first; }
+
+ static V& GetValue(Iterator& iterator) { return iterator->second; }
+ static const V& GetValue(ConstIterator& iterator) { return iterator->second; }
+
+ static bool Insert(std::unordered_map<K, V>& input, const K& key, V&& value) {
+ input.insert(std::make_pair(key, std::forward<V>(value)));
+ return true;
+ }
+ static bool Insert(std::unordered_map<K, V>& input,
+ const K& key,
+ const V& value) {
+ input.insert(std::make_pair(key, value));
+ return true;
+ }
+
+ static void SetToEmpty(std::unordered_map<K, V>* output) { output->clear(); }
+};
+
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_STL_H_
« no previous file with comments | « mojo/public/cpp/bindings/map.h ('k') | mojo/public/cpp/bindings/map_traits_wtf_hash_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698