Skip to content

Commit

Permalink
Fixed compilation with newer libfmt
Browse files Browse the repository at this point in the history
Newer fmt disabled automatic formatting of enums, see
fmtlib/fmt#1841
  • Loading branch information
davidmoreno committed Sep 24, 2023
1 parent 57903a7 commit 01cee80
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
68 changes: 68 additions & 0 deletions include/rtpmidid/rtppeer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,71 @@ class rtppeer {
void parse_journal_chapter_N(uint8_t channel, io_bytes_reader &);
};
} // namespace rtpmidid

template <>
struct fmt::formatter<rtpmidid::rtppeer::status_e>
: formatter<std::string_view> {
auto format(rtpmidid::rtppeer::status_e c, format_context &ctx) {
std::string_view name = "UNKNOWN";
switch (c) {
case rtpmidid::rtppeer::status_e::NOT_CONNECTED:
name = "NOT_CONNECTED";
break;
case rtpmidid::rtppeer::status_e::CONTROL_CONNECTED:
name = "CONTROL_CONNECTED";
break;
case rtpmidid::rtppeer::status_e::MIDI_CONNECTED:
name = "MIDI_CONNECTED";
break;
case rtpmidid::rtppeer::status_e::CONNECTED:
name = "CONNECTED";
break;
}
return formatter<std::string_view>::format(name, ctx);
}
};

template <>
struct fmt::formatter<rtpmidid::rtppeer::port_e> : formatter<std::string_view> {
auto format(rtpmidid::rtppeer::port_e c, format_context &ctx) {
std::string_view name = "UNKNOWN";
switch (c) {
case rtpmidid::rtppeer::port_e::MIDI_PORT:
name = "MIDI_PORT";
break;
case rtpmidid::rtppeer::port_e::CONTROL_PORT:
name = "CONTROL_PORT";
break;
}
return formatter<std::string_view>::format(name, ctx);
}
};

template <>
struct fmt::formatter<rtpmidid::rtppeer::disconnect_reason_e>
: formatter<std::string_view> {
auto format(rtpmidid::rtppeer::disconnect_reason_e c, format_context &ctx) {
std::string_view name = "UNKNOWN";
switch (c) {
case rtpmidid::rtppeer::disconnect_reason_e::CANT_CONNECT:
name = "CANT_CONNECT";
break;
case rtpmidid::rtppeer::disconnect_reason_e::PEER_DISCONNECTED:
name = "PEER_DISCONNECTED";
break;
case rtpmidid::rtppeer::disconnect_reason_e::CONNECTION_REJECTED:
name = "CONNECTON_REJECTED";
break;
case rtpmidid::rtppeer::disconnect_reason_e::DISCONNECT:
name = "DISCONNECT";
break;
case rtpmidid::rtppeer::disconnect_reason_e::CONNECT_TIMEOUT:
name = "CONNECT_TIMEOUT";
break;
case rtpmidid::rtppeer::disconnect_reason_e::CK_TIMEOUT:
name = "CK_TIMEOUT";
break;
}
return formatter<std::string_view>::format(name, ctx);
}
};
5 changes: 3 additions & 2 deletions lib/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ enum Color {
std::string color(const std::string_view &str, Color color,
bool highlight = false) {
int hl = highlight ? 1 : 0;
return fmt::format("\033[{};{}m{}\033[0m", hl, color, str);
return fmt::format("\033[{};{}m{}\033[0m", hl, (int)color, str);
}
std::string color(const std::string_view &str, Color color, Color bgcolor,
bool highlight = false) {
int hl = highlight ? 1 : 0;
return fmt::format("\033[{};{};{}m{}\033[0m", hl, color, bgcolor, str);
return fmt::format("\033[{};{};{}m{}\033[0m", hl, (int)color, (int)bgcolor,
str);
}

logger::logger() { is_a_terminal = isatty(fileno(stdout)); }
Expand Down
11 changes: 11 additions & 0 deletions lib/mdns_rtpmidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ struct AvahiEntryGroup {
char *name;
};

template <> struct fmt::formatter<AvahiWatchEvent> : fmt::formatter<int> {
auto format(AvahiWatchEvent ev, fmt::format_context &ctx) {
return fmt::formatter<int>::format((int)ev, ctx);
}
};
template <> struct fmt::formatter<AvahiBrowserEvent> : fmt::formatter<int> {
auto format(AvahiBrowserEvent ev, fmt::format_context &ctx) {
return fmt::formatter<int>::format((int)ev, ctx);
}
};

static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state,
AVAHI_GCC_UNUSED void *userdata) {
rtpmidid::mdns_rtpmidi *mr = (rtpmidid::mdns_rtpmidi *)userdata;
Expand Down

0 comments on commit 01cee80

Please sign in to comment.