-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathflag_set.cpp
41 lines (36 loc) · 1.11 KB
/
flag_set.cpp
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
#include "databento/flag_set.hpp"
#include <array>
#include "stream_op_helper.hpp"
namespace databento {
std::ostream& operator<<(std::ostream& stream, FlagSet flag_set) {
const std::array<std::pair<bool (FlagSet::*)() const, const char*>, 6>
kFlagsAndNames = {{
{&FlagSet::IsLast, "LAST"},
{&FlagSet::IsTob, "TOB"},
{&FlagSet::IsSnapshot, "SNAPSHOT"},
{&FlagSet::IsMbp, "MBP"},
{&FlagSet::IsBadTsRecv, "BAD_TS_RECV"},
{&FlagSet::IsMaybeBadBook, "MAYBE_BAD_BOOK"},
}};
bool has_written_flag = false;
for (const auto& [flag, name] : kFlagsAndNames) {
if ((flag_set.*flag)()) {
if (has_written_flag) {
stream << " | " << name;
} else {
stream << name;
has_written_flag = true;
}
}
}
// Cast to uint16_t to avoid being formatted as char
const auto raw = static_cast<std::uint16_t>(flag_set.Raw());
if (has_written_flag) {
stream << " (" << raw << ')';
} else {
stream << raw;
}
return stream;
}
std::string ToString(FlagSet flags) { return MakeString(flags); }
} // namespace databento