map.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
21 #include "map.hpp"
22 #include "nlsr.hpp"
23 #include "adjacent.hpp"
24 #include "lsa.hpp"
25 #include "lsdb.hpp"
26 #include "logger.hpp"
27 
28 #include <iostream>
29 #include <list>
30 
31 namespace nlsr {
32 
33 INIT_LOGGER("Map");
34 
35 void
36 Map::addEntry(const ndn::Name& rtrName)
37 {
38  MapEntry me(rtrName, m_mappingIndex);
39  if (addEntry(me)) {
40  m_mappingIndex++;
41  }
42 }
43 
44 bool
46 {
47  return m_entries.insert(mpe).second;
48 }
49 
50 ndn::optional<ndn::Name>
52 {
53  auto&& mappingNumberView = m_entries.get<detail::byMappingNumber>();
54  auto iterator = mappingNumberView.find(mn);
55  if (iterator == mappingNumberView.end()) {
56  return {};
57  }
58  else {
59  return {iterator->getRouter()};
60  }
61 }
62 
63 ndn::optional<int32_t>
64 Map::getMappingNoByRouterName(const ndn::Name& rName)
65 {
66  auto&& routerNameView = m_entries.get<detail::byRouterName>();
67  auto iterator = routerNameView.find(rName);
68  if (iterator == routerNameView.end()) {
69  return {};
70  }
71  else {
72  return {iterator->getMappingNumber()};
73  }
74 }
75 
76 void
78 {
79  m_entries = detail::entryContainer{};
80  m_mappingIndex = 0;
81 }
82 
83 void
85 {
86  NLSR_LOG_DEBUG("---------------Map----------------------");
87  auto&& routerNameView = m_entries.get<detail::byRouterName>();
88  for (auto entry = routerNameView.begin(); entry != routerNameView.end(); entry++) {
89  NLSR_LOG_DEBUG("MapEntry: ( Router: " << entry->getRouter() << " Mapping No: "
90  << entry->getMappingNumber() << " )");
91  }
92 }
93 
94 } // namespace nlsr
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
ndn::optional< int32_t > getMappingNoByRouterName(const ndn::Name &rName)
Definition: map.cpp:64
ndn::optional< ndn::Name > getRouterNameByMappingNo(int32_t mn)
Definition: map.cpp:51
#define NLSR_LOG_DEBUG(x)
Definition: logger.hpp:41
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California.
#define INIT_LOGGER(name)
Definition: logger.hpp:35
void writeLog()
Definition: map.cpp:84
void addEntry(const ndn::Name &rtrName)
Add a map entry to this map.
Definition: map.cpp:36
void reset()
Definition: map.cpp:77
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.