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

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

Issue 2136733002: Mojo C++ bindings: add a new mode to generator to use native STL/WTF types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@67_new
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
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 <stddef.h> 8 #include <stddef.h>
9 #include <map> 9 #include <map>
10 #include <unordered_map>
10 #include <utility> 11 #include <utility>
11 12
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "mojo/public/cpp/bindings/array.h" 15 #include "mojo/public/cpp/bindings/array.h"
15 #include "mojo/public/cpp/bindings/lib/map_data_internal.h" 16 #include "mojo/public/cpp/bindings/lib/map_data_internal.h"
16 #include "mojo/public/cpp/bindings/lib/template_util.h" 17 #include "mojo/public/cpp/bindings/lib/template_util.h"
17 #include "mojo/public/cpp/bindings/type_converter.h" 18 #include "mojo/public/cpp/bindings/type_converter.h"
18 19
19 namespace mojo { 20 namespace mojo {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 void SetToEmpty() { 129 void SetToEmpty() {
129 is_null_ = false; 130 is_null_ = false;
130 map_.clear(); 131 map_.clear();
131 } 132 }
132 133
133 // Returns a const reference to the std::map managed by this class. If this 134 // Returns a const reference to the std::map managed by this class. If this
134 // object is null, the return value will be an empty map. 135 // object is null, the return value will be an empty map.
135 const std::map<Key, Value>& storage() const { return map_; } 136 const std::map<Key, Value>& storage() const { return map_; }
136 137
137 // Passes the underlying storage and resets this map to null. 138 // Passes the underlying storage and resets this map to null.
138 //
139 // TODO(yzshen): Consider changing this to a rvalue-ref-qualified conversion
140 // to std::map<Key, Value> after we move to MSVC 2015.
141 std::map<Key, Value> PassStorage() { 139 std::map<Key, Value> PassStorage() {
142 is_null_ = true; 140 is_null_ = true;
143 return std::move(map_); 141 return std::move(map_);
144 } 142 }
145 143
144 operator const std::map<Key, Value>&() const { return map_; }
145
146 // Swaps the contents of this Map with another Map of the same type (including 146 // Swaps the contents of this Map with another Map of the same type (including
147 // nullness). 147 // nullness).
148 void Swap(Map<Key, Value>* other) { 148 void Swap(Map<Key, Value>* other) {
149 std::swap(is_null_, other->is_null_); 149 std::swap(is_null_, other->is_null_);
150 map_.swap(other->map_); 150 map_.swap(other->map_);
151 } 151 }
152 152
153 // Swaps the contents of this Map with an std::map containing keys and values 153 // Swaps the contents of this Map with an std::map containing keys and values
154 // of the same type. Since std::map cannot represent the null state, the 154 // of the same type. Since std::map cannot represent the null state, the
155 // std::map will be empty if Map is null. The Map will always be left in a 155 // std::map will be empty if Map is null. The Map will always be left in a
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 TypeConverter<STLValue, MojoValue>::Convert(it->second))); 295 TypeConverter<STLValue, MojoValue>::Convert(it->second)));
296 } 296 }
297 } 297 }
298 return result; 298 return result;
299 } 299 }
300 }; 300 };
301 301
302 } // namespace mojo 302 } // namespace mojo
303 303
304 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ 304 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/wtf_serialization.h ('k') | mojo/public/cpp/bindings/map_traits_stl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698