blob: 4be554daaec9e5d11c6fedc4d2d3e4da817a2b5b [file] [log] [blame]
hbos615d3012016-08-24 01:33:13 -07001/*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
hbos74e1a4f2016-09-15 23:33:01 -070011#include "webrtc/api/stats/rtcstatsreport.h"
hbos615d3012016-08-24 01:33:13 -070012
13namespace webrtc {
14
15RTCStatsReport::ConstIterator::ConstIterator(
16 const rtc::scoped_refptr<const RTCStatsReport>& report,
17 StatsMap::const_iterator it)
18 : report_(report),
19 it_(it) {
20}
21
22RTCStatsReport::ConstIterator::ConstIterator(const ConstIterator&& other)
23 : report_(std::move(other.report_)),
24 it_(std::move(other.it_)) {
25}
26
27RTCStatsReport::ConstIterator::~ConstIterator() {
28}
29
30RTCStatsReport::ConstIterator& RTCStatsReport::ConstIterator::operator++() {
31 ++it_;
32 return *this;
33}
34
35RTCStatsReport::ConstIterator& RTCStatsReport::ConstIterator::operator++(int) {
36 return ++(*this);
37}
38
39const RTCStats& RTCStatsReport::ConstIterator::operator*() const {
40 return *it_->second.get();
41}
42
43bool RTCStatsReport::ConstIterator::operator==(
44 const RTCStatsReport::ConstIterator& other) const {
45 return it_ == other.it_;
46}
47
48bool RTCStatsReport::ConstIterator::operator!=(
49 const RTCStatsReport::ConstIterator& other) const {
50 return !(*this == other);
51}
52
perkj7eaa8362016-10-31 23:52:25 -070053rtc::scoped_refptr<RTCStatsReport> RTCStatsReport::Create() {
hbos615d3012016-08-24 01:33:13 -070054 return rtc::scoped_refptr<RTCStatsReport>(
perkj7eaa8362016-10-31 23:52:25 -070055 new rtc::RefCountedObject<RTCStatsReport>());
hbos615d3012016-08-24 01:33:13 -070056}
57
perkj7eaa8362016-10-31 23:52:25 -070058RTCStatsReport::RTCStatsReport() {
hbos615d3012016-08-24 01:33:13 -070059}
60
61RTCStatsReport::~RTCStatsReport() {
62}
63
64bool RTCStatsReport::AddStats(std::unique_ptr<const RTCStats> stats) {
65 return !stats_.insert(std::make_pair(std::string(stats->id()),
66 std::move(stats))).second;
67}
68
hbos6d183ac2016-08-29 07:20:33 -070069const RTCStats* RTCStatsReport::Get(const std::string& id) const {
hbos615d3012016-08-24 01:33:13 -070070 StatsMap::const_iterator it = stats_.find(id);
71 if (it != stats_.cend())
72 return it->second.get();
73 return nullptr;
74}
75
hbos6d183ac2016-08-29 07:20:33 -070076void RTCStatsReport::TakeMembersFrom(
77 rtc::scoped_refptr<RTCStatsReport> victim) {
78 for (StatsMap::iterator it = victim->stats_.begin();
79 it != victim->stats_.end(); ++it) {
80 AddStats(std::unique_ptr<const RTCStats>(it->second.release()));
81 }
82 victim->stats_.clear();
83}
84
hbos615d3012016-08-24 01:33:13 -070085RTCStatsReport::ConstIterator RTCStatsReport::begin() const {
86 return ConstIterator(rtc::scoped_refptr<const RTCStatsReport>(this),
87 stats_.cbegin());
88}
89
90RTCStatsReport::ConstIterator RTCStatsReport::end() const {
91 return ConstIterator(rtc::scoped_refptr<const RTCStatsReport>(this),
92 stats_.cend());
93}
94
hbos615d3012016-08-24 01:33:13 -070095} // namespace webrtc