UserRole.h
Go to the documentation of this file.
1 /****
2  * UserRole.h
3  *
4  * Created on: 6 Jun 2018
5  *
6  * Copyright 2019 mikee47 <mike@sillyhouse.net>
7  *
8  * This file is part of the IFS Library
9  *
10  * This library is free software: you can redistribute it and/or modify it under the terms of the
11  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  * See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with this library.
18  * If not, see <https://www.gnu.org/licenses/>.
19  *
20  ****/
21 
22 #pragma once
23 
24 #include "Types.h"
25 
26 namespace IFS
27 {
28 // Access Control level
29 #define IFS_USER_ROLE_MAP(XX) \
30  XX(None, -, "No assigned role") \
31  XX(Guest, g, "User-type access without authentication") \
32  XX(User, u, "Normal user") \
33  XX(Manager, m, "Perform restricted system functions, reset user passwords, etc.") \
34  XX(Admin, a, "Full access")
35 
36 enum class UserRole : uint8_t {
37 #define XX(_tag, _char, _comment) _tag,
39 #undef XX
40  MAX
41 };
42 
50 UserRole getUserRole(const char* str, UserRole defaultRole);
51 
52 inline UserRole getUserRole(const String& str, UserRole defaultRole)
53 {
54  return getUserRole(str.c_str(), defaultRole);
55 }
58 /*
59  * @brief Get the character code representing the given access type
60  * @param role
61  * @retval char
62  */
63 char getChar(UserRole role);
64 
65 /*
66  * @brief Return the access type corresponding to the given code.
67  * @param code
68  * @param defaultRole Returned if code isn't recognised
69  * @retval UserRole
70  */
71 UserRole getUserRole(char code, UserRole defaultRole);
72 
73 } // namespace IFS
74 
75 /*
76  * Get the string representation for the given access type.
77  */
String toString(IFS::UserRole role)
char getChar(UserRole role)
The String class.
Definition: WString.h:136
#define str(s)
Definition: testrunner.h:124
@ MAX
Actually maxmimum value + 1...
UserRole getUserRole(const char *str, UserRole defaultRole)
#define IFS_USER_ROLE_MAP(XX)
Definition: UserRole.h:48
XX(_tag, _char, _comment)
Definition: DirectoryTemplate.h:36
UserRole
Definition: UserRole.h:55