-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathcheck_flags.cpp
More file actions
51 lines (45 loc) · 1.26 KB
/
check_flags.cpp
File metadata and controls
51 lines (45 loc) · 1.26 KB
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
#include <bit>
#include <cstdint>
#include <iostream>
#include <utility>
enum class CheckFlags : uint8_t {
NONE = 0,
TIME = (1 << 0),
DATE = (1 << 1),
USER = (1 << 2),
CERT = (1 << 3),
KEYS = (1 << 4),
DEST = (1 << 5),
ALL = TIME | DATE | USER | CERT | KEYS | DEST
};
void PrintCheckFlags(CheckFlags flags) {
constexpr static const auto all { static_cast<uint8_t>(CheckFlags::ALL) };
const auto value { static_cast<uint8_t>(flags) };
// Есть биты вне диапазона
if ((value & ~all) != 0) {
std::cout << "";
return;
}
if (value == static_cast<uint8_t>(CheckFlags::NONE)) {
std::cout << "[]";
return;
}
std::string out {'['};
bool first { true };
for (uint8_t i = 0; std::cmp_less(i, std::popcount(all)); ++i) {
if ((value & (1u << i)) != 0) {
if (!first) out += ',';
switch (i) {
case 0: out += "TIME"; break;
case 1: out += "DATE"; break;
case 2: out += "USER"; break;
case 3: out += "CERT"; break;
case 4: out += "KEYS"; break;
case 5: out += "DEST"; break;
}
first = false;
}
}
out += ']';
std::cout << out;
}