make metric_type_t an enum class, deprecate the in-class enum values

This commit is contained in:
arvidn 2018-07-23 10:53:50 +02:00 committed by Arvid Norberg
parent acbe3c1880
commit c2ebae7dbb
3 changed files with 16 additions and 4 deletions

View File

@ -42,7 +42,7 @@ int main()
for (int i = 0; i < int(m.size()); ++i) for (int i = 0; i < int(m.size()); ++i)
{ {
std::printf("%s: %s (%d)\n" 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); , m[i].name, m[i].value_index);
} }
return 0; return 0;

View File

@ -40,13 +40,21 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent { namespace libtorrent {
enum class metric_type_t
{
counter, gauge
};
// describes one statistics metric from the session. For more information, // describes one statistics metric from the session. For more information,
// see the session-statistics_ section. // see the session-statistics_ section.
struct TORRENT_EXPORT stats_metric struct TORRENT_EXPORT stats_metric
{ {
char const* name; char const* name;
int value_index; 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; metric_type_t type;
}; };

View File

@ -39,8 +39,12 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent { 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 struct stats_metric_impl
{ {
@ -566,7 +570,7 @@ namespace {
stats[i].name = metrics[i].name; stats[i].name = metrics[i].name;
stats[i].value_index = metrics[i].value_index; stats[i].value_index = metrics[i].value_index;
stats[i].type = metrics[i].value_index >= counters::num_stats_counters 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); return std::move(stats);
} }