-
Notifications
You must be signed in to change notification settings - Fork 0
/
enum-util.cc
45 lines (35 loc) · 857 Bytes
/
enum-util.cc
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
// enum-util.cc
// Code for enum-util.h.
#include "enum-util.h" // this module
#include <sstream> // std::ostringstream
// Stringify 'flags' as a '|'-separated sequence of flag names.
std::string bitflagsString(
BitflagsEntry const *beginEntries,
BitflagsEntry const *endEntries,
unsigned flags,
char const *typeName,
char const *zeroName)
{
std::ostringstream oss;
int ct=0;
for (BitflagsEntry const *e = beginEntries; e < endEntries; ++e) {
if (e->m_flag & flags) {
if (ct++ > 0) {
oss << '|';
}
oss << e->m_name;
flags &= ~e->m_flag;
}
}
if (flags) {
if (ct++ > 0) {
oss << '|';
}
oss << typeName << "(0x" << std::hex << flags << ")";
}
if (ct == 0) {
oss << zeroName;
}
return oss.str();
}
// EOF