blob: 8adaf24cfa0a60107214d648c4fe82b28bb49f48 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -04002/*
Junxiao Shi52f16642023-08-15 00:18:35 +00003 * Copyright (c) 2014-2023, The University of Memphis,
alvy297f4162015-03-03 17:15:33 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040020 */
alvy297f4162015-03-03 17:15:33 -060021
akmhoquefdbddb12014-05-02 18:35:19 -050022#ifndef NLSR_NAME_PREFIX_LIST_HPP
23#define NLSR_NAME_PREFIX_LIST_HPP
akmhoque53353462014-04-22 08:43:45 -050024
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080025#include "test-access-control.hpp"
26
Junxiao Shi52f16642023-08-15 00:18:35 +000027#include <ndn-cxx/name.hpp>
28
29#include <boost/operators.hpp>
30
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040031#include <initializer_list>
akmhoque53353462014-04-22 08:43:45 -050032#include <list>
Junxiao Shi52f16642023-08-15 00:18:35 +000033#include <map>
34#include <set>
akmhoque53353462014-04-22 08:43:45 -050035#include <string>
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040036
akmhoque53353462014-04-22 08:43:45 -050037namespace nlsr {
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080038
Junxiao Shi52f16642023-08-15 00:18:35 +000039class NamePrefixList : private boost::equality_comparable<NamePrefixList>
akmhoque53353462014-04-22 08:43:45 -050040{
akmhoque53353462014-04-22 08:43:45 -050041public:
akmhoquec8a10f72014-04-25 18:42:55 -050042 NamePrefixList();
akmhoque53353462014-04-22 08:43:45 -050043
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040044 explicit
Junxiao Shi931ca9f2023-08-15 02:59:46 +000045 NamePrefixList(std::initializer_list<ndn::Name> names);
Nick Gordon96861ca2017-10-17 18:25:21 -050046
Junxiao Shi931ca9f2023-08-15 02:59:46 +000047 /*! \brief Inserts name and source combination.
48 \retval true Name and source combination is inserted.
49 \retval false Name and source combination already exists.
alvy297f4162015-03-03 17:15:33 -060050 */
51 bool
Nick Gordonf14ec352017-07-24 16:09:58 -050052 insert(const ndn::Name& name, const std::string& source = "");
akmhoque53353462014-04-22 08:43:45 -050053
Junxiao Shi931ca9f2023-08-15 02:59:46 +000054 /*! \brief Deletes name and source combination
55 \retval true Name and source combination is deleted.
56 \retval false Name and source combination does not exist.
alvy297f4162015-03-03 17:15:33 -060057 */
58 bool
Junxiao Shi52f16642023-08-15 00:18:35 +000059 erase(const ndn::Name& name, const std::string& source = "");
akmhoque53353462014-04-22 08:43:45 -050060
akmhoque31d1d4b2014-05-05 22:08:14 -050061 size_t
Nick Gordonff9a6272017-10-12 13:38:29 -050062 size() const
akmhoque53353462014-04-22 08:43:45 -050063 {
Junxiao Shi52f16642023-08-15 00:18:35 +000064 return m_namesSources.size();
akmhoque53353462014-04-22 08:43:45 -050065 }
66
Nick Gordonf14ec352017-07-24 16:09:58 -050067 std::list<ndn::Name>
68 getNames() const;
Nick Gordon56d1fae2017-05-26 16:39:25 -050069
Junxiao Shi931ca9f2023-08-15 02:59:46 +000070#ifdef WITH_TESTS
Nick Gordonf14ec352017-07-24 16:09:58 -050071 /*! Returns the sources that this name has.
Junxiao Shi931ca9f2023-08-15 02:59:46 +000072 If the name does not exist, returns an empty container.
Nick Gordonf14ec352017-07-24 16:09:58 -050073 */
Junxiao Shi931ca9f2023-08-15 02:59:46 +000074 std::set<std::string>
Nick Gordonf14ec352017-07-24 16:09:58 -050075 getSources(const ndn::Name& name) const;
Junxiao Shi931ca9f2023-08-15 02:59:46 +000076#endif
Nick Gordonf14ec352017-07-24 16:09:58 -050077
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080078 void
79 clear()
80 {
Junxiao Shi52f16642023-08-15 00:18:35 +000081 m_namesSources.clear();
82 }
83
84private: // non-member operators
85 // NOTE: the following "hidden friend" operators are available via
86 // argument-dependent lookup only and must be defined inline.
87 // boost::equality_comparable provides != operators.
88
89 friend bool
90 operator==(const NamePrefixList& lhs, const NamePrefixList& rhs)
91 {
92 return lhs.getNames() == rhs.getNames();
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080093 }
94
Nick Gordonf14ec352017-07-24 16:09:58 -050095private:
Junxiao Shi52f16642023-08-15 00:18:35 +000096 std::map<ndn::Name, std::set<std::string>> m_namesSources;
akmhoque53353462014-04-22 08:43:45 -050097
Junxiao Shi931ca9f2023-08-15 02:59:46 +000098 friend std::ostream&
99 operator<<(std::ostream& os, const NamePrefixList& list);
100};
Nick Gordon56d1fae2017-05-26 16:39:25 -0500101
Nick Gordonfad8e252016-08-11 14:21:38 -0500102} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500103
Nick Gordon56d1fae2017-05-26 16:39:25 -0500104#endif // NLSR_NAME_PREFIX_LIST_HPP