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

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

Issue 2014403002: Mojo C++ bindings: custom type mapping of map (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>
(...skipping 18 matching lines...) Expand all
29 MOVE_ONLY_TYPE_FOR_CPP_03(Map); 29 MOVE_ONLY_TYPE_FOR_CPP_03(Map);
30 30
31 public: 31 public:
32 using Key = K; 32 using Key = K;
33 using Value = V; 33 using Value = V;
34 34
35 // Map keys cannot be move only classes. 35 // Map keys cannot be move only classes.
36 static_assert(!internal::IsMoveOnlyType<Key>::value, 36 static_assert(!internal::IsMoveOnlyType<Key>::value,
37 "Map keys cannot be move only types."); 37 "Map keys cannot be move only types.");
38 38
39 using Iterator = typename std::map<Key, Value>::iterator;
39 using ConstIterator = typename std::map<Key, Value>::const_iterator; 40 using ConstIterator = typename std::map<Key, Value>::const_iterator;
40 41
41 using Data_ = internal::Map_Data< 42 using Data_ = internal::Map_Data<
42 typename internal::GetDataTypeAsArrayElement<Key>::Data, 43 typename internal::GetDataTypeAsArrayElement<Key>::Data,
43 typename internal::GetDataTypeAsArrayElement<Value>::Data>; 44 typename internal::GetDataTypeAsArrayElement<Value>::Data>;
44 45
45 // Constructs an empty map. 46 // Constructs an empty map.
46 Map() : is_null_(false) {} 47 Map() : is_null_(false) {}
47 // Constructs a null map. 48 // Constructs a null map.
48 Map(std::nullptr_t null_pointer) : is_null_(true) {} 49 Map(std::nullptr_t null_pointer) : is_null_(true) {}
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 return false; 217 return false;
217 ++i; 218 ++i;
218 ++j; 219 ++j;
219 } 220 }
220 return true; 221 return true;
221 } 222 }
222 223
223 // Provide read-only iteration over map members in a way similar to STL 224 // Provide read-only iteration over map members in a way similar to STL
224 // collections. 225 // collections.
225 ConstIterator begin() const { return map_.begin(); } 226 ConstIterator begin() const { return map_.begin(); }
227 Iterator begin() { return map_.begin(); }
228
226 ConstIterator end() const { return map_.end(); } 229 ConstIterator end() const { return map_.end(); }
230 Iterator end() { return map_.end(); }
227 231
228 // Returns the iterator pointing to the entry for |key|, if present, or else 232 // Returns the iterator pointing to the entry for |key|, if present, or else
229 // returns end(). 233 // returns end().
230 ConstIterator find(const Key& key) const { return map_.find(key); } 234 ConstIterator find(const Key& key) const { return map_.find(key); }
235 Iterator find(const Key& key) { return map_.find(key); }
231 236
232 private: 237 private:
233 typedef std::map<Key, Value> Map::*Testable; 238 typedef std::map<Key, Value> Map::*Testable;
234 239
235 public: 240 public:
236 // The Map may be used in boolean expressions to determine if it is non-null, 241 // The Map may be used in boolean expressions to determine if it is non-null,
237 // but is not implicitly convertible to an actual bool value (which would be 242 // but is not implicitly convertible to an actual bool value (which would be
238 // dangerous). 243 // dangerous).
239 operator Testable() const { return is_null_ ? 0 : &Map::map_; } 244 operator Testable() const { return is_null_ ? 0 : &Map::map_; }
240 245
241 private: 246 private:
242 using Traits = 247 using Traits =
243 internal::MapTraits<Key, Value, internal::IsMoveOnlyType<Value>::value>; 248 internal::MapCloneTraits<Key,
249 Value,
250 internal::IsMoveOnlyType<Value>::value>;
244 251
245 // Forbid the == and != operators explicitly, otherwise Map will be converted 252 // Forbid the == and != operators explicitly, otherwise Map will be converted
246 // to Testable to do == or != comparison. 253 // to Testable to do == or != comparison.
247 template <typename T, typename U> 254 template <typename T, typename U>
248 bool operator==(const Map<T, U>& other) const = delete; 255 bool operator==(const Map<T, U>& other) const = delete;
249 template <typename T, typename U> 256 template <typename T, typename U>
250 bool operator!=(const Map<T, U>& other) const = delete; 257 bool operator!=(const Map<T, U>& other) const = delete;
251 258
252 void Take(Map* other) { 259 void Take(Map* other) {
253 operator=(nullptr); 260 operator=(nullptr);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 TypeConverter<STLValue, MojoValue>::Convert(it->second))); 300 TypeConverter<STLValue, MojoValue>::Convert(it->second)));
294 } 301 }
295 } 302 }
296 return result; 303 return result;
297 } 304 }
298 }; 305 };
299 306
300 } // namespace mojo 307 } // namespace mojo
301 308
302 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ 309 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/serialization_util.h ('k') | mojo/public/cpp/bindings/map_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698