blob: 522f4e286224b3e16cd436d32f5d34d574b94212 [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shifef73e42016-03-29 14:15:05 -07003 * Copyright (c) 2014-2016, Regents of the University of California,
Junxiao Shicde37ad2015-12-24 01:02:05 -07004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Alexander Afanasyev28d586a2014-07-10 20:10:54 -070024 */
Junxiao Shicbba04c2014-01-26 14:21:22 -070025
26#include "pit-entry.hpp"
27#include <algorithm>
28
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080029namespace nfd {
Junxiao Shicbba04c2014-01-26 14:21:22 -070030namespace pit {
31
32Entry::Entry(const Interest& interest)
Alexander Afanasyev28d586a2014-07-10 20:10:54 -070033 : m_interest(interest.shared_from_this())
Junxiao Shi340d5532016-08-13 04:00:35 +000034 , m_nameTreeEntry(nullptr)
Junxiao Shicbba04c2014-01-26 14:21:22 -070035{
36}
37
Junxiao Shi4846f372016-04-05 13:39:30 -070038InRecordCollection::iterator
39Entry::getInRecord(const Face& face)
Junxiao Shicbba04c2014-01-26 14:21:22 -070040{
Junxiao Shi4846f372016-04-05 13:39:30 -070041 return std::find_if(m_inRecords.begin(), m_inRecords.end(),
Junxiao Shi9cff7792016-08-01 21:45:11 +000042 [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
Junxiao Shicbba04c2014-01-26 14:21:22 -070043}
44
Junxiao Shicbba04c2014-01-26 14:21:22 -070045InRecordCollection::iterator
Junxiao Shi9cff7792016-08-01 21:45:11 +000046Entry::insertOrUpdateInRecord(Face& face, const Interest& interest)
Junxiao Shicbba04c2014-01-26 14:21:22 -070047{
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070048 auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
Junxiao Shi9cff7792016-08-01 21:45:11 +000049 [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
Junxiao Shicbba04c2014-01-26 14:21:22 -070050 if (it == m_inRecords.end()) {
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070051 m_inRecords.emplace_front(face);
Junxiao Shicbba04c2014-01-26 14:21:22 -070052 it = m_inRecords.begin();
53 }
Junxiao Shi11bd9c22014-03-13 20:44:13 -070054
Junxiao Shicbba04c2014-01-26 14:21:22 -070055 it->update(interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -070056 return it;
57}
58
59void
Junxiao Shi5e5e4452015-09-24 16:56:52 -070060Entry::deleteInRecord(const Face& face)
61{
62 auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
Junxiao Shi9cff7792016-08-01 21:45:11 +000063 [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
Junxiao Shi5e5e4452015-09-24 16:56:52 -070064 if (it != m_inRecords.end()) {
65 m_inRecords.erase(it);
66 }
67}
68
69void
Junxiao Shi4846f372016-04-05 13:39:30 -070070Entry::clearInRecords()
Junxiao Shicbba04c2014-01-26 14:21:22 -070071{
72 m_inRecords.clear();
73}
74
75OutRecordCollection::iterator
Junxiao Shi4846f372016-04-05 13:39:30 -070076Entry::getOutRecord(const Face& face)
77{
78 return std::find_if(m_outRecords.begin(), m_outRecords.end(),
Junxiao Shi9cff7792016-08-01 21:45:11 +000079 [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
Junxiao Shi4846f372016-04-05 13:39:30 -070080}
81
82OutRecordCollection::iterator
Junxiao Shi9cff7792016-08-01 21:45:11 +000083Entry::insertOrUpdateOutRecord(Face& face, const Interest& interest)
Junxiao Shicbba04c2014-01-26 14:21:22 -070084{
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070085 auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
Junxiao Shi9cff7792016-08-01 21:45:11 +000086 [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
Junxiao Shicbba04c2014-01-26 14:21:22 -070087 if (it == m_outRecords.end()) {
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070088 m_outRecords.emplace_front(face);
Junxiao Shicbba04c2014-01-26 14:21:22 -070089 it = m_outRecords.begin();
90 }
Junxiao Shi11bd9c22014-03-13 20:44:13 -070091
Junxiao Shicbba04c2014-01-26 14:21:22 -070092 it->update(interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -070093 return it;
94}
95
96void
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070097Entry::deleteOutRecord(const Face& face)
Junxiao Shicbba04c2014-01-26 14:21:22 -070098{
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070099 auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
Junxiao Shi9cff7792016-08-01 21:45:11 +0000100 [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
Junxiao Shicbba04c2014-01-26 14:21:22 -0700101 if (it != m_outRecords.end()) {
102 m_outRecords.erase(it);
103 }
104}
105
Junxiao Shicbba04c2014-01-26 14:21:22 -0700106} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800107} // namespace nfd