Skip to content

Commit

Permalink
update formatters (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
copperlight authored Nov 24, 2024
1 parent 7b137a5 commit 5a19037
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
9 changes: 3 additions & 6 deletions spectator/id.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,9 @@ struct equal_to<shared_ptr<spectator::Id>> {

} // namespace std

template <> struct fmt::formatter<spectator::Id> {
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }

// formatter: Id(c, {id->2, statistic->count})
template <typename format_context>
constexpr auto format(const spectator::Id& id, format_context& ctx) const {
// formatter: Id(c, {id->2, statistic->count})
template <> struct fmt::formatter<spectator::Id>: formatter<std::string_view> {
static auto format(const spectator::Id& id, format_context& ctx) -> format_context::iterator {
return fmt::format_to(ctx.out(), "Id({}, {})", id.Name(), id.GetTags());
}
};
9 changes: 3 additions & 6 deletions spectator/measurement.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ using Measurements = std::vector<Measurement>;

} // namespace spectator

template <> struct fmt::formatter<spectator::Measurement> {
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }

// formatter: Measurement{Id(c, {id->2, statistic->count}),1}
template <typename format_context>
constexpr auto format(const spectator::Measurement& m, format_context& ctx) const {
// formatter: Measurement{Id(c, {id->2, statistic->count}),1}
template <> struct fmt::formatter<spectator::Measurement>: formatter<std::string_view> {
static auto format(const spectator::Measurement& m, format_context& ctx) -> format_context::iterator {
return fmt::format_to(ctx.out(), "Measurement{{{}, {}}}", m.id, m.value);
}
};
11 changes: 4 additions & 7 deletions spectator/tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,9 @@ inline auto operator<<(std::ostream& os, const Tags& tags) -> std::ostream& {

} // namespace spectator

template <> struct fmt::formatter<spectator::Tag> {
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }

// Tag formatter: statistic->count
template <typename format_context>
constexpr auto format(const spectator::Tag& tag, format_context& ctx) const {
return fmt::format_to(ctx.out(), "{}->{}", tag.key, tag.value);
// formatter: statistic->count
template <> struct fmt::formatter<spectator::Tag>: formatter<std::string_view> {
static auto format(const spectator::Tag& tag, format_context& ctx) -> format_context::iterator {
return fmt::format_to(ctx.out(), "{}->{}", tag.key, tag.value);
}
};

0 comments on commit 5a19037

Please sign in to comment.