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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // Returns a vector of pointers to all the |RTCStatsMemberInterface| members | 65 // Returns a vector of pointers to all the |RTCStatsMemberInterface| members |
66 // of this class. This allows for iteration of members. For a given class, | 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 // |Members| always returns the same members in the same order. |
68 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 | 69 // Checks if the two stats objects are of the same type and have the same |
70 // member values. Timestamps are not compared. These operators are exposed for | 70 // member values. Timestamps are not compared. These operators are exposed for |
71 // testing. | 71 // testing. |
72 bool operator==(const RTCStats& other) const; | 72 bool operator==(const RTCStats& other) const; |
73 bool operator!=(const RTCStats& other) const; | 73 bool operator!=(const RTCStats& other) const; |
74 | 74 |
75 // Creates a human readable string representation of the stats object, listing | 75 // Creates a JSON readable string representation of the stats |
76 // all of its members (names and values). | 76 // object, listing all of its members (names and values). |
77 std::string ToString() const; | 77 std::string ToJson() const; |
78 | 78 |
79 // Downcasts the stats object to an |RTCStats| subclass |T|. DCHECKs that the | 79 // Downcasts the stats object to an |RTCStats| subclass |T|. DCHECKs that the |
80 // object is of type |T|. | 80 // object is of type |T|. |
81 template<typename T> | 81 template<typename T> |
82 const T& cast_to() const { | 82 const T& cast_to() const { |
83 RTC_DCHECK_EQ(type(), T::kType); | 83 RTC_DCHECK_EQ(type(), T::kType); |
84 return static_cast<const T&>(*this); | 84 return static_cast<const T&>(*this); |
85 } | 85 } |
86 | 86 |
87 protected: | 87 protected: |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 virtual bool is_sequence() const = 0; | 215 virtual bool is_sequence() const = 0; |
216 virtual bool is_string() const = 0; | 216 virtual bool is_string() const = 0; |
217 bool is_defined() const { return is_defined_; } | 217 bool is_defined() const { return is_defined_; } |
218 // Type and value comparator. The names are not compared. These operators are | 218 // Type and value comparator. The names are not compared. These operators are |
219 // exposed for testing. | 219 // exposed for testing. |
220 virtual bool operator==(const RTCStatsMemberInterface& other) const = 0; | 220 virtual bool operator==(const RTCStatsMemberInterface& other) const = 0; |
221 bool operator!=(const RTCStatsMemberInterface& other) const { | 221 bool operator!=(const RTCStatsMemberInterface& other) const { |
222 return !(*this == other); | 222 return !(*this == other); |
223 } | 223 } |
224 virtual std::string ValueToString() const = 0; | 224 virtual std::string ValueToString() const = 0; |
| 225 // This is the same as ValueToString except for kInt64 and kUint64 types, |
| 226 // where the value is represented as a double instead of as an integer. |
| 227 // Since JSON stores numbers as floating point numbers, very large integers |
| 228 // cannot be accurately represented, so we prefer to display them as doubles |
| 229 // instead. |
| 230 virtual std::string ValueToJson() const = 0; |
225 | 231 |
226 template<typename T> | 232 template<typename T> |
227 const T& cast_to() const { | 233 const T& cast_to() const { |
228 RTC_DCHECK_EQ(type(), T::kType); | 234 RTC_DCHECK_EQ(type(), T::kType); |
229 return static_cast<const T&>(*this); | 235 return static_cast<const T&>(*this); |
230 } | 236 } |
231 | 237 |
232 protected: | 238 protected: |
233 RTCStatsMemberInterface(const char* name, bool is_defined) | 239 RTCStatsMemberInterface(const char* name, bool is_defined) |
234 : name_(name), is_defined_(is_defined) {} | 240 : name_(name), is_defined_(is_defined) {} |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 return false; | 276 return false; |
271 const RTCStatsMember<T>& other_t = | 277 const RTCStatsMember<T>& other_t = |
272 static_cast<const RTCStatsMember<T>&>(other); | 278 static_cast<const RTCStatsMember<T>&>(other); |
273 if (!is_defined_) | 279 if (!is_defined_) |
274 return !other_t.is_defined(); | 280 return !other_t.is_defined(); |
275 if (!other.is_defined()) | 281 if (!other.is_defined()) |
276 return false; | 282 return false; |
277 return value_ == other_t.value_; | 283 return value_ == other_t.value_; |
278 } | 284 } |
279 std::string ValueToString() const override; | 285 std::string ValueToString() const override; |
| 286 std::string ValueToJson() const override; |
280 | 287 |
281 // Assignment operators. | 288 // Assignment operators. |
282 T& operator=(const T& value) { | 289 T& operator=(const T& value) { |
283 value_ = value; | 290 value_ = value; |
284 is_defined_ = true; | 291 is_defined_ = true; |
285 return value_; | 292 return value_; |
286 } | 293 } |
287 T& operator=(const T&& value) { | 294 T& operator=(const T&& value) { |
288 value_ = std::move(value); | 295 value_ = std::move(value); |
289 is_defined_ = true; | 296 is_defined_ = true; |
(...skipping 26 matching lines...) Expand all Loading... |
316 return &value_; | 323 return &value_; |
317 } | 324 } |
318 | 325 |
319 private: | 326 private: |
320 T value_; | 327 T value_; |
321 }; | 328 }; |
322 | 329 |
323 } // namespace webrtc | 330 } // namespace webrtc |
324 | 331 |
325 #endif // WEBRTC_API_STATS_RTCSTATS_H_ | 332 #endif // WEBRTC_API_STATS_RTCSTATS_H_ |
OLD | NEW |