Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: webrtc/api/stats/rtcstats.h

Issue 2441543002: RTCStats equality operator added (Closed)
Patch Set: Addressed comments and rebase with master Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/stats/rtcstats.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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. These operators are exposed for testing.
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
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. These operators are
218 // exposed for testing.
219 virtual bool operator==(const RTCStatsMemberInterface& other) const = 0;
220 bool operator!=(const RTCStatsMemberInterface& other) const {
221 return !(*this == other);
222 }
212 virtual std::string ValueToString() const = 0; 223 virtual std::string ValueToString() const = 0;
213 224
214 template<typename T> 225 template<typename T>
215 const T& cast_to() const { 226 const T& cast_to() const {
216 RTC_DCHECK_EQ(type(), T::kType); 227 RTC_DCHECK_EQ(type(), T::kType);
217 return static_cast<const T&>(*this); 228 return static_cast<const T&>(*this);
218 } 229 }
219 230
220 protected: 231 protected:
221 RTCStatsMemberInterface(const char* name, bool is_defined) 232 RTCStatsMemberInterface(const char* name, bool is_defined)
(...skipping 24 matching lines...) Expand all
246 explicit RTCStatsMember(const RTCStatsMember<T>& other) 257 explicit RTCStatsMember(const RTCStatsMember<T>& other)
247 : RTCStatsMemberInterface(other.name_, other.is_defined_), 258 : RTCStatsMemberInterface(other.name_, other.is_defined_),
248 value_(other.value_) {} 259 value_(other.value_) {}
249 explicit RTCStatsMember(RTCStatsMember<T>&& other) 260 explicit RTCStatsMember(RTCStatsMember<T>&& other)
250 : RTCStatsMemberInterface(other.name_, other.is_defined_), 261 : RTCStatsMemberInterface(other.name_, other.is_defined_),
251 value_(std::move(other.value_)) {} 262 value_(std::move(other.value_)) {}
252 263
253 Type type() const override { return kType; } 264 Type type() const override { return kType; }
254 bool is_sequence() const override; 265 bool is_sequence() const override;
255 bool is_string() const override; 266 bool is_string() const override;
267 bool operator==(const RTCStatsMemberInterface& other) const override {
268 if (type() != other.type())
269 return false;
270 const RTCStatsMember<T>& other_t =
271 static_cast<const RTCStatsMember<T>&>(other);
272 if (!is_defined_)
273 return !other_t.is_defined();
274 return value_ == other_t.value_;
275 }
256 std::string ValueToString() const override; 276 std::string ValueToString() const override;
257 277
258 // Assignment operators. 278 // Assignment operators.
259 T& operator=(const T& value) { 279 T& operator=(const T& value) {
260 value_ = value; 280 value_ = value;
261 is_defined_ = true; 281 is_defined_ = true;
262 return value_; 282 return value_;
263 } 283 }
264 T& operator=(const T&& value) { 284 T& operator=(const T&& value) {
265 value_ = std::move(value); 285 value_ = std::move(value);
(...skipping 27 matching lines...) Expand all
293 return &value_; 313 return &value_;
294 } 314 }
295 315
296 private: 316 private:
297 T value_; 317 T value_;
298 }; 318 };
299 319
300 } // namespace webrtc 320 } // namespace webrtc
301 321
302 #endif // WEBRTC_API_STATS_RTCSTATS_H_ 322 #endif // WEBRTC_API_STATS_RTCSTATS_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/stats/rtcstats.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698