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

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

Issue 2047633002: Revert of Remove base/move.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 <utility> 10 #include <utility>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/move.h"
14 #include "mojo/public/cpp/bindings/array.h" 14 #include "mojo/public/cpp/bindings/array.h"
15 #include "mojo/public/cpp/bindings/lib/map_data_internal.h" 15 #include "mojo/public/cpp/bindings/lib/map_data_internal.h"
16 #include "mojo/public/cpp/bindings/lib/template_util.h" 16 #include "mojo/public/cpp/bindings/lib/template_util.h"
17 #include "mojo/public/cpp/bindings/type_converter.h" 17 #include "mojo/public/cpp/bindings/type_converter.h"
18 18
19 namespace mojo { 19 namespace mojo {
20 20
21 // A move-only map that can handle move-only values. Map has the following 21 // A move-only map that can handle move-only values. Map has the following
22 // characteristics: 22 // characteristics:
23 // - The map itself can be null, and this is distinct from empty. 23 // - The map itself can be null, and this is distinct from empty.
24 // - Keys must not be move-only. 24 // - Keys must not be move-only.
25 // - The Key-type's "<" operator is used to sort the entries, and also is 25 // - The Key-type's "<" operator is used to sort the entries, and also is
26 // used to determine equality of the key values. 26 // used to determine equality of the key values.
27 // - There can only be one entry per unique key. 27 // - There can only be one entry per unique key.
28 // - Values of move-only types will be moved into the Map when they are added 28 // - Values of move-only types will be moved into the Map when they are added
29 // using the insert() method. 29 // using the insert() method.
30 template <typename K, typename V> 30 template <typename K, typename V>
31 class Map { 31 class Map {
32 MOVE_ONLY_TYPE_FOR_CPP_03(Map);
33
32 public: 34 public:
33 using Key = K; 35 using Key = K;
34 using Value = V; 36 using Value = V;
35 37
36 // Map keys cannot be move only classes. 38 // Map keys cannot be move only classes.
37 static_assert(!internal::IsMoveOnlyType<Key>::value, 39 static_assert(!internal::IsMoveOnlyType<Key>::value,
38 "Map keys cannot be move only types."); 40 "Map keys cannot be move only types.");
39 41
40 using Iterator = typename std::map<Key, Value>::iterator; 42 using Iterator = typename std::map<Key, Value>::iterator;
41 using ConstIterator = typename std::map<Key, Value>::const_iterator; 43 using ConstIterator = typename std::map<Key, Value>::const_iterator;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 template <typename T, typename U> 255 template <typename T, typename U>
254 bool operator!=(const Map<T, U>& other) const = delete; 256 bool operator!=(const Map<T, U>& other) const = delete;
255 257
256 void Take(Map* other) { 258 void Take(Map* other) {
257 operator=(nullptr); 259 operator=(nullptr);
258 Swap(other); 260 Swap(other);
259 } 261 }
260 262
261 std::map<Key, Value> map_; 263 std::map<Key, Value> map_;
262 bool is_null_; 264 bool is_null_;
263
264 DISALLOW_COPY_AND_ASSIGN(Map);
265 }; 265 };
266 266
267 // Copies the contents of an std::map to a new Map, optionally changing the 267 // Copies the contents of an std::map to a new Map, optionally changing the
268 // types of the keys and values along the way using TypeConverter. 268 // types of the keys and values along the way using TypeConverter.
269 template <typename MojoKey, 269 template <typename MojoKey,
270 typename MojoValue, 270 typename MojoValue,
271 typename STLKey, 271 typename STLKey,
272 typename STLValue> 272 typename STLValue>
273 struct TypeConverter<Map<MojoKey, MojoValue>, std::map<STLKey, STLValue>> { 273 struct TypeConverter<Map<MojoKey, MojoValue>, std::map<STLKey, STLValue>> {
274 static Map<MojoKey, MojoValue> Convert( 274 static Map<MojoKey, MojoValue> Convert(
(...skipping 24 matching lines...) Expand all
299 TypeConverter<STLValue, MojoValue>::Convert(it->second))); 299 TypeConverter<STLValue, MojoValue>::Convert(it->second)));
300 } 300 }
301 } 301 }
302 return result; 302 return result;
303 } 303 }
304 }; 304 };
305 305
306 } // namespace mojo 306 } // namespace mojo
307 307
308 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ 308 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/template_util.h ('k') | mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698