blob: 6a2890f9accb9599c9120b721b890514f06e79c0 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonf8b5bcd2016-08-11 15:06:50 -05003 * Copyright (c) 2014-2016, The University of Memphis,
4 * 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 *
20 * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21 *
22 **/
akmhoque157b0a42014-05-13 00:26:37 -050023#ifndef NLSR_FACE_MAP_HPP
24#define NLSR_FACE_MAP_HPP
25
akmhoque2f423352014-06-03 11:49:35 -050026#include <ndn-cxx/common.hpp>
Vince Lehman0a7da612014-10-29 14:39:29 -050027#include <algorithm>
akmhoque2f423352014-06-03 11:49:35 -050028
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);
92 std::list<FaceMapEntry>::iterator it = std::find_if(m_table.begin(),
93 m_table.end(),
94 bind(&FaceMapEntry::compare,
95 &fme, _1));
96 if (it == m_table.end()) {
97 m_table.push_back(fme);
98 }
99 else {
100 (*it).setFaceId(fme.getFaceId());
101 }
102 }
103
104 inline uint32_t
105 getFaceId(const std::string& faceUri)
106 {
107 FaceMapEntry fme(faceUri, 0);
108 std::list<FaceMapEntry>::iterator it = std::find_if(m_table.begin(),
109 m_table.end(),
110 bind(&FaceMapEntry::compare,
111 &fme, _1));
112 if (it != m_table.end()) {
113 return (*it).getFaceId();
114 }
115 return 0;
116 }
117
akmhoque2f423352014-06-03 11:49:35 -0500118 void
119 writeLog();
akmhoque157b0a42014-05-13 00:26:37 -0500120
121private:
122 std::list<FaceMapEntry> m_table;
123};
124
Nick Gordonfad8e252016-08-11 14:21:38 -0500125} // namespace nlsr
akmhoque157b0a42014-05-13 00:26:37 -0500126
127#endif //NLSR_FACE_MAP_HPP