map.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
21 #ifndef NLSR_MAP_HPP
22 #define NLSR_MAP_HPP
23 
24 #include "common.hpp"
25 #include "map-entry.hpp"
26 
27 #include <iostream>
28 #include <list>
29 #include <boost/cstdint.hpp>
30 
31 #include <boost/multi_index_container.hpp>
32 #include <boost/multi_index/hashed_index.hpp>
33 #include <boost/multi_index/mem_fun.hpp>
34 #include <boost/multi_index/tag.hpp>
35 
36 namespace nlsr {
37 
38 namespace detail {
39 
40  using namespace boost::multi_index;
41  // Define tags so that we can search by different indices.
42  struct byRouterName {};
43  struct byMappingNumber{};
44  using entryContainer = multi_index_container<
45  MapEntry,
46  indexed_by<
47  hashed_unique<tag<byRouterName>,
48  const_mem_fun<MapEntry, const ndn::Name&, &MapEntry::getRouter>,
49  std::hash<ndn::Name>>,
50  hashed_unique<tag<byMappingNumber>,
51  const_mem_fun<MapEntry, int32_t, &MapEntry::getMappingNumber>>
52  >
53  >;
54 
55 } // namespace detail
56 
57 class Map
58 {
59 public:
60  Map()
61  : m_mappingIndex(0)
62  {
63  }
64 
71  void
72  addEntry(const ndn::Name& rtrName);
73 
78  template<typename IteratorType>
79  void
80  createFromAdjLsdb(IteratorType begin, IteratorType end)
81  {
82  BOOST_STATIC_ASSERT_MSG(is_iterator<IteratorType>::value, "IteratorType must be an iterator!");
83  for (auto lsa = begin; lsa != end; lsa++) {
84  addEntry(lsa->getOrigRouter());
85  for (const auto& adjacent : lsa->getAdl().getAdjList()) {
86  addEntry(adjacent.getName());
87  }
88  }
89  }
90 
95  template<typename IteratorType>
96  void
97  createFromCoordinateLsdb(IteratorType begin, IteratorType end)
98  {
99  BOOST_STATIC_ASSERT_MSG(is_iterator<IteratorType>::value, "IteratorType must be an iterator!");
100  for (auto lsa = begin; lsa != end; lsa++) {
101  addEntry(lsa->getOrigRouter());
102  }
103  }
104 
105  ndn::optional<ndn::Name>
106  getRouterNameByMappingNo(int32_t mn) const;
107 
108  ndn::optional<int32_t>
109  getMappingNoByRouterName(const ndn::Name& rName);
110 
111  void
112  reset();
113 
114  size_t
115  getMapSize() const
116  {
117  return m_entries.size();
118  }
119 
120  void
121  writeLog();
122 
123 private:
124  bool
125  addEntry(MapEntry& mpe);
126 
127  int32_t m_mappingIndex;
128  detail::entryContainer m_entries;
129 };
130 
131 } // namespace nlsr
132 
133 #endif // NLSR_MAP_HPP
size_t getMapSize() const
Definition: map.hpp:115
void createFromCoordinateLsdb(IteratorType begin, IteratorType end)
Definition: map.hpp:97
multi_index_container< MapEntry, indexed_by< hashed_unique< tag< byRouterName >, const_mem_fun< MapEntry, const ndn::Name &,&MapEntry::getRouter >, std::hash< ndn::Name >>, hashed_unique< tag< byMappingNumber >, const_mem_fun< MapEntry, int32_t,&MapEntry::getMappingNumber >> > > entryContainer
Definition: map.hpp:53
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
void createFromAdjLsdb(IteratorType begin, IteratorType end)
Definition: map.hpp:80
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
Map()
Definition: map.hpp:60