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

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

Issue 1358353002: * Change C++ serialization/deserialization to not be move-only operations (with the except of |Ha… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: (*it).get() to it->, and other formatting Created 5 years, 2 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
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
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
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_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/string_serialization.cc ('k') | mojo/public/cpp/bindings/struct_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698