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

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

Issue 2014403002: Mojo C++ bindings: custom type mapping of map (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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.h ('k') | mojo/public/cpp/bindings/map_traits_stl.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_standard.h
diff --git a/mojo/public/cpp/bindings/map_traits_standard.h b/mojo/public/cpp/bindings/map_traits_standard.h
new file mode 100644
index 0000000000000000000000000000000000000000..231c739a79de218401a68805c915137cb48560a6
--- /dev/null
+++ b/mojo/public/cpp/bindings/map_traits_standard.h
@@ -0,0 +1,51 @@
+// 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_STANDARD_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_STANDARD_H_
+
+#include "mojo/public/cpp/bindings/map.h"
+#include "mojo/public/cpp/bindings/map_traits.h"
+
+namespace mojo {
+
+template <typename K, typename V>
+struct MapTraits<Map<K, V>> {
+ using Key = K;
+ using Value = V;
+ using Iterator = typename Map<K, V>::Iterator;
+ using ConstIterator = typename Map<K, V>::ConstIterator;
+
+ static bool IsNull(const Map<K, V>& input) { return input.is_null(); }
+ static void SetToNull(Map<K, V>* output) { *output = nullptr; }
+
+ static size_t GetSize(const Map<K, V>& input) { return input.size(); }
+
+ static ConstIterator GetBegin(const Map<K, V>& input) {
+ return input.begin();
+ }
+ static Iterator GetBegin(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 void Insert(Map<K, V>& input, const K& key, V&& value) {
+ input.insert(key, std::forward<V>(value));
+ }
+ static void Insert(Map<K, V>& input, const K& key, const V& value) {
+ input.insert(key, value);
+ }
+
+ static void SetToEmpty(Map<K, V>* output) { output->SetToEmpty(); }
+};
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_STANDARD_H_
« no previous file with comments | « mojo/public/cpp/bindings/map_traits.h ('k') | mojo/public/cpp/bindings/map_traits_stl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698