| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "mojo/public/cpp/bindings/array.h" | 12 #include "mojo/public/cpp/bindings/array.h" |
| 13 #include "mojo/public/cpp/bindings/lib/template_util.h" | 13 #include "mojo/public/cpp/bindings/lib/template_util.h" |
| 14 | 14 |
| 15 namespace mojo { | 15 namespace mojo { |
| 16 namespace internal { | 16 namespace internal { |
| 17 | 17 |
| 18 template <typename Key, typename Value, bool kValueIsMoveOnlyType> | 18 template <typename Key, typename Value, bool kValueIsMoveOnlyType> |
| 19 struct MapTraits {}; | 19 struct MapCloneTraits {}; |
| 20 | 20 |
| 21 // Defines traits of a map for which Value is not a move-only type. | 21 // Defines traits of a map for which Value is not a move-only type. |
| 22 template <typename Key, typename Value> | 22 template <typename Key, typename Value> |
| 23 struct MapTraits<Key, Value, false> { | 23 struct MapCloneTraits<Key, Value, false> { |
| 24 static inline void Clone(const std::map<Key, Value>& src, | 24 static inline void Clone(const std::map<Key, Value>& src, |
| 25 std::map<Key, Value>* dst) { | 25 std::map<Key, Value>* dst) { |
| 26 dst->clear(); | 26 dst->clear(); |
| 27 for (auto it = src.begin(); it != src.end(); ++it) | 27 for (auto it = src.begin(); it != src.end(); ++it) |
| 28 dst->insert(*it); | 28 dst->insert(*it); |
| 29 } | 29 } |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 // Defines traits of a map for which Value is a move-only type. | 32 // Defines traits of a map for which Value is a move-only type. |
| 33 template <typename Key, typename Value> | 33 template <typename Key, typename Value> |
| 34 struct MapTraits<Key, Value, true> { | 34 struct MapCloneTraits<Key, Value, true> { |
| 35 static inline void Clone(const std::map<Key, Value>& src, | 35 static inline void Clone(const std::map<Key, Value>& src, |
| 36 std::map<Key, Value>* dst) { | 36 std::map<Key, Value>* dst) { |
| 37 dst->clear(); | 37 dst->clear(); |
| 38 for (auto it = src.begin(); it != src.end(); ++it) | 38 for (auto it = src.begin(); it != src.end(); ++it) |
| 39 dst->insert(std::make_pair(it->first, it->second.Clone())); | 39 dst->insert(std::make_pair(it->first, it->second.Clone())); |
| 40 } | 40 } |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 } // namespace internal | 43 } // namespace internal |
| 44 } // namespace mojo | 44 } // namespace mojo |
| 45 | 45 |
| 46 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_INTERNAL_H_ | 46 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_INTERNAL_H_ |
| OLD | NEW |