rockot | 85dce086 | 2015-11-13 01:33:59 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ |
| 6 | #define MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ |
| 7 | |
rockot | 85dce086 | 2015-11-13 01:33:59 | [diff] [blame] | 8 | #include <map> |
dcheng | aa6492d | 2015-12-26 04:46:36 | [diff] [blame] | 9 | #include <utility> |
rockot | 85dce086 | 2015-11-13 01:33:59 | [diff] [blame] | 10 | |
Ken Rockot | 08942735 | 2018-04-24 14:51:37 | [diff] [blame] | 11 | #include "base/containers/flat_map.h" |
| 12 | |
rockot | 85dce086 | 2015-11-13 01:33:59 | [diff] [blame] | 13 | namespace mojo { |
| 14 | |
yzshen | 6a5ee17d | 2016-11-21 17:43:28 | [diff] [blame] | 15 | // TODO(yzshen): These conversion functions should be removed and callsites |
| 16 | // should be revisited and changed to use the same map type. |
| 17 | template <typename Key, typename Value> |
Ken Rockot | 08942735 | 2018-04-24 14:51:37 | [diff] [blame] | 18 | base::flat_map<Key, Value> MapToFlatMap(const std::map<Key, Value>& input) { |
| 19 | return base::flat_map<Key, Value>(input.begin(), input.end()); |
yzshen | 6a5ee17d | 2016-11-21 17:43:28 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | template <typename Key, typename Value> |
Ken Rockot | 08942735 | 2018-04-24 14:51:37 | [diff] [blame] | 23 | base::flat_map<Key, Value> MapToFlatMap(std::map<Key, Value>&& input) { |
| 24 | return base::flat_map<Key, Value>(std::make_move_iterator(input.begin()), |
| 25 | std::make_move_iterator(input.end())); |
yzshen | 6a5ee17d | 2016-11-21 17:43:28 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | template <typename Key, typename Value> |
Ken Rockot | 08942735 | 2018-04-24 14:51:37 | [diff] [blame] | 29 | std::map<Key, Value> FlatMapToMap(const base::flat_map<Key, Value>& input) { |
yzshen | 6a5ee17d | 2016-11-21 17:43:28 | [diff] [blame] | 30 | return std::map<Key, Value>(input.begin(), input.end()); |
| 31 | } |
| 32 | |
| 33 | template <typename Key, typename Value> |
Ken Rockot | 08942735 | 2018-04-24 14:51:37 | [diff] [blame] | 34 | std::map<Key, Value> FlatMapToMap(base::flat_map<Key, Value>&& input) { |
yzshen | 6a5ee17d | 2016-11-21 17:43:28 | [diff] [blame] | 35 | return std::map<Key, Value>(std::make_move_iterator(input.begin()), |
| 36 | std::make_move_iterator(input.end())); |
| 37 | } |
| 38 | |
rockot | 85dce086 | 2015-11-13 01:33:59 | [diff] [blame] | 39 | } // namespace mojo |
| 40 | |
| 41 | #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ |