blob: 870651d2dfc52b1afff2bda5f227ee57274c34ed [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
11#include "webrtc/api/rtcstatsreport.h"
12
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
53rtc::scoped_refptr<RTCStatsReport> RTCStatsReport::Create() {
54 return rtc::scoped_refptr<RTCStatsReport>(
55 new rtc::RefCountedObject<RTCStatsReport>());
56}
57
58RTCStatsReport::RTCStatsReport() {
59}
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
69const RTCStats* RTCStatsReport::operator[](const std::string& id) const {
70 StatsMap::const_iterator it = stats_.find(id);
71 if (it != stats_.cend())
72 return it->second.get();
73 return nullptr;
74}
75
76RTCStatsReport::ConstIterator RTCStatsReport::begin() const {
77 return ConstIterator(rtc::scoped_refptr<const RTCStatsReport>(this),
78 stats_.cbegin());
79}
80
81RTCStatsReport::ConstIterator RTCStatsReport::end() const {
82 return ConstIterator(rtc::scoped_refptr<const RTCStatsReport>(this),
83 stats_.cend());
84}
85
86} // namespace webrtc