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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/map_data_view.h
diff --git a/mojo/public/cpp/bindings/map_data_view.h b/mojo/public/cpp/bindings/map_data_view.h
new file mode 100644
index 0000000000000000000000000000000000000000..c340407b360cb3ef43897c5e99001113834fff20
--- /dev/null
+++ b/mojo/public/cpp/bindings/map_data_view.h
@@ -0,0 +1,68 @@
+// 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_DATA_VIEW_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_MAP_DATA_VIEW_H_
+
+#include "base/logging.h"
+#include "mojo/public/cpp/bindings/array.h"
+#include "mojo/public/cpp/bindings/array_data_view.h"
+#include "mojo/public/cpp/bindings/lib/bindings_internal.h"
+#include "mojo/public/cpp/bindings/lib/serialization_context.h"
+#include "mojo/public/cpp/bindings/lib/serialization_forward.h"
+#include "mojo/public/cpp/bindings/map.h"
+
+namespace mojo {
+
+template <typename K, typename V>
+class MapDataView {
+ public:
+ using Data_ = typename internal::MojomTypeTraits<
+ Map<typename internal::DataViewTraits<K>::MojomType,
+ typename internal::DataViewTraits<V>::MojomType>>::Data;
+
+ MapDataView() {}
+
+ MapDataView(Data_* data, internal::SerializationContext* context)
+ : keys_(data ? data->keys.Get() : nullptr, context),
+ values_(data ? data->values.Get() : nullptr, context) {}
+
+ bool is_null() const {
+ DCHECK_EQ(keys_.is_null(), values_.is_null());
+ return keys_.is_null();
+ }
+
+ size_t size() const {
+ DCHECK_EQ(keys_.size(), values_.size());
+ return keys_.size();
+ }
+
+ ArrayDataView<K>& keys() { return keys_; }
+ const ArrayDataView<K>& keys() const { return keys_; }
+
+ template <typename U>
+ bool ReadKeys(U* output) {
+ return internal::Deserialize<
+ Array<typename internal::DataViewTraits<K>::MojomType>>(
+ keys_.data_, output, keys_.context_);
+ }
+
+ ArrayDataView<V>& values() { return values_; }
+ const ArrayDataView<V>& values() const { return values_; }
+
+ template <typename U>
+ bool ReadValues(U* output) {
+ return internal::Deserialize<
+ Array<typename internal::DataViewTraits<V>::MojomType>>(
+ values_.data_, output, values_.context_);
+ }
+
+ private:
+ ArrayDataView<K> keys_;
+ ArrayDataView<V> values_;
+};
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_DATA_VIEW_H_
« 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