Loading...
Searching...
No Matches
name-map.cpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2024, The University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "name-map.hpp"
22#include "nlsr.hpp"
23#include "adjacent.hpp"
24#include "lsa/lsa.hpp"
25#include "lsdb.hpp"
26
27namespace nlsr {
28
29void
30NameMap::addEntry(const ndn::Name& rtrName)
31{
32 int32_t mappingNo = static_cast<int32_t>(m_bimap.size());
33 m_bimap.by<ndn::Name>().insert({rtrName, mappingNo});
34}
35
36std::optional<ndn::Name>
38{
39 auto it = m_bimap.by<MappingNo>().find(mn);
40 if (it == m_bimap.by<MappingNo>().end()) {
41 return std::nullopt;
42 }
43 return it->get<ndn::Name>();
44}
45
46std::optional<int32_t>
47NameMap::getMappingNoByRouterName(const ndn::Name& rtrName) const
48{
49 auto it = m_bimap.by<ndn::Name>().find(rtrName);
50 if (it == m_bimap.by<ndn::Name>().end()) {
51 return std::nullopt;
52 }
53 return it->get<MappingNo>();
54}
55
56std::ostream&
57operator<<(std::ostream& os, const NameMap& map)
58{
59 os << "---------------NameMap---------------";
60 for (const auto& entry : map.m_bimap) {
61 os << "\nMapEntry: ( Router: " << entry.get<ndn::Name>()
62 << " Mapping No: " << entry.get<NameMap::MappingNo>() << " )";
63 }
64 return os;
65}
66
67} // namespace nlsr
Assigning numbers to router names.
Definition name-map.hpp:46
std::optional< ndn::Name > getRouterNameByMappingNo(int32_t mn) const
Find router name by its mapping number.
Definition name-map.cpp:37
std::optional< int32_t > getMappingNoByRouterName(const ndn::Name &rtrName) const
Find mapping number of a router name.
Definition name-map.cpp:47
void addEntry(const ndn::Name &rtrName)
Insert a router name.
Definition name-map.cpp:30
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