| 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_LIB_MAP_INTERNAL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_INTERNAL_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_INTERNAL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_INTERNAL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "mojo/public/cpp/bindings/array.h" | 10 #include "mojo/public/cpp/bindings/array.h" |
| 11 #include "mojo/public/cpp/bindings/lib/template_util.h" | 11 #include "mojo/public/cpp/bindings/lib/template_util.h" |
| 12 | 12 |
| 13 namespace mojo { | 13 namespace mojo { |
| 14 namespace internal { | 14 namespace internal { |
| 15 | 15 |
| 16 template <typename Key, typename Value, bool kValueIsMoveOnlyType> | 16 template <typename Key, typename Value, bool kValueIsMoveOnlyType> |
| 17 struct MapTraits {}; | 17 struct MapTraits {}; |
| 18 | 18 |
| 19 // Defines traits of a map for which Value is not a move-only type. |
| 19 template <typename Key, typename Value> | 20 template <typename Key, typename Value> |
| 20 struct MapTraits<Key, Value, false> { | 21 struct MapTraits<Key, Value, false> { |
| 21 // Map keys can't be move only types. | 22 // Map keys can't be move only types. |
| 22 static_assert(!internal::IsMoveOnlyType<Key>::value, | 23 static_assert(!internal::IsMoveOnlyType<Key>::value, |
| 23 "Map keys can not be move only types."); | 24 "Map keys can not be move only types."); |
| 24 | 25 |
| 25 typedef Key KeyStorageType; | 26 typedef Key KeyStorageType; |
| 26 typedef Key& KeyRefType; | 27 typedef Key& KeyRefType; |
| 27 typedef const Key& KeyConstRefType; | 28 typedef const Key& KeyConstRefType; |
| 28 typedef KeyConstRefType KeyForwardType; | 29 typedef KeyConstRefType KeyForwardType; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 99 } |
| 99 static inline void Clone( | 100 static inline void Clone( |
| 100 const std::map<KeyStorageType, ValueStorageType>& src, | 101 const std::map<KeyStorageType, ValueStorageType>& src, |
| 101 std::map<KeyStorageType, ValueStorageType>* dst) { | 102 std::map<KeyStorageType, ValueStorageType>* dst) { |
| 102 dst->clear(); | 103 dst->clear(); |
| 103 for (auto it = src.begin(); it != src.end(); ++it) | 104 for (auto it = src.begin(); it != src.end(); ++it) |
| 104 dst->insert(*it); | 105 dst->insert(*it); |
| 105 } | 106 } |
| 106 }; | 107 }; |
| 107 | 108 |
| 109 // Defines traits of a map for which Value is a move-only type. |
| 108 template <typename Key, typename Value> | 110 template <typename Key, typename Value> |
| 109 struct MapTraits<Key, Value, true> { | 111 struct MapTraits<Key, Value, true> { |
| 110 // Map keys can't be move only types. | 112 // Map keys can't be move only types. |
| 111 static_assert(!internal::IsMoveOnlyType<Key>::value, | 113 static_assert(!internal::IsMoveOnlyType<Key>::value, |
| 112 "Map keys can not be move only types."); | 114 "Map keys can not be move only types."); |
| 113 | 115 |
| 114 typedef Key KeyStorageType; | 116 typedef Key KeyStorageType; |
| 115 typedef Key& KeyRefType; | 117 typedef Key& KeyRefType; |
| 116 typedef const Key& KeyConstRefType; | 118 typedef const Key& KeyConstRefType; |
| 117 typedef KeyConstRefType KeyForwardType; | 119 typedef KeyConstRefType KeyForwardType; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 dst->clear(); | 211 dst->clear(); |
| 210 for (auto it = src.begin(); it != src.end(); ++it) | 212 for (auto it = src.begin(); it != src.end(); ++it) |
| 211 new ((*dst)[it->first].buf) Value(GetValue(it).Clone()); | 213 new ((*dst)[it->first].buf) Value(GetValue(it).Clone()); |
| 212 } | 214 } |
| 213 }; | 215 }; |
| 214 | 216 |
| 215 } // namespace internal | 217 } // namespace internal |
| 216 } // namespace mojo | 218 } // namespace mojo |
| 217 | 219 |
| 218 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_INTERNAL_H_ | 220 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_INTERNAL_H_ |
| OLD | NEW |