mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-10 04:50:31 -04:00
refactor: ostream/format support for fragment_category
This commit is contained in:
parent
d938191248
commit
4ad155e19f
@ -24,9 +24,12 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
#include <folly/hash/Hash.h>
|
#include <folly/hash/Hash.h>
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
namespace dwarfs {
|
namespace dwarfs {
|
||||||
|
|
||||||
class fragment_category {
|
class fragment_category {
|
||||||
@ -101,8 +104,41 @@ class fragment_category {
|
|||||||
value_type subcategory_{uninitialized};
|
value_type subcategory_{uninitialized};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline std::ostream&
|
||||||
|
operator<<(std::ostream& os, fragment_category const& cat) {
|
||||||
|
if (cat) {
|
||||||
|
os << cat.value();
|
||||||
|
|
||||||
|
if (cat.has_subcategory()) {
|
||||||
|
os << '.' << cat.subcategory();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
os << "uninitialized";
|
||||||
|
}
|
||||||
|
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dwarfs
|
} // namespace dwarfs
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct fmt::formatter<dwarfs::fragment_category> : formatter<std::string> {
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(dwarfs::fragment_category const& cat, FormatContext& ctx) {
|
||||||
|
if (cat) {
|
||||||
|
if (cat.has_subcategory()) {
|
||||||
|
return formatter<std::string>::format(
|
||||||
|
fmt::format("{}.{}", cat.value(), cat.subcategory()), ctx);
|
||||||
|
} else {
|
||||||
|
return formatter<std::string>::format(fmt::format("{}", cat.value()),
|
||||||
|
ctx);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return formatter<std::string>::format("uninitialized", ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user