Vitaly Buka | 6fed053 | 2015-05-14 16:57:23 -0700 | [diff] [blame] | 1 | // Copyright 2014 The Chromium OS 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 | #include "buffet/commands/user_role.h" |
| 6 | |
| 7 | #include <chromeos/errors/error.h> |
| 8 | |
| 9 | #include "buffet/commands/enum_to_string.h" |
| 10 | #include "buffet/commands/schema_constants.h" |
| 11 | |
| 12 | namespace buffet { |
| 13 | |
| 14 | template <> |
| 15 | const EnumToString<UserRole>::Map EnumToString<UserRole>::kMap[] = { |
| 16 | {UserRole::kViewer, commands::attributes::kCommand_Role_Viewer}, |
| 17 | {UserRole::kUser, commands::attributes::kCommand_Role_User}, |
| 18 | {UserRole::kOwner, commands::attributes::kCommand_Role_Owner}, |
| 19 | {UserRole::kManager, commands::attributes::kCommand_Role_Manager}, |
| 20 | }; |
| 21 | |
| 22 | std::string ToString(UserRole role) { |
| 23 | return EnumToString<UserRole>::FindNameById(role); |
| 24 | } |
| 25 | |
| 26 | bool FromString(const std::string& str, |
| 27 | UserRole* role, |
| 28 | chromeos::ErrorPtr* error) { |
| 29 | if (EnumToString<UserRole>::FindIdByName(str, role)) |
| 30 | return true; |
| 31 | chromeos::Error::AddToPrintf(error, FROM_HERE, errors::commands::kDomain, |
| 32 | errors::commands::kInvalidPropValue, |
| 33 | "Invalid role: '%s'", str.c_str()); |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | } // namespace buffet |