| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "mojo/public/cpp/bindings/lib/map_internal.h" | 10 #include "mojo/public/cpp/bindings/lib/map_internal.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 128 |
| 129 // Swaps the contents of this Map with an std::map containing keys and values | 129 // Swaps the contents of this Map with an std::map containing keys and values |
| 130 // of the same type. Since std::map cannot represent the null state, the | 130 // of the same type. Since std::map cannot represent the null state, the |
| 131 // std::map will be empty if Map is null. The Map will always be left in a | 131 // std::map will be empty if Map is null. The Map will always be left in a |
| 132 // non-null state. | 132 // non-null state. |
| 133 void Swap(std::map<Key, Value>* other) { | 133 void Swap(std::map<Key, Value>* other) { |
| 134 is_null_ = false; | 134 is_null_ = false; |
| 135 map_.swap(*other); | 135 map_.swap(*other); |
| 136 } | 136 } |
| 137 | 137 |
| 138 // Removes all contents from the Map and places them into parallel key/value | |
| 139 // arrays. Each key will be copied from the source to the destination, and | |
| 140 // values will be copied unless their type is designated move-only, in which | |
| 141 // case they will be passed by calling their Pass() method. Either way, the | |
| 142 // Map will be left in a null state. | |
| 143 void DecomposeMapTo(mojo::Array<Key>* keys, mojo::Array<Value>* values) { | |
| 144 Traits::Decompose(&map_, keys, values); | |
| 145 Traits::Finalize(&map_); | |
| 146 map_.clear(); | |
| 147 is_null_ = true; | |
| 148 } | |
| 149 | |
| 150 // Returns a new Map that contains a copy of the contents of this map. If the | 138 // Returns a new Map that contains a copy of the contents of this map. If the |
| 151 // values are of a type that is designated move-only, they will be cloned | 139 // values are of a type that is designated move-only, they will be cloned |
| 152 // using the Clone() method of the type. Please note that calling this method | 140 // using the Clone() method of the type. Please note that calling this method |
| 153 // will fail compilation if the value type cannot be cloned (which usually | 141 // will fail compilation if the value type cannot be cloned (which usually |
| 154 // means that it is a Mojo handle type or a type that contains Mojo handles). | 142 // means that it is a Mojo handle type or a type that contains Mojo handles). |
| 155 Map Clone() const { | 143 Map Clone() const { |
| 156 Map result; | 144 Map result; |
| 157 result.is_null_ = is_null_; | 145 result.is_null_ = is_null_; |
| 158 Traits::Clone(map_, &result.map_); | 146 Traits::Clone(map_, &result.map_); |
| 159 return result.Pass(); | 147 return result.Pass(); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 TypeConverter<STLValue, MojoValue>::Convert(it.GetValue()))); | 302 TypeConverter<STLValue, MojoValue>::Convert(it.GetValue()))); |
| 315 } | 303 } |
| 316 } | 304 } |
| 317 return result; | 305 return result; |
| 318 } | 306 } |
| 319 }; | 307 }; |
| 320 | 308 |
| 321 } // namespace mojo | 309 } // namespace mojo |
| 322 | 310 |
| 323 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ | 311 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ |
| OLD | NEW |