From c2ebae7dbbd1085cc03dcf113824d7af22c81091 Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 23 Jul 2018 10:53:50 +0200 Subject: [PATCH] make metric_type_t an enum class, deprecate the in-class enum values --- examples/stats_counters.cpp | 2 +- include/libtorrent/session_stats.hpp | 10 +++++++++- src/session_stats.cpp | 8 ++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/examples/stats_counters.cpp b/examples/stats_counters.cpp index 4b570d334..f05acaa92 100644 --- a/examples/stats_counters.cpp +++ b/examples/stats_counters.cpp @@ -42,7 +42,7 @@ int main() for (int i = 0; i < int(m.size()); ++i) { std::printf("%s: %s (%d)\n" - , m[i].type == stats_metric::type_counter ? "CNTR" : "GAUG" + , m[i].type == metric_type_t::counter ? "CNTR" : "GAUG" , m[i].name, m[i].value_index); } return 0; diff --git a/include/libtorrent/session_stats.hpp b/include/libtorrent/session_stats.hpp index f132c4c81..5d694c622 100644 --- a/include/libtorrent/session_stats.hpp +++ b/include/libtorrent/session_stats.hpp @@ -40,13 +40,21 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { + enum class metric_type_t + { + counter, gauge + }; + // describes one statistics metric from the session. For more information, // see the session-statistics_ section. struct TORRENT_EXPORT stats_metric { char const* name; int value_index; - enum metric_type_t { type_counter, type_gauge }; +#if TORRENT_ABI_VERSION == 1 + static constexpr metric_type_t TORRENT_DEPRECATED_MEMBER type_counter = metric_type_t::counter; + static constexpr metric_type_t TORRENT_DEPRECATED_MEMBER type_gauge = metric_type_t::gauge; +#endif metric_type_t type; }; diff --git a/src/session_stats.cpp b/src/session_stats.cpp index 42b582272..8144af343 100644 --- a/src/session_stats.cpp +++ b/src/session_stats.cpp @@ -39,8 +39,12 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { -namespace { +#if TORRENT_ABI_VERSION == 1 + constexpr metric_type_t stats_metric::type_counter; + constexpr metric_type_t stats_metric::type_gauge; +#endif +namespace { struct stats_metric_impl { @@ -566,7 +570,7 @@ namespace { stats[i].name = metrics[i].name; stats[i].value_index = metrics[i].value_index; stats[i].type = metrics[i].value_index >= counters::num_stats_counters - ? stats_metric::type_gauge : stats_metric::type_counter; + ? metric_type_t::gauge : metric_type_t::counter; } return std::move(stats); }