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

Side by Side Diff: mojo/public/cpp/bindings/map_traits_wtf.h

Issue 2034273002: Mojo C++ bindings: introduce mojo::WTFMap for blink bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed the code of adding enum key support to WTF::HashMap; which turned out to be non-trivial; wi… 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_stl.h ('k') | mojo/public/cpp/bindings/tests/BUILD.gn » ('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_WTF_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_WTF_H_
7
8 #include "base/logging.h"
9 #include "mojo/public/cpp/bindings/map_traits.h"
10 #include "mojo/public/cpp/bindings/wtf_map.h"
11
12 namespace mojo {
13
14 template <typename K, typename V>
15 struct MapTraits<WTFMap<K, V>> {
16 using Key = K;
17 using Value = V;
18 using Iterator = typename WTFMap<K, V>::Iterator;
19 using ConstIterator = typename WTFMap<K, V>::ConstIterator;
20
21 static bool IsNull(const WTFMap<K, V>& input) { return input.is_null(); }
22 static void SetToNull(WTFMap<K, V>* output) { *output = nullptr; }
23
24 static size_t GetSize(const WTFMap<K, V>& input) { return input.size(); }
25
26 static ConstIterator GetBegin(const WTFMap<K, V>& input) {
27 return input.begin();
28 }
29 static Iterator GetBegin(WTFMap<K, V>& input) { return input.begin(); }
30
31 static void AdvanceIterator(ConstIterator& iterator) { ++iterator; }
32 static void AdvanceIterator(Iterator& iterator) { ++iterator; }
33
34 static const K& GetKey(Iterator& iterator) { return iterator->key; }
35 static const K& GetKey(ConstIterator& iterator) { return iterator->key; }
36
37 static V& GetValue(Iterator& iterator) { return iterator->value; }
38 static const V& GetValue(ConstIterator& iterator) { return iterator->value; }
39
40 static bool Insert(WTFMap<K, V>& input, const K& key, V&& value) {
41 if (!WTFMap<K, V>::IsValidKey(key)) {
42 LOG(ERROR) << "The key value is disallowed by WTF::HashMap: " << key;
43 return false;
44 }
45 input.insert(key, std::forward<V>(value));
46 return true;
47 }
48 static bool Insert(WTFMap<K, V>& input, const K& key, const V& value) {
49 if (!WTFMap<K, V>::IsValidKey(key)) {
50 LOG(ERROR) << "The key value is disallowed by WTF::HashMap: " << key;
51 return false;
52 }
53 input.insert(key, value);
54 return true;
55 }
56
57 static void SetToEmpty(WTFMap<K, V>* output) { output->SetToEmpty(); }
58 };
59
60 } // namespace mojo
61
62 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_WTF_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/map_traits_stl.h ('k') | mojo/public/cpp/bindings/tests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698