diff --git a/api/stats/rtc_stats.h b/api/stats/rtc_stats.h index 2af9768a99..535e6fb345 100644 --- a/api/stats/rtc_stats.h +++ b/api/stats/rtc_stats.h @@ -258,7 +258,9 @@ class RTCStatsMemberInterface { virtual std::vector group_ids() const { return {}; } // Type and value comparator. The names are not compared. These operators are // exposed for testing. - virtual bool operator==(const RTCStatsMemberInterface& other) const = 0; + bool operator==(const RTCStatsMemberInterface& other) const { + return IsEqual(other); + } bool operator!=(const RTCStatsMemberInterface& other) const { return !(*this == other); } @@ -280,6 +282,8 @@ class RTCStatsMemberInterface { RTCStatsMemberInterface(const char* name, bool is_defined) : name_(name), is_defined_(is_defined) {} + virtual bool IsEqual(const RTCStatsMemberInterface& other) const = 0; + const char* const name_; bool is_defined_; }; @@ -309,17 +313,6 @@ class RTCStatsMember : public RTCStatsMemberInterface { bool is_sequence() const override; bool is_string() const override; bool is_standardized() const override { return true; } - bool operator==(const RTCStatsMemberInterface& other) const override { - if (type() != other.type() || is_standardized() != other.is_standardized()) - return false; - const RTCStatsMember& other_t = - static_cast&>(other); - if (!is_defined_) - return !other_t.is_defined(); - if (!other.is_defined()) - return false; - return value_ == other_t.value_; - } std::string ValueToString() const override; std::string ValueToJson() const override; @@ -363,6 +356,19 @@ class RTCStatsMember : public RTCStatsMemberInterface { return &value_; } + protected: + bool IsEqual(const RTCStatsMemberInterface& other) const override { + if (type() != other.type() || is_standardized() != other.is_standardized()) + return false; + const RTCStatsMember& other_t = + static_cast&>(other); + if (!is_defined_) + return !other_t.is_defined(); + if (!other.is_defined()) + return false; + return value_ == other_t.value_; + } + private: T value_; };