| // Copyright 2015 The Chromium OS Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| #ifndef BUFFET_COMMANDS_ENUM_TO_STRING_H_ |
| #define BUFFET_COMMANDS_ENUM_TO_STRING_H_ |
| // Helps to map enumeration to stings and back. |
| // enum class MyEnum { kV1, kV2 }; |
| // std::string ToString(MyEnum id); |
| // bool FromString(const std::string& str, MyEnum* id); |
| // const EnumToString<MyEnum>::Map EnumToString<MyEnum>::kMap[] = { |
| // std::string ToString(MyEnum id) { |
| // return EnumToString<MyEnum>::FindNameById(id); |
| // bool FromString(const std::string& str, MyEnum* id) { |
| // return EnumToString<MyEnum>::FindIdByName(str, id)); |
| class EnumToString final { |
| static std::string FindNameById(T id) { |
| for (const Map& m : kMap) { |
| static bool FindIdByName(const std::string& name, T* id) { |
| for (const Map& m : kMap) { |
| if (m.name && m.name == name) { |
| #endif // BUFFET_COMMANDS_ENUM_TO_STRING_H_ |