| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 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 ASH_DISPLAY_DISPLAY_PREF_UTIL_H | |
| 6 #define ASH_DISPLAY_DISPLAY_PREF_UTIL_H | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/strings/string_piece.h" | |
| 12 | |
| 13 namespace ash { | |
| 14 | |
| 15 // Utility templates to create enum to string map and | |
| 16 // a function to find an enum value from a string. | |
| 17 template <typename T> | |
| 18 std::map<T, std::string>* CreateToStringMap(T k1, | |
| 19 const std::string& v1, | |
| 20 T k2, | |
| 21 const std::string& v2, | |
| 22 T k3, | |
| 23 const std::string& v3, | |
| 24 T k4, | |
| 25 const std::string& v4) { | |
| 26 std::map<T, std::string>* map = new std::map<T, std::string>(); | |
| 27 (*map)[k1] = v1; | |
| 28 (*map)[k2] = v2; | |
| 29 (*map)[k3] = v3; | |
| 30 (*map)[k4] = v4; | |
| 31 return map; | |
| 32 } | |
| 33 | |
| 34 template <typename T> | |
| 35 std::map<T, std::string>* CreateToStringMap(T k1, | |
| 36 const std::string& v1, | |
| 37 T k2, | |
| 38 const std::string& v2, | |
| 39 T k3, | |
| 40 const std::string& v3) { | |
| 41 std::map<T, std::string>* map = new std::map<T, std::string>(); | |
| 42 (*map)[k1] = v1; | |
| 43 (*map)[k2] = v2; | |
| 44 (*map)[k3] = v3; | |
| 45 return map; | |
| 46 } | |
| 47 | |
| 48 template <typename T> | |
| 49 bool ReverseFind(const std::map<T, std::string>* map, | |
| 50 const base::StringPiece& value, | |
| 51 T* key) { | |
| 52 typename std::map<T, std::string>::const_iterator iter = map->begin(); | |
| 53 for (; iter != map->end(); ++iter) { | |
| 54 if (iter->second == value) { | |
| 55 *key = iter->first; | |
| 56 return true; | |
| 57 } | |
| 58 } | |
| 59 return false; | |
| 60 } | |
| 61 | |
| 62 } // namespace ash | |
| 63 | |
| 64 #endif // ASH_DISPLAY_DISPLAY_PREF_UTIL_H | |
| OLD | NEW |