blob: 41cf520a30a17f3cffcec40a30fbb1823d91332a [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 Regents of the University of California,
4 * 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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Junxiao Shicbba04c2014-01-26 14:21:22 -070024
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070025#ifndef NFD_DAEMON_TABLE_PIT_HPP
26#define NFD_DAEMON_TABLE_PIT_HPP
Junxiao Shicbba04c2014-01-26 14:21:22 -070027
Haowei Yuan78c84d12014-02-27 15:35:13 -060028#include "name-tree.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070029#include "pit-entry.hpp"
Haowei Yuan78c84d12014-02-27 15:35:13 -060030
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080031namespace nfd {
Junxiao Shicbba04c2014-01-26 14:21:22 -070032namespace pit {
33
34/** \class DataMatchResult
35 * \brief an unordered iterable of all PIT entries matching Data
36 * This type shall support:
37 * iterator<shared_ptr<pit::Entry>> begin()
38 * iterator<shared_ptr<pit::Entry>> end()
39 */
40typedef std::vector<shared_ptr<pit::Entry> > DataMatchResult;
41
42} // namespace pit
43
44/** \class Pit
45 * \brief represents the PIT
46 */
47class Pit : noncopyable
48{
49public:
Haowei Yuan78c84d12014-02-27 15:35:13 -060050 explicit
51 Pit(NameTree& nameTree);
Haowei Yuane1079fc2014-03-08 14:41:25 -060052
Junxiao Shicbba04c2014-01-26 14:21:22 -070053 ~Pit();
Haowei Yuan78c84d12014-02-27 15:35:13 -060054
Haowei Yuane1079fc2014-03-08 14:41:25 -060055 /**
Haowei Yuan78c84d12014-02-27 15:35:13 -060056 * \brief Get the number of items stored in the PIT.
57 */
Haowei Yuane1079fc2014-03-08 14:41:25 -060058 size_t
Haowei Yuan78c84d12014-02-27 15:35:13 -060059 size() const;
Haowei Yuane1079fc2014-03-08 14:41:25 -060060
Junxiao Shi66f91f82014-05-10 17:28:58 -070061 /** \brief inserts a PIT entry for prefix
62 * If an entry for exact same name and selectors exists, that entry is returned.
Junxiao Shicbba04c2014-01-26 14:21:22 -070063 * \return{ the entry, and true for new entry, false for existing entry }
64 */
65 std::pair<shared_ptr<pit::Entry>, bool>
66 insert(const Interest& interest);
Haowei Yuane1079fc2014-03-08 14:41:25 -060067
Junxiao Shicbba04c2014-01-26 14:21:22 -070068 /** \brief performs a Data match
69 * \return{ an iterable of all PIT entries matching data }
70 */
71 shared_ptr<pit::DataMatchResult>
72 findAllDataMatches(const Data& data) const;
Haowei Yuane1079fc2014-03-08 14:41:25 -060073
Haowei Yuan78c84d12014-02-27 15:35:13 -060074 /**
75 * \brief Erase a PIT Entry
Haowei Yuane1079fc2014-03-08 14:41:25 -060076 */
Junxiao Shicbba04c2014-01-26 14:21:22 -070077 void
Haowei Yuan78c84d12014-02-27 15:35:13 -060078 erase(shared_ptr<pit::Entry> pitEntry);
Junxiao Shicbba04c2014-01-26 14:21:22 -070079
80private:
Haowei Yuan78c84d12014-02-27 15:35:13 -060081 NameTree& m_nameTree;
82 size_t m_nItems;
Junxiao Shicbba04c2014-01-26 14:21:22 -070083};
84
Haowei Yuan78c84d12014-02-27 15:35:13 -060085inline size_t
86Pit::size() const
87{
88 return m_nItems;
89}
90
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080091} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -070092
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070093#endif // NFD_DAEMON_TABLE_PIT_HPP