Home | History | Annotate | Download | only in display
      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, const std::string& v1,
     19                                             T k2, const std::string& v2,
     20                                             T k3, const std::string& v3,
     21                                             T k4, const std::string& v4) {
     22   std::map<T, std::string>* map = new std::map<T, std::string>();
     23   (*map)[k1] = v1;
     24   (*map)[k2] = v2;
     25   (*map)[k3] = v3;
     26   (*map)[k4] = v4;
     27   return map;
     28 }
     29 
     30 template<typename T>
     31 std::map<T, std::string>* CreateToStringMap(T k1, const std::string& v1,
     32                                             T k2, const std::string& v2,
     33                                             T k3, const std::string& v3) {
     34   std::map<T, std::string>* map = new std::map<T, std::string>();
     35   (*map)[k1] = v1;
     36   (*map)[k2] = v2;
     37   (*map)[k3] = v3;
     38   return map;
     39 }
     40 
     41 template<typename T>
     42 bool ReverseFind(const std::map<T, std::string>* map,
     43                  const base::StringPiece& value,
     44                  T* key) {
     45   typename std::map<T, std::string>::const_iterator iter = map->begin();
     46   for (;
     47        iter != map->end();
     48        ++iter) {
     49     if (iter->second == value) {
     50       *key = iter->first;
     51       return true;
     52     }
     53   }
     54   return false;
     55 }
     56 
     57 }  // namespace ash
     58 
     59 #endif  // ASH_DISPLAY_DISPLAY_PREF_UTIL_H
     60