blob: 9505229c879c360a98927b6dd15582d908930fed [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, The University of Memphis,
Nick Gordonf8b5bcd2016-08-11 15:06:50 -05004 * Regents of the University of California
akmhoque3d06e792014-05-27 16:23:20 -05005 *
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 *
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050021
akmhoque157b0a42014-05-13 00:26:37 -050022#ifndef NLSR_FACE_MAP_HPP
23#define NLSR_FACE_MAP_HPP
24
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050025#include "common.hpp"
akmhoque2f423352014-06-03 11:49:35 -050026
Nick Gordonb7168472016-09-21 13:57:17 -050027#include <map>
28
akmhoque157b0a42014-05-13 00:26:37 -050029namespace nlsr {
30
Nick Gordon7b5872e2016-08-11 16:27:36 -050031class FaceMapEntry
32{
akmhoque157b0a42014-05-13 00:26:37 -050033
34public:
35 FaceMapEntry(const std::string& faceUri, uint32_t faceId)
36 : m_faceUri(faceUri)
37 , m_faceId(faceId)
38 {
39 }
40
41 void
42 setFaceUri(const std::string& faceUri)
43 {
44 m_faceUri = faceUri;
45 }
46
47 const std::string&
48 getFaceUri() const
49 {
50 return m_faceUri;
51 }
52
53 void
54 setFaceId(uint32_t faceId)
55 {
56 m_faceId = faceId;
57 }
58
59 uint32_t
60 getFaceId() const
61 {
62 return m_faceId;
63 }
64
65 bool
66 compare(const FaceMapEntry& fme)
67 {
68 return m_faceUri == fme.getFaceUri();
69 }
70
71private:
72 std::string m_faceUri;
73 uint32_t m_faceId;
74};
75
Nick Gordon7b5872e2016-08-11 16:27:36 -050076class FaceMap
77{
akmhoque157b0a42014-05-13 00:26:37 -050078
79public:
80 FaceMap()
81 {
82 }
83
84 ~FaceMap()
85 {
86 }
87
88 inline void
89 update(const std::string& faceUri, uint32_t faceId)
90 {
91 FaceMapEntry fme(faceUri, faceId);
Nick Gordonb7168472016-09-21 13:57:17 -050092 std::map<std::string, FaceMapEntry>::iterator it = m_table.find(faceUri);
akmhoque157b0a42014-05-13 00:26:37 -050093 if (it == m_table.end()) {
Nick Gordonb7168472016-09-21 13:57:17 -050094 m_table.emplace(faceUri, fme);
akmhoque157b0a42014-05-13 00:26:37 -050095 }
96 else {
Nick Gordonb7168472016-09-21 13:57:17 -050097 (it->second).setFaceId(fme.getFaceId());
akmhoque157b0a42014-05-13 00:26:37 -050098 }
99 }
100
101 inline uint32_t
102 getFaceId(const std::string& faceUri)
103 {
104 FaceMapEntry fme(faceUri, 0);
Nick Gordonb7168472016-09-21 13:57:17 -0500105 std::map<std::string, FaceMapEntry>::iterator it = m_table.find(faceUri);
akmhoque157b0a42014-05-13 00:26:37 -0500106 if (it != m_table.end()) {
Nick Gordonb7168472016-09-21 13:57:17 -0500107 return (it->second).getFaceId();
akmhoque157b0a42014-05-13 00:26:37 -0500108 }
109 return 0;
110 }
111
akmhoque2f423352014-06-03 11:49:35 -0500112 void
113 writeLog();
akmhoque157b0a42014-05-13 00:26:37 -0500114
115private:
Nick Gordonb7168472016-09-21 13:57:17 -0500116 std::map<std::string, FaceMapEntry> m_table;
akmhoque157b0a42014-05-13 00:26:37 -0500117};
118
Nick Gordonfad8e252016-08-11 14:21:38 -0500119} // namespace nlsr
akmhoque157b0a42014-05-13 00:26:37 -0500120
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500121#endif // NLSR_FACE_MAP_HPP