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

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

Issue 2370643004: Port messages sent by WebIDBFactoryImpl to Mojo. (Closed)
Patch Set: Address last nits and fix leaks in unit tests. Created 4 years, 2 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/BUILD.gn ('k') | mojo/public/cpp/bindings/associated_interface_ptr_info.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/array_traits_stl.h
diff --git a/mojo/public/cpp/bindings/array_traits_stl.h b/mojo/public/cpp/bindings/array_traits_stl.h
index c1aac00a7cd4686091ed5be927bc5fd886c2d7c0..dec47bfe7df9343cfc83778822b3c28ef50c59e8 100644
--- a/mojo/public/cpp/bindings/array_traits_stl.h
+++ b/mojo/public/cpp/bindings/array_traits_stl.h
@@ -5,6 +5,8 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_STL_H_
#define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_STL_H_
+#include <map>
+#include <set>
#include <vector>
#include "mojo/public/cpp/bindings/array_traits.h"
@@ -85,6 +87,41 @@ struct ArrayTraits<std::set<T>> {
}
};
+template <typename K, typename V>
+struct MapValuesArrayView {
+ explicit MapValuesArrayView(const std::map<K, V>& map) : map(map) {}
+ const std::map<K, V>& map;
+};
+
+// Convenience function to create a MapValuesArrayView<> that infers the
+// template arguments from its argument type.
+template <typename K, typename V>
+MapValuesArrayView<K, V> MapValuesToArray(const std::map<K, V>& map) {
+ return MapValuesArrayView<K, V>(map);
+}
+
+// This ArrayTraits specialization is used only for serialization and converts
+// a map<K, V> into an array<V>, discarding the keys.
+template <typename K, typename V>
+struct ArrayTraits<MapValuesArrayView<K, V>> {
+ using Element = V;
+ using ConstIterator = typename std::map<K, V>::const_iterator;
+
+ static bool IsNull(const MapValuesArrayView<K, V>& input) {
+ // std::map<> is always converted to non-null mojom array.
+ return false;
+ }
+
+ static size_t GetSize(const MapValuesArrayView<K, V>& input) {
+ return input.map.size();
+ }
+ static ConstIterator GetBegin(const MapValuesArrayView<K, V>& input) {
+ return input.map.begin();
+ }
+ static void AdvanceIterator(ConstIterator& iterator) { ++iterator; }
+ static const V& GetValue(ConstIterator& iterator) { return iterator->second; }
+};
+
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_STL_H_
« no previous file with comments | « mojo/public/cpp/bindings/BUILD.gn ('k') | mojo/public/cpp/bindings/associated_interface_ptr_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698