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-2022, 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 <initializer_list>
28 #include <list>
29 #include <string>
30 #include <tuple>
31 #include <vector>
32 
33 #include <ndn-cxx/name.hpp>
34 
35 namespace nlsr {
36 
38 {
39 public:
40  using NamePair = std::tuple<ndn::Name, std::vector<std::string>>;
41 
44  SOURCES
45  };
46 
48 
49  explicit
50  NamePrefixList(ndn::span<const ndn::Name> names);
51 
52 #ifdef WITH_TESTS
53  NamePrefixList(std::initializer_list<ndn::Name> names)
54  : NamePrefixList(ndn::span<const ndn::Name>(names))
55  {
56  }
57 
58  NamePrefixList(std::initializer_list<NamePair> namesAndSources)
59  : m_names(namesAndSources)
60  {
61  }
62 #endif
63 
68  bool
69  insert(const ndn::Name& name, const std::string& source = "");
70 
75  bool
76  remove(const ndn::Name& name, const std::string& source = "");
77 
78  void
79  sort();
80 
81  size_t
82  size() const
83  {
84  return m_names.size();
85  }
86 
87  std::list<ndn::Name>
88  getNames() const;
89 
90  bool
91  operator==(const NamePrefixList& other) const;
92 
97  uint32_t
98  countSources(const ndn::Name& name) const;
99 
105  const std::vector<std::string>
106  getSources(const ndn::Name& name) const;
107 
108  void
110  {
111  m_names.clear();
112  }
113 
114 private:
120  std::vector<NamePair>::iterator
121  get(const ndn::Name& name);
122 
125  std::vector<std::string>::iterator
126  getSource(const std::string& source, std::vector<NamePair>::iterator& entry);
127 
128  std::vector<NamePair> m_names;
129 };
130 
131 std::ostream&
132 operator<<(std::ostream& os, const NamePrefixList& list);
133 
134 } // namespace nlsr
135 
136 #endif // NLSR_NAME_PREFIX_LIST_HPP
bool operator==(const NamePrefixList &other) const
bool remove(const ndn::Name &name, const std::string &source="")
removes name from NamePrefixList
bool insert(const ndn::Name &name, const std::string &source="")
inserts name into NamePrefixList
std::tuple< ndn::Name, std::vector< std::string > > NamePair
uint32_t countSources(const ndn::Name &name) const
std::list< ndn::Name > getNames() const
const std::vector< std::string > getSources(const ndn::Name &name) const
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
Definition: adjacent.cpp:176