diff --git a/include/dwarfs/fragment_category.h b/include/dwarfs/fragment_category.h index 4425bb8e..3568bc77 100644 --- a/include/dwarfs/fragment_category.h +++ b/include/dwarfs/fragment_category.h @@ -24,9 +24,12 @@ #include #include #include +#include #include +#include + namespace dwarfs { class fragment_category { @@ -101,8 +104,41 @@ class fragment_category { 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 +template <> +struct fmt::formatter : formatter { + template + auto format(dwarfs::fragment_category const& cat, FormatContext& ctx) { + if (cat) { + if (cat.has_subcategory()) { + return formatter::format( + fmt::format("{}.{}", cat.value(), cat.subcategory()), ctx); + } else { + return formatter::format(fmt::format("{}", cat.value()), + ctx); + } + } else { + return formatter::format("uninitialized", ctx); + } + } +}; + namespace std { template <>