libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
utils.hxx
1#pragma once
2
3// C++
4#include <sstream>
5#include <string>
6
7// cosmos
8#include <cosmos/formatting.hxx>
9
10namespace clues {
11
12inline std::string strip_back(std::string &&s, const char ch = '|') {
13 if (s.back() == ch)
14 s.pop_back();
15 return s;
16}
17
19#define BITFLAGS_FORMAT_START(bitmask) std::stringstream _bf_ss; auto _flags = bitmask.raw(); \
20 _bf_ss << cosmos::HexNum<decltype(bitmask)::EnumBaseType>{_flags, 0} << " ("
22
28#define BITFLAGS_FORMAT_START_COMBINED(bitmask, raw_val) std::stringstream _bf_ss; \
29 auto _flags = bitmask.raw(); \
30 _bf_ss << cosmos::HexNum<decltype(raw_val)>{raw_val, 0} << " ("
31#define BITFLAGS_STREAM() _bf_ss
32#define BITFLAGS_ADD(FLAG) if (FLAG && (_flags & FLAG) == FLAG) _bf_ss << #FLAG << '|'
33#define BITFLAGS_STR() strip_back(_bf_ss.str()) + ")"
34
35} // end ns