spirosmastorakis | 0e2b197 | 2016-03-27 20:54:41 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2016 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of the nTorrent codebase. |
| 6 | * |
| 7 | * nTorrent is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * nTorrent is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with nTorrent, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS for complete list of nTorrent authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | #include "stats-table.hpp" |
| 23 | |
| 24 | namespace ndn { |
| 25 | namespace ntorrent { |
| 26 | |
| 27 | StatsTable::StatsTable(const Name& torrentName) |
| 28 | : m_torrentName(torrentName) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | void |
| 33 | StatsTable::insert(const Name& prefix) |
| 34 | { |
| 35 | m_statsTable.push_back(StatsTableRecord(prefix)); |
| 36 | } |
| 37 | |
| 38 | StatsTable::const_iterator |
| 39 | StatsTable::find(const Name& prefix) const |
| 40 | { |
| 41 | for (auto i = m_statsTable.begin(); i != m_statsTable.end(); ++i) { |
| 42 | if (i->getRecordName() == prefix) { |
| 43 | return i; |
| 44 | } |
| 45 | } |
| 46 | return StatsTable::end(); |
| 47 | } |
| 48 | |
| 49 | StatsTable::iterator |
| 50 | StatsTable::find(const Name& prefix) |
| 51 | { |
| 52 | for (auto i = m_statsTable.begin(); i != m_statsTable.end(); ++i) { |
| 53 | if (i->getRecordName() == prefix) { |
| 54 | return i; |
| 55 | } |
| 56 | } |
| 57 | return StatsTable::end(); |
| 58 | } |
| 59 | |
| 60 | bool |
| 61 | StatsTable::erase(const Name& prefix) |
| 62 | { |
| 63 | for (auto i = m_statsTable.begin(); i != m_statsTable.end(); ++i) { |
| 64 | if (i->getRecordName() == prefix) { |
| 65 | m_statsTable.erase(i); |
| 66 | return true; |
| 67 | } |
| 68 | } |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | } // namespace ntorrent |
| 73 | } // namespace ndn |