name-prefix-list.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2023, The University of Memphis,
4  * Regents of the University of California,
5  * Arizona Board of Regents.
6  *
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/>.
20  */
21 
22 #ifndef NLSR_NAME_PREFIX_LIST_HPP
23 #define NLSR_NAME_PREFIX_LIST_HPP
24 
25 #include "test-access-control.hpp"
26 
27 #include <ndn-cxx/name.hpp>
28 
29 #include <boost/operators.hpp>
30 
31 #include <initializer_list>
32 #include <list>
33 #include <map>
34 #include <set>
35 #include <string>
36 
37 namespace nlsr {
38 
39 class NamePrefixList : private boost::equality_comparable<NamePrefixList>
40 {
41 public:
43 
44  explicit
45  NamePrefixList(std::initializer_list<ndn::Name> names);
46 
51  bool
52  insert(const ndn::Name& name, const std::string& source = "");
53 
58  bool
59  erase(const ndn::Name& name, const std::string& source = "");
60 
61  size_t
62  size() const
63  {
64  return m_namesSources.size();
65  }
66 
67  std::list<ndn::Name>
68  getNames() const;
69 
70 #ifdef WITH_TESTS
74  std::set<std::string>
75  getSources(const ndn::Name& name) const;
76 #endif
77 
78  void
80  {
81  m_namesSources.clear();
82  }
83 
84 private: // 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();
93  }
94 
95 private:
96  std::map<ndn::Name, std::set<std::string>> m_namesSources;
97 
98  friend std::ostream&
99  operator<<(std::ostream& os, const NamePrefixList& list);
100 };
101 
102 } // namespace nlsr
103 
104 #endif // NLSR_NAME_PREFIX_LIST_HPP
bool erase(const ndn::Name &name, const std::string &source="")
Deletes name and source combination.
bool insert(const ndn::Name &name, const std::string &source="")
Inserts name and source combination.
friend std::ostream & operator<<(std::ostream &os, const NamePrefixList &list)
friend bool operator==(const NamePrefixList &lhs, const NamePrefixList &rhs)
std::list< ndn::Name > getNames() const
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.