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