name-prefix-list.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NLSR_NAME_PREFIX_LIST_HPP
23 #define NLSR_NAME_PREFIX_LIST_HPP
24 
25 #include "test-access-control.hpp"
26 
27 #include <list>
28 #include <string>
29 #include <ndn-cxx/name.hpp>
30 
31 namespace nlsr {
32 
34 {
35 public:
36  using NamePair = std::tuple<ndn::Name, std::vector<std::string>>;
39  SOURCES
40  };
41 
43 
44  NamePrefixList(const std::initializer_list<ndn::Name>& names);
45 
46  NamePrefixList(const std::initializer_list<NamePrefixList::NamePair>& namesAndSources);
47 
49  template<class ContainerType>
50  NamePrefixList(const ContainerType& names)
51  {
52  for (const auto& elem : names) {
53  m_names.push_back(NamePair{elem, {""}});
54  }
55  }
56 
57 public:
59 
64  bool
65  insert(const ndn::Name& name, const std::string& source = "");
66 
71  bool
72  remove(const ndn::Name& name, const std::string& source = "");
73 
74  void
75  sort();
76 
77  size_t
78  size() const
79  {
80  return m_names.size();
81  }
82 
83  std::list<ndn::Name>
84  getNames() const;
85 
86  bool
87  operator==(const NamePrefixList& other) const;
88 
93  uint32_t
94  countSources(const ndn::Name& name) const;
95 
101  const std::vector<std::string>
102  getSources(const ndn::Name& name) const;
103 
104  void
106  {
107  m_names.clear();
108  }
109 
110 private:
116  std::vector<NamePair>::iterator
117  get(const ndn::Name& name);
118 
121  std::vector<std::string>::iterator
122  getSource(const std::string& source, std::vector<NamePair>::iterator& entry);
123 
124  std::vector<NamePair> m_names;
125 };
126 
127 std::ostream&
128 operator<<(std::ostream& os, const NamePrefixList& list);
129 
130 } // namespace nlsr
131 
132 #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:179
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE