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

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

Issue 2165233003: Mojo C++ bindings: provide data view for all object types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 unified diff | Download patch
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_DATA_VIEW_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_DATA_VIEW_H_
7
8 #include "base/logging.h"
9 #include "mojo/public/cpp/bindings/array.h"
10 #include "mojo/public/cpp/bindings/array_data_view.h"
11 #include "mojo/public/cpp/bindings/lib/bindings_internal.h"
12 #include "mojo/public/cpp/bindings/lib/serialization_context.h"
13 #include "mojo/public/cpp/bindings/lib/serialization_forward.h"
14 #include "mojo/public/cpp/bindings/map.h"
15
16 namespace mojo {
17
18 template <typename K, typename V>
19 class MapDataView {
20 public:
21 using Data_ = typename internal::MojomTypeTraits<
22 Map<typename internal::DataViewTraits<K>::MojomType,
23 typename internal::DataViewTraits<V>::MojomType>>::Data;
24
25 MapDataView() {}
26
27 MapDataView(Data_* data, internal::SerializationContext* context)
28 : keys_(data ? data->keys.Get() : nullptr, context),
29 values_(data ? data->values.Get() : nullptr, context) {}
30
31 bool is_null() const {
32 DCHECK_EQ(keys_.is_null(), values_.is_null());
33 return keys_.is_null();
34 }
35
36 size_t size() const {
37 DCHECK_EQ(keys_.size(), values_.size());
38 return keys_.size();
39 }
40
41 ArrayDataView<K>& keys() { return keys_; }
42 const ArrayDataView<K>& keys() const { return keys_; }
43
44 template <typename U>
45 bool ReadKeys(U* output) {
46 return internal::Deserialize<
47 Array<typename internal::DataViewTraits<K>::MojomType>>(
48 keys_.data_, output, keys_.context_);
49 }
50
51 ArrayDataView<V>& values() { return values_; }
52 const ArrayDataView<V>& values() const { return values_; }
53
54 template <typename U>
55 bool ReadValues(U* output) {
56 return internal::Deserialize<
57 Array<typename internal::DataViewTraits<V>::MojomType>>(
58 values_.data_, output, values_.context_);
59 }
60
61 private:
62 ArrayDataView<K> keys_;
63 ArrayDataView<V> values_;
64 };
65
66 } // namespace mojo
67
68 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_DATA_VIEW_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/string_serialization.h ('k') | mojo/public/cpp/bindings/native_struct_data_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698