Skip to content

Commit

Permalink
fmt: update to v11.0.0 (#266)
Browse files Browse the repository at this point in the history
* fmt: update to v11.0.0 for significant performance and API improvements 🎉

* ensure format helpers are const

* fixing more of the types

* make format helper functions const

* revert change to abi_encoder from find-replace

* fix formatter parse function which cannot be const because it modifies presentation

* update format includes
  • Loading branch information
finger563 authored Jul 1, 2024
1 parent 9ac15bc commit c044871
Show file tree
Hide file tree
Showing 33 changed files with 222 additions and 148 deletions.
13 changes: 8 additions & 5 deletions components/adc/include/adc_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ static bool operator==(const AdcConfig &lhs, const AdcConfig &rhs) { return !(lh

// for libfmt printing of adc_unit_t
template <> struct fmt::formatter<adc_unit_t> : fmt::formatter<std::string> {
template <typename FormatContext> auto format(adc_unit_t t, FormatContext &ctx) {
template <typename FormatContext> auto format(adc_unit_t t, FormatContext &ctx) const {
return fmt::format_to(ctx.out(), "ADC_UNIT_{}", (int)t + 1);
}
};

// for libfmt printing of adc_channel_t
template <> struct fmt::formatter<adc_channel_t> : fmt::formatter<std::string> {
template <typename FormatContext> auto format(adc_channel_t t, FormatContext &ctx) {
template <typename FormatContext> auto format(adc_channel_t t, FormatContext &ctx) const {
return fmt::format_to(ctx.out(), "ADC_CHANNEL_{}", (int)t);
}
};

// for libfmt printing of adc_atten_t
template <> struct fmt::formatter<adc_atten_t> : fmt::formatter<std::string> {
template <typename FormatContext> auto format(adc_atten_t t, FormatContext &ctx) {
template <typename FormatContext> auto format(adc_atten_t t, FormatContext &ctx) const {
switch (t) {
case ADC_ATTEN_DB_0:
return fmt::format_to(ctx.out(), "ADC_ATTEN_DB_0");
Expand All @@ -55,9 +55,12 @@ template <> struct fmt::formatter<adc_atten_t> : fmt::formatter<std::string> {

// for easy serialization of AdcConfig with libfmt
template <> struct fmt::formatter<espp::AdcConfig> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext> auto format(const espp::AdcConfig &c, FormatContext &ctx) {
template <typename FormatContext>
auto format(const espp::AdcConfig &c, FormatContext &ctx) const {
return fmt::format_to(ctx.out(), "AdcConfig(unit={}, channel={}, attenuation={})", c.unit,
c.channel, c.attenuation);
}
Expand Down
36 changes: 24 additions & 12 deletions components/ads7138/include/ads7138.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1497,10 +1497,12 @@ class Ads7138 : public BasePeripheral<> {
// for allowing easy serialization/printing of the
// espp::Ads7138::OverSamplingRatio enum
template <> struct fmt::formatter<espp::Ads7138::OversamplingRatio> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext>
auto format(espp::Ads7138::OversamplingRatio const &ratio, FormatContext &ctx) {
auto format(espp::Ads7138::OversamplingRatio const &ratio, FormatContext &ctx) const {
switch (ratio) {
case espp::Ads7138::OversamplingRatio::NONE:
return fmt::format_to(ctx.out(), "NONE");
Expand All @@ -1527,10 +1529,12 @@ template <> struct fmt::formatter<espp::Ads7138::OversamplingRatio> {
// for allowing easy serialization/printing of the
// espp::Ads7138::Mode enum
template <> struct fmt::formatter<espp::Ads7138::Mode> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext>
auto format(espp::Ads7138::Mode const &mode, FormatContext &ctx) {
auto format(espp::Ads7138::Mode const &mode, FormatContext &ctx) const {
switch (mode) {
case espp::Ads7138::Mode::MANUAL:
return fmt::format_to(ctx.out(), "MANUAL");
Expand All @@ -1547,10 +1551,12 @@ template <> struct fmt::formatter<espp::Ads7138::Mode> {
// for allowing easy serialization/printing of the
// espp::Ads7138::DataFormat enum
template <> struct fmt::formatter<espp::Ads7138::DataFormat> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext>
auto format(espp::Ads7138::DataFormat const &format, FormatContext &ctx) {
auto format(espp::Ads7138::DataFormat const &format, FormatContext &ctx) const {
switch (format) {
case espp::Ads7138::DataFormat::RAW:
return fmt::format_to(ctx.out(), "RAW");
Expand All @@ -1565,10 +1571,12 @@ template <> struct fmt::formatter<espp::Ads7138::DataFormat> {
// for allowing easy serialization/printing of the
// espp::Ads7138::Append enum
template <> struct fmt::formatter<espp::Ads7138::Append> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext>
auto format(espp::Ads7138::Append const &format, FormatContext &ctx) {
auto format(espp::Ads7138::Append const &format, FormatContext &ctx) const {
switch (format) {
case espp::Ads7138::Append::NONE:
return fmt::format_to(ctx.out(), "NONE");
Expand All @@ -1585,10 +1593,12 @@ template <> struct fmt::formatter<espp::Ads7138::Append> {
// for allowing easy serialization/printing of the
// espp::Ads7138::Channel enum
template <> struct fmt::formatter<espp::Ads7138::Channel> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext>
auto format(espp::Ads7138::Channel const &ch, FormatContext &ctx) {
auto format(espp::Ads7138::Channel const &ch, FormatContext &ctx) const {
switch (ch) {
case espp::Ads7138::Channel::CH0:
return fmt::format_to(ctx.out(), "CH0");
Expand All @@ -1615,10 +1625,12 @@ template <> struct fmt::formatter<espp::Ads7138::Channel> {
// for allowing easy serialization/printing of a
// std::vector<espp::Ads7138::Channel> object
template <> struct fmt::formatter<std::vector<espp::Ads7138::Channel>> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext>
auto format(std::vector<espp::Ads7138::Channel> const &channels, FormatContext &ctx) {
auto format(std::vector<espp::Ads7138::Channel> const &channels, FormatContext &ctx) const {
std::string result = "{";
for (auto const &ch : channels) {
result += fmt::format("{}, ", ch);
Expand Down
6 changes: 4 additions & 2 deletions components/bldc_haptics/include/detent_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ static const DetentConfig RETURN_TO_CENTER_WITH_DETENTS = {
// for allowing easy serialization/printing of the
// DetentConfig
template <> struct fmt::formatter<espp::detail::DetentConfig> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext>
auto format(espp::detail::DetentConfig const &detent_config, FormatContext &ctx) {
auto format(espp::detail::DetentConfig const &detent_config, FormatContext &ctx) const {
return fmt::format_to(ctx.out(),
"DetentConfig:\n"
"\tposition_width: {} radians ({} degrees)\n"
Expand Down
12 changes: 6 additions & 6 deletions components/bldc_motor/include/bldc_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ enum class FocType {

// for easy printing of enums using fmt
template <> struct fmt::formatter<espp::detail::MotionControlType> {
constexpr auto parse(format_parse_context &ctx) { return ctx.begin(); }
constexpr auto parse(format_parse_context &ctx) const { return ctx.begin(); }

template <typename FormatContext>
auto format(espp::detail::MotionControlType t, FormatContext &ctx) {
auto format(espp::detail::MotionControlType t, FormatContext &ctx) const {
switch (t) {
case espp::detail::MotionControlType::TORQUE:
return fmt::format_to(ctx.out(), "TORQUE");
Expand All @@ -64,10 +64,10 @@ template <> struct fmt::formatter<espp::detail::MotionControlType> {
};

template <> struct fmt::formatter<espp::detail::TorqueControlType> {
constexpr auto parse(format_parse_context &ctx) { return ctx.begin(); }
constexpr auto parse(format_parse_context &ctx) const { return ctx.begin(); }

template <typename FormatContext>
auto format(espp::detail::TorqueControlType t, FormatContext &ctx) {
auto format(espp::detail::TorqueControlType t, FormatContext &ctx) const {
switch (t) {
case espp::detail::TorqueControlType::VOLTAGE:
return fmt::format_to(ctx.out(), "VOLTAGE");
Expand All @@ -82,9 +82,9 @@ template <> struct fmt::formatter<espp::detail::TorqueControlType> {
};

template <> struct fmt::formatter<espp::detail::FocType> {
constexpr auto parse(format_parse_context &ctx) { return ctx.begin(); }
constexpr auto parse(format_parse_context &ctx) const { return ctx.begin(); }

template <typename FormatContext> auto format(espp::detail::FocType t, FormatContext &ctx) {
template <typename FormatContext> auto format(espp::detail::FocType t, FormatContext &ctx) const {
switch (t) {
case espp::detail::FocType::SINE_PWM:
return fmt::format_to(ctx.out(), "SINE_PWM");
Expand Down
4 changes: 2 additions & 2 deletions components/bldc_motor/include/sensor_direction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ enum class SensorDirection {

// for printing SensorDirection using libfmt
template <> struct fmt::formatter<espp::detail::SensorDirection> {
constexpr auto parse(format_parse_context &ctx) { return ctx.begin(); }
constexpr auto parse(format_parse_context &ctx) const { return ctx.begin(); }

template <typename FormatContext>
auto format(espp::detail::SensorDirection dir, FormatContext &ctx) {
auto format(espp::detail::SensorDirection dir, FormatContext &ctx) const {
switch (dir) {
case espp::detail::SensorDirection::CLOCKWISE:
return fmt::format_to(ctx.out(), "CLOCKWISE");
Expand Down
8 changes: 4 additions & 4 deletions components/ble_gatt_server/include/ble_gatt_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,10 +685,10 @@ class BleGattServer : public BaseComponent {
#if !CONFIG_BT_NIMBLE_EXT_ADV || defined(_DOXYGEN_)
// for easy printing of the advertising parameters using libfmt
template <> struct fmt::formatter<espp::BleGattServer::AdvertisingParameters> {
constexpr auto parse(format_parse_context &ctx) { return ctx.begin(); }
constexpr auto parse(format_parse_context &ctx) const { return ctx.begin(); }
template <typename FormatContext>
auto format(const espp::BleGattServer::AdvertisingParameters &advertising_params,
FormatContext &ctx) {
FormatContext &ctx) const {
if (advertising_params.directed_address) {
return fmt::format_to(
ctx.out(),
Expand All @@ -711,9 +711,9 @@ template <> struct fmt::formatter<espp::BleGattServer::AdvertisingParameters> {

// for easy printing of the DisconnectReason enum using libfmt
template <> struct fmt::formatter<espp::BleGattServer::DisconnectReason> {
constexpr auto parse(format_parse_context &ctx) { return ctx.begin(); }
constexpr auto parse(format_parse_context &ctx) const { return ctx.begin(); }
template <typename FormatContext>
auto format(const espp::BleGattServer::DisconnectReason &reason, FormatContext &ctx) {
auto format(const espp::BleGattServer::DisconnectReason &reason, FormatContext &ctx) const {
switch (reason) {
case espp::BleGattServer::DisconnectReason::UNKNOWN:
return fmt::format_to(ctx.out(), "UNKNOWN");
Expand Down
20 changes: 14 additions & 6 deletions components/bm8563/include/bm8563.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,28 +192,36 @@ class Bm8563 : public BasePeripheral<> {
// for allowing easy serialization/printing of the
// espp::Bm8563::Date, espp::Bm8563::Time, and espp::Bm8563::DateTime
template <> struct fmt::formatter<espp::Bm8563::Date> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext> auto format(espp::Bm8563::Date const &d, FormatContext &ctx) {
template <typename FormatContext>
auto format(espp::Bm8563::Date const &d, FormatContext &ctx) const {
return fmt::format_to(ctx.out(), "{{.year = {}, .month = {}, .weekday = {}, .day = {}}}",
d.year, d.month, d.weekday, d.day);
}
};

template <> struct fmt::formatter<espp::Bm8563::Time> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext> auto format(espp::Bm8563::Time const &t, FormatContext &ctx) {
template <typename FormatContext>
auto format(espp::Bm8563::Time const &t, FormatContext &ctx) const {
return fmt::format_to(ctx.out(), "{{.hour = {}, .minute = {}, .second = {}}}", t.hour, t.minute,
t.second);
}
};

template <> struct fmt::formatter<espp::Bm8563::DateTime> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext>
auto format(espp::Bm8563::DateTime const &dt, FormatContext &ctx) {
auto format(espp::Bm8563::DateTime const &dt, FormatContext &ctx) const {
return fmt::format_to(ctx.out(), "{{.date = {}, .time = {}}}", dt.date, dt.time);
}
};
12 changes: 8 additions & 4 deletions components/color/include/color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,23 @@ class Hsv {
// for allowing easy serialization/printing of the
// Rgb
template <> struct fmt::formatter<espp::Rgb> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext> auto format(espp::Rgb const &rgb, FormatContext &ctx) {
template <typename FormatContext> auto format(espp::Rgb const &rgb, FormatContext &ctx) const {
return fmt::format_to(ctx.out(), "({}, {}, {})", rgb.r, rgb.g, rgb.b);
}
};

// for allowing easy serialization/printing of the
// Rgb
template <> struct fmt::formatter<espp::Hsv> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext> auto format(espp::Hsv const &hsv, FormatContext &ctx) {
template <typename FormatContext> auto format(espp::Hsv const &hsv, FormatContext &ctx) const {
return fmt::format_to(ctx.out(), "({}, {}, {})", hsv.h, hsv.s, hsv.v);
}
};
14 changes: 8 additions & 6 deletions components/drv2605/include/drv2605.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ class Drv2605 : public BasePeripheral<> {

// for easy printing of the enums with the libfmt library:
template <> struct fmt::formatter<espp::Drv2605::Mode> {
constexpr auto parse(format_parse_context &ctx) { return ctx.begin(); }
constexpr auto parse(format_parse_context &ctx) const { return ctx.begin(); }

template <typename FormatContext> auto format(espp::Drv2605::Mode m, FormatContext &ctx) {
template <typename FormatContext> auto format(espp::Drv2605::Mode m, FormatContext &ctx) const {
switch (m) {
case espp::Drv2605::Mode::INTTRIG:
return fmt::format_to(ctx.out(), "INTTRIG");
Expand All @@ -303,9 +303,10 @@ template <> struct fmt::formatter<espp::Drv2605::Mode> {
};

template <> struct fmt::formatter<espp::Drv2605::Waveform> {
constexpr auto parse(format_parse_context &ctx) { return ctx.begin(); }
constexpr auto parse(format_parse_context &ctx) const { return ctx.begin(); }

template <typename FormatContext> auto format(espp::Drv2605::Waveform w, FormatContext &ctx) {
template <typename FormatContext>
auto format(espp::Drv2605::Waveform w, FormatContext &ctx) const {
switch (w) {
case espp::Drv2605::Waveform::END:
return fmt::format_to(ctx.out(), "END");
Expand Down Expand Up @@ -352,9 +353,10 @@ template <> struct fmt::formatter<espp::Drv2605::Waveform> {
};

template <> struct fmt::formatter<espp::Drv2605::Library> {
constexpr auto parse(format_parse_context &ctx) { return ctx.begin(); }
constexpr auto parse(format_parse_context &ctx) const { return ctx.begin(); }

template <typename FormatContext> auto format(espp::Drv2605::Library l, FormatContext &ctx) {
template <typename FormatContext>
auto format(espp::Drv2605::Library l, FormatContext &ctx) const {
switch (l) {
case espp::Drv2605::Library::EMPTY:
return fmt::format_to(ctx.out(), "EMPTY");
Expand Down
4 changes: 2 additions & 2 deletions components/esp-box/include/esp-box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class EspBox : public BaseComponent {

// for easy printing of BoxType using libfmt
template <> struct fmt::formatter<espp::EspBox::BoxType> : fmt::formatter<std::string> {
template <typename FormatContext> auto format(espp::EspBox::BoxType c, FormatContext &ctx) {
template <typename FormatContext> auto format(espp::EspBox::BoxType c, FormatContext &ctx) const {
std::string name;
switch (c) {
case espp::EspBox::BoxType::UNKNOWN:
Expand All @@ -411,7 +411,7 @@ template <> struct fmt::formatter<espp::EspBox::BoxType> : fmt::formatter<std::s
// for easy printing of TouchpadData using libfmt
template <> struct fmt::formatter<espp::EspBox::TouchpadData> : fmt::formatter<std::string> {
template <typename FormatContext>
auto format(const espp::EspBox::TouchpadData &c, FormatContext &ctx) {
auto format(const espp::EspBox::TouchpadData &c, FormatContext &ctx) const {
return fmt::format_to(ctx.out(),
"TouchpadData{{num_touch_points={}, x={}, y={}, btn_state={}}}",
c.num_touch_points, c.x, c.y, c.btn_state);
Expand Down
12 changes: 8 additions & 4 deletions components/filters/include/biquad_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,25 @@ class BiquadFilterDf2 {
// for allowing easy serialization/printing of the
// espp::BiquadFilterDf1
template <> struct fmt::formatter<espp::BiquadFilterDf1> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext>
auto format(espp::BiquadFilterDf1 const &bqf, FormatContext &ctx) {
auto format(espp::BiquadFilterDf1 const &bqf, FormatContext &ctx) const {
return fmt::format_to(ctx.out(), "DF1 - B: {}, A: {}", bqf.b_, bqf.a_);
}
};

// for allowing easy serialization/printing of the
// espp::BiquadFilterDf2
template <> struct fmt::formatter<espp::BiquadFilterDf2> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext>
auto format(espp::BiquadFilterDf2 const &bqf, FormatContext &ctx) {
auto format(espp::BiquadFilterDf2 const &bqf, FormatContext &ctx) const {
return fmt::format_to(ctx.out(), "DF2 - B: {}, A: {}", bqf.b_, bqf.a_);
}
};
6 changes: 4 additions & 2 deletions components/filters/include/butterworth_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ class ButterworthFilter : public SosFilter<(ORDER + 1) / 2, Impl> {
// for allowing easy serialization/printing of the
// espp::ButterworthFilter
template <size_t ORDER, class Impl> struct fmt::formatter<espp::ButterworthFilter<ORDER, Impl>> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext>
auto format(espp::ButterworthFilter<ORDER, Impl> const &f, FormatContext &ctx) {
auto format(espp::ButterworthFilter<ORDER, Impl> const &f, FormatContext &ctx) const {
auto &&out = ctx.out();
fmt::format_to(out, "Butterworth - [");
if constexpr (ORDER > 0) {
Expand Down
Loading

0 comments on commit c044871

Please sign in to comment.