| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_DATA_VIEW_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_DATA_VIEW_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_DATA_VIEW_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_DATA_VIEW_H_ |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "mojo/public/cpp/bindings/array.h" | |
| 10 #include "mojo/public/cpp/bindings/array_data_view.h" | 9 #include "mojo/public/cpp/bindings/array_data_view.h" |
| 11 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" | 10 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
| 11 #include "mojo/public/cpp/bindings/lib/map_data_internal.h" |
| 12 #include "mojo/public/cpp/bindings/lib/serialization_context.h" | 12 #include "mojo/public/cpp/bindings/lib/serialization_context.h" |
| 13 #include "mojo/public/cpp/bindings/lib/serialization_forward.h" | 13 #include "mojo/public/cpp/bindings/lib/serialization_forward.h" |
| 14 #include "mojo/public/cpp/bindings/map.h" | |
| 15 | 14 |
| 16 namespace mojo { | 15 namespace mojo { |
| 17 | 16 |
| 18 template <typename K, typename V> | 17 template <typename K, typename V> |
| 19 class MapDataView { | 18 class MapDataView { |
| 20 public: | 19 public: |
| 21 using Data_ = typename internal::MojomTypeTraits< | 20 using Data_ = typename internal::MojomTypeTraits<MapDataView<K, V>>::Data; |
| 22 Map<typename internal::DataViewTraits<K>::MojomType, | |
| 23 typename internal::DataViewTraits<V>::MojomType>>::Data; | |
| 24 | 21 |
| 25 MapDataView() {} | 22 MapDataView() {} |
| 26 | 23 |
| 27 MapDataView(Data_* data, internal::SerializationContext* context) | 24 MapDataView(Data_* data, internal::SerializationContext* context) |
| 28 : keys_(data ? data->keys.Get() : nullptr, context), | 25 : keys_(data ? data->keys.Get() : nullptr, context), |
| 29 values_(data ? data->values.Get() : nullptr, context) {} | 26 values_(data ? data->values.Get() : nullptr, context) {} |
| 30 | 27 |
| 31 bool is_null() const { | 28 bool is_null() const { |
| 32 DCHECK_EQ(keys_.is_null(), values_.is_null()); | 29 DCHECK_EQ(keys_.is_null(), values_.is_null()); |
| 33 return keys_.is_null(); | 30 return keys_.is_null(); |
| 34 } | 31 } |
| 35 | 32 |
| 36 size_t size() const { | 33 size_t size() const { |
| 37 DCHECK_EQ(keys_.size(), values_.size()); | 34 DCHECK_EQ(keys_.size(), values_.size()); |
| 38 return keys_.size(); | 35 return keys_.size(); |
| 39 } | 36 } |
| 40 | 37 |
| 41 ArrayDataView<K>& keys() { return keys_; } | 38 ArrayDataView<K>& keys() { return keys_; } |
| 42 const ArrayDataView<K>& keys() const { return keys_; } | 39 const ArrayDataView<K>& keys() const { return keys_; } |
| 43 | 40 |
| 44 template <typename U> | 41 template <typename U> |
| 45 bool ReadKeys(U* output) { | 42 bool ReadKeys(U* output) { |
| 46 return internal::Deserialize< | 43 return internal::Deserialize<ArrayDataView<K>>(keys_.data_, output, |
| 47 Array<typename internal::DataViewTraits<K>::MojomType>>( | 44 keys_.context_); |
| 48 keys_.data_, output, keys_.context_); | |
| 49 } | 45 } |
| 50 | 46 |
| 51 ArrayDataView<V>& values() { return values_; } | 47 ArrayDataView<V>& values() { return values_; } |
| 52 const ArrayDataView<V>& values() const { return values_; } | 48 const ArrayDataView<V>& values() const { return values_; } |
| 53 | 49 |
| 54 template <typename U> | 50 template <typename U> |
| 55 bool ReadValues(U* output) { | 51 bool ReadValues(U* output) { |
| 56 return internal::Deserialize< | 52 return internal::Deserialize<ArrayDataView<V>>(values_.data_, output, |
| 57 Array<typename internal::DataViewTraits<V>::MojomType>>( | 53 values_.context_); |
| 58 values_.data_, output, values_.context_); | |
| 59 } | 54 } |
| 60 | 55 |
| 61 private: | 56 private: |
| 62 ArrayDataView<K> keys_; | 57 ArrayDataView<K> keys_; |
| 63 ArrayDataView<V> values_; | 58 ArrayDataView<V> values_; |
| 64 }; | 59 }; |
| 65 | 60 |
| 66 } // namespace mojo | 61 } // namespace mojo |
| 67 | 62 |
| 68 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_DATA_VIEW_H_ | 63 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_DATA_VIEW_H_ |
| OLD | NEW |