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

Side by Side 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, 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_STANDARD_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_STANDARD_H_
7
8 #include "mojo/public/cpp/bindings/map.h"
9 #include "mojo/public/cpp/bindings/map_traits.h"
10
11 namespace mojo {
12
13 template <typename K, typename V>
14 struct MapTraits<Map<K, V>> {
15 using Key = K;
16 using Value = V;
17 using Iterator = typename Map<K, V>::Iterator;
18 using ConstIterator = typename Map<K, V>::ConstIterator;
19
20 static bool IsNull(const Map<K, V>& input) { return input.is_null(); }
21 static void SetToNull(Map<K, V>* output) { *output = nullptr; }
22
23 static size_t GetSize(const Map<K, V>& input) { return input.size(); }
24
25 static ConstIterator GetBegin(const Map<K, V>& input) {
26 return input.begin();
27 }
28 static Iterator GetBegin(Map<K, V>& input) { return input.begin(); }
29
30 static void AdvanceIterator(ConstIterator& iterator) { iterator++; }
31 static void AdvanceIterator(Iterator& iterator) { iterator++; }
32
33 static const K& GetKey(Iterator& iterator) { return iterator->first; }
34 static const K& GetKey(ConstIterator& iterator) { return iterator->first; }
35
36 static V& GetValue(Iterator& iterator) { return iterator->second; }
37 static const V& GetValue(ConstIterator& iterator) { return iterator->second; }
38
39 static void Insert(Map<K, V>& input, const K& key, V&& value) {
40 input.insert(key, std::forward<V>(value));
41 }
42 static void Insert(Map<K, V>& input, const K& key, const V& value) {
43 input.insert(key, value);
44 }
45
46 static void SetToEmpty(Map<K, V>* output) { output->SetToEmpty(); }
47 };
48
49 } // namespace mojo
50
51 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_STANDARD_H_
OLDNEW
« 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