1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
/*
** Copyright (C) 2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
** Free Software Foundation; either version 3, or (at your option) any
** later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software Foundation,
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
*/
#ifndef MU_PRIORITY_HH__
#define MU_PRIORITY_HH__
#include <array>
#include <string>
#include <string_view>
#include "mu-fields.hh"
namespace Mu {
/**
* Message priorities
*
*/
/**
* The priority ids
*
*/
enum struct Priority : char {
Low = 'l', /**< Low priority */
Normal = 'n', /**< Normal priority */
High = 'h', /**< High priority */
};
/**
* Sequence of all message priorities.
*/
static constexpr std::array<Priority, 3> AllMessagePriorities = {
Priority::Low, Priority::Normal, Priority::High};
/**
* Get the char for some priority
*
* @param id an id
*
* @return the char
*/
constexpr char
to_char(Priority prio)
{
return static_cast<char>(prio);
}
/**
* Get the priority for some character; unknown ones
* become Normal.
*
* @param c some character
*/
constexpr Priority
priority_from_char(char c)
{
switch (c) {
case 'l':
return Priority::Low;
case 'h':
return Priority::High;
case 'n':
default:
return Priority::Normal;
}
}
/**
* Get the priority from their (internal) name, i.e., low/normal/high
* or shortcut.
*
* @param pname
*
* @return the priority or none
*/
static inline Option<Priority>
priority_from_name(std::string_view pname)
{
if (pname == "low" || pname == "l")
return Priority::Low;
else if (pname == "high" || pname == "h")
return Priority::High;
else if (pname == "normal" || pname == "n")
return Priority::Normal;
else
return Nothing;
}
/**
* Get the name for a given priority
*
* @return the name
*/
constexpr std::string_view
priority_name(Priority prio)
{
switch (prio) {
case Priority::Low:
return "low";
case Priority::High:
return "high";
case Priority::Normal:
default:
return "normal";
}
}
/**
* Get the name for a given priority (backward compatibility)
*
* @return the name
*/
constexpr const char*
priority_name_c_str(Priority prio)
{
switch (prio) {
case Priority::Low:
return "low";
case Priority::High:
return "high";
case Priority::Normal:
default:
return "normal";
}
}
/**
* Get a the message priority as a string
*
* @param prio priority
*
* @return a string
*/
std::string to_string(Priority prio);
} // namespace Mu
#endif /*MU_PRIORITY_HH_*/
|