| 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 |
| 11 #include "webrtc/api/stats/rtcstatsreport.h" | 11 #include "webrtc/api/stats/rtcstatsreport.h" |
| 12 | 12 |
| 13 #include <sstream> |
| 14 |
| 13 namespace webrtc { | 15 namespace webrtc { |
| 14 | 16 |
| 15 RTCStatsReport::ConstIterator::ConstIterator( | 17 RTCStatsReport::ConstIterator::ConstIterator( |
| 16 const rtc::scoped_refptr<const RTCStatsReport>& report, | 18 const rtc::scoped_refptr<const RTCStatsReport>& report, |
| 17 StatsMap::const_iterator it) | 19 StatsMap::const_iterator it) |
| 18 : report_(report), | 20 : report_(report), |
| 19 it_(it) { | 21 it_(it) { |
| 20 } | 22 } |
| 21 | 23 |
| 22 RTCStatsReport::ConstIterator::ConstIterator(const ConstIterator&& other) | 24 RTCStatsReport::ConstIterator::ConstIterator(const ConstIterator&& other) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 33 } | 35 } |
| 34 | 36 |
| 35 RTCStatsReport::ConstIterator& RTCStatsReport::ConstIterator::operator++(int) { | 37 RTCStatsReport::ConstIterator& RTCStatsReport::ConstIterator::operator++(int) { |
| 36 return ++(*this); | 38 return ++(*this); |
| 37 } | 39 } |
| 38 | 40 |
| 39 const RTCStats& RTCStatsReport::ConstIterator::operator*() const { | 41 const RTCStats& RTCStatsReport::ConstIterator::operator*() const { |
| 40 return *it_->second.get(); | 42 return *it_->second.get(); |
| 41 } | 43 } |
| 42 | 44 |
| 45 const RTCStats* RTCStatsReport::ConstIterator::operator->() const { |
| 46 return it_->second.get(); |
| 47 } |
| 48 |
| 43 bool RTCStatsReport::ConstIterator::operator==( | 49 bool RTCStatsReport::ConstIterator::operator==( |
| 44 const RTCStatsReport::ConstIterator& other) const { | 50 const RTCStatsReport::ConstIterator& other) const { |
| 45 return it_ == other.it_; | 51 return it_ == other.it_; |
| 46 } | 52 } |
| 47 | 53 |
| 48 bool RTCStatsReport::ConstIterator::operator!=( | 54 bool RTCStatsReport::ConstIterator::operator!=( |
| 49 const RTCStatsReport::ConstIterator& other) const { | 55 const RTCStatsReport::ConstIterator& other) const { |
| 50 return !(*this == other); | 56 return !(*this == other); |
| 51 } | 57 } |
| 52 | 58 |
| 53 rtc::scoped_refptr<RTCStatsReport> RTCStatsReport::Create() { | 59 rtc::scoped_refptr<RTCStatsReport> RTCStatsReport::Create( |
| 60 uint64_t timestamp_us) { |
| 54 return rtc::scoped_refptr<RTCStatsReport>( | 61 return rtc::scoped_refptr<RTCStatsReport>( |
| 55 new rtc::RefCountedObject<RTCStatsReport>()); | 62 new rtc::RefCountedObject<RTCStatsReport>(timestamp_us)); |
| 56 } | 63 } |
| 57 | 64 |
| 58 RTCStatsReport::RTCStatsReport() { | 65 RTCStatsReport::RTCStatsReport(uint64_t timestamp_us) |
| 66 : timestamp_us_(timestamp_us) { |
| 59 } | 67 } |
| 60 | 68 |
| 61 RTCStatsReport::~RTCStatsReport() { | 69 RTCStatsReport::~RTCStatsReport() { |
| 62 } | 70 } |
| 63 | 71 |
| 64 bool RTCStatsReport::AddStats(std::unique_ptr<const RTCStats> stats) { | 72 bool RTCStatsReport::AddStats(std::unique_ptr<const RTCStats> stats) { |
| 65 return !stats_.insert(std::make_pair(std::string(stats->id()), | 73 return !stats_.insert(std::make_pair(std::string(stats->id()), |
| 66 std::move(stats))).second; | 74 std::move(stats))).second; |
| 67 } | 75 } |
| 68 | 76 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 85 RTCStatsReport::ConstIterator RTCStatsReport::begin() const { | 93 RTCStatsReport::ConstIterator RTCStatsReport::begin() const { |
| 86 return ConstIterator(rtc::scoped_refptr<const RTCStatsReport>(this), | 94 return ConstIterator(rtc::scoped_refptr<const RTCStatsReport>(this), |
| 87 stats_.cbegin()); | 95 stats_.cbegin()); |
| 88 } | 96 } |
| 89 | 97 |
| 90 RTCStatsReport::ConstIterator RTCStatsReport::end() const { | 98 RTCStatsReport::ConstIterator RTCStatsReport::end() const { |
| 91 return ConstIterator(rtc::scoped_refptr<const RTCStatsReport>(this), | 99 return ConstIterator(rtc::scoped_refptr<const RTCStatsReport>(this), |
| 92 stats_.cend()); | 100 stats_.cend()); |
| 93 } | 101 } |
| 94 | 102 |
| 103 std::string RTCStatsReport::ToString() const { |
| 104 std::ostringstream oss; |
| 105 ConstIterator it = begin(); |
| 106 if (it != end()) { |
| 107 oss << it->ToString(); |
| 108 for (++it; it != end(); ++it) { |
| 109 oss << '\n' << it->ToString(); |
| 110 } |
| 111 } |
| 112 return oss.str(); |
| 113 } |
| 114 |
| 95 } // namespace webrtc | 115 } // namespace webrtc |
| OLD | NEW |