| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 : id_(std::move(id)), timestamp_us_(timestamp_us) {} | 55 : id_(std::move(id)), timestamp_us_(timestamp_us) {} |
| 56 virtual ~RTCStats() {} | 56 virtual ~RTCStats() {} |
| 57 | 57 |
| 58 virtual std::unique_ptr<RTCStats> copy() const = 0; | 58 virtual std::unique_ptr<RTCStats> copy() const = 0; |
| 59 | 59 |
| 60 const std::string& id() const { return id_; } | 60 const std::string& id() const { return id_; } |
| 61 // Time relative to the UNIX epoch (Jan 1, 1970, UTC), in microseconds. | 61 // Time relative to the UNIX epoch (Jan 1, 1970, UTC), in microseconds. |
| 62 int64_t timestamp_us() const { return timestamp_us_; } | 62 int64_t timestamp_us() const { return timestamp_us_; } |
| 63 // Returns the static member variable |kType| of the implementing class. | 63 // Returns the static member variable |kType| of the implementing class. |
| 64 virtual const char* type() const = 0; | 64 virtual const char* type() const = 0; |
| 65 // Returns a vector of pointers to all the RTCStatsMemberInterface members of | 65 // Returns a vector of pointers to all the |RTCStatsMemberInterface| members |
| 66 // this class. This allows for iteration of members. | 66 // of this class. This allows for iteration of members. For a given class, |
| 67 // |Members| always returns the same members in the same order. |
| 67 std::vector<const RTCStatsMemberInterface*> Members() const; | 68 std::vector<const RTCStatsMemberInterface*> Members() const; |
| 69 // Checks if the two stats objects are of the same type and have the same |
| 70 // member values. |
| 71 bool operator==(const RTCStats& other) const; |
| 72 bool operator!=(const RTCStats& other) const; |
| 68 | 73 |
| 69 // Creates a human readable string representation of the report, listing all | 74 // Creates a human readable string representation of the report, listing all |
| 70 // of its members (names and values). | 75 // of its members (names and values). |
| 71 std::string ToString() const; | 76 std::string ToString() const; |
| 72 | 77 |
| 73 // Downcasts the stats object to an |RTCStats| subclass |T|. DCHECKs that the | 78 // Downcasts the stats object to an |RTCStats| subclass |T|. DCHECKs that the |
| 74 // object is of type |T|. | 79 // object is of type |T|. |
| 75 template<typename T> | 80 template<typename T> |
| 76 const T& cast_to() const { | 81 const T& cast_to() const { |
| 77 RTC_DCHECK_EQ(type(), T::kType); | 82 RTC_DCHECK_EQ(type(), T::kType); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 kSequenceString, // std::vector<std::string> | 207 kSequenceString, // std::vector<std::string> |
| 203 }; | 208 }; |
| 204 | 209 |
| 205 virtual ~RTCStatsMemberInterface() {} | 210 virtual ~RTCStatsMemberInterface() {} |
| 206 | 211 |
| 207 const char* name() const { return name_; } | 212 const char* name() const { return name_; } |
| 208 virtual Type type() const = 0; | 213 virtual Type type() const = 0; |
| 209 virtual bool is_sequence() const = 0; | 214 virtual bool is_sequence() const = 0; |
| 210 virtual bool is_string() const = 0; | 215 virtual bool is_string() const = 0; |
| 211 bool is_defined() const { return is_defined_; } | 216 bool is_defined() const { return is_defined_; } |
| 217 // Type and value comparator. The names are not compared. |
| 218 virtual bool operator==(const RTCStatsMemberInterface& other) const = 0; |
| 219 bool operator!=(const RTCStatsMemberInterface& other) const { |
| 220 return !(*this == other); |
| 221 } |
| 212 virtual std::string ValueToString() const = 0; | 222 virtual std::string ValueToString() const = 0; |
| 213 | 223 |
| 214 template<typename T> | 224 template<typename T> |
| 215 const T& cast_to() const { | 225 const T& cast_to() const { |
| 216 RTC_DCHECK_EQ(type(), T::kType); | 226 RTC_DCHECK_EQ(type(), T::kType); |
| 217 return static_cast<const T&>(*this); | 227 return static_cast<const T&>(*this); |
| 218 } | 228 } |
| 219 | 229 |
| 220 protected: | 230 protected: |
| 221 RTCStatsMemberInterface(const char* name, bool is_defined) | 231 RTCStatsMemberInterface(const char* name, bool is_defined) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 246 explicit RTCStatsMember(const RTCStatsMember<T>& other) | 256 explicit RTCStatsMember(const RTCStatsMember<T>& other) |
| 247 : RTCStatsMemberInterface(other.name_, other.is_defined_), | 257 : RTCStatsMemberInterface(other.name_, other.is_defined_), |
| 248 value_(other.value_) {} | 258 value_(other.value_) {} |
| 249 explicit RTCStatsMember(RTCStatsMember<T>&& other) | 259 explicit RTCStatsMember(RTCStatsMember<T>&& other) |
| 250 : RTCStatsMemberInterface(other.name_, other.is_defined_), | 260 : RTCStatsMemberInterface(other.name_, other.is_defined_), |
| 251 value_(std::move(other.value_)) {} | 261 value_(std::move(other.value_)) {} |
| 252 | 262 |
| 253 Type type() const override { return kType; } | 263 Type type() const override { return kType; } |
| 254 bool is_sequence() const override; | 264 bool is_sequence() const override; |
| 255 bool is_string() const override; | 265 bool is_string() const override; |
| 266 bool operator==(const RTCStatsMemberInterface& other) const override { |
| 267 if (type() != other.type()) |
| 268 return false; |
| 269 const RTCStatsMember<T>& other_t = |
| 270 static_cast<const RTCStatsMember<T>&>(other); |
| 271 if (!is_defined_) |
| 272 return !other_t.is_defined(); |
| 273 return value_ == other_t.value_; |
| 274 } |
| 256 std::string ValueToString() const override; | 275 std::string ValueToString() const override; |
| 257 | 276 |
| 258 // Assignment operators. | 277 // Assignment operators. |
| 259 T& operator=(const T& value) { | 278 T& operator=(const T& value) { |
| 260 value_ = value; | 279 value_ = value; |
| 261 is_defined_ = true; | 280 is_defined_ = true; |
| 262 return value_; | 281 return value_; |
| 263 } | 282 } |
| 264 T& operator=(const T&& value) { | 283 T& operator=(const T&& value) { |
| 265 value_ = std::move(value); | 284 value_ = std::move(value); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 293 return &value_; | 312 return &value_; |
| 294 } | 313 } |
| 295 | 314 |
| 296 private: | 315 private: |
| 297 T value_; | 316 T value_; |
| 298 }; | 317 }; |
| 299 | 318 |
| 300 } // namespace webrtc | 319 } // namespace webrtc |
| 301 | 320 |
| 302 #endif // WEBRTC_API_STATS_RTCSTATS_H_ | 321 #endif // WEBRTC_API_STATS_RTCSTATS_H_ |
| OLD | NEW |