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 Nlsr;
58 
59 class Map
60 {
61 public:
62  Map()
63  : m_mappingIndex(0)
64  {
65  }
66 
73  void
74  addEntry(const ndn::Name& rtrName);
75 
80  template<typename IteratorType>
81  void
82  createFromAdjLsdb(IteratorType begin, IteratorType end)
83  {
84  BOOST_STATIC_ASSERT_MSG(is_iterator<IteratorType>::value, "IteratorType must be an iterator!");
85  for (auto lsa = begin; lsa != end; lsa++) {
86  addEntry(lsa->getOrigRouter());
87  for (const auto& adjacent : lsa->getAdl().getAdjList()) {
88  addEntry(adjacent.getName());
89  }
90  }
91  }
92 
97  template<typename IteratorType>
98  void
99  createFromCoordinateLsdb(IteratorType begin, IteratorType end)
100  {
101  BOOST_STATIC_ASSERT_MSG(is_iterator<IteratorType>::value, "IteratorType must be an iterator!");
102  for (auto lsa = begin; lsa != end; lsa++) {
103  addEntry(lsa->getOrigRouter());
104  }
105  }
106 
107  ndn::optional<ndn::Name>
108  getRouterNameByMappingNo(int32_t mn) const;
109 
110  ndn::optional<int32_t>
111  getMappingNoByRouterName(const ndn::Name& rName);
112 
113  void
114  reset();
115 
116  size_t
117  getMapSize() const
118  {
119  return m_entries.size();
120  }
121 
122  void
123  writeLog();
124 
125 private:
126  bool
127  addEntry(MapEntry& mpe);
128 
129  int32_t m_mappingIndex;
130  detail::entryContainer m_entries;
131 };
132 
133 } // namespace nlsr
134 
135 #endif // NLSR_MAP_HPP
size_t getMapSize() const
Definition: map.hpp:117
void createFromCoordinateLsdb(IteratorType begin, IteratorType end)
Definition: map.hpp:99
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-2017, The University of Memphis, Regents of the University of California.
void createFromAdjLsdb(IteratorType begin, IteratorType end)
Definition: map.hpp:82
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
Map()
Definition: map.hpp:62