blob: ccd801bcd42be0b02f9e6c8e19362a5df9788e51 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 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 * \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
31class FaceMapEntry {
32
33public:
34 FaceMapEntry(const std::string& faceUri, uint32_t faceId)
35 : m_faceUri(faceUri)
36 , m_faceId(faceId)
37 {
38 }
39
40 void
41 setFaceUri(const std::string& faceUri)
42 {
43 m_faceUri = faceUri;
44 }
45
46 const std::string&
47 getFaceUri() const
48 {
49 return m_faceUri;
50 }
51
52 void
53 setFaceId(uint32_t faceId)
54 {
55 m_faceId = faceId;
56 }
57
58 uint32_t
59 getFaceId() const
60 {
61 return m_faceId;
62 }
63
64 bool
65 compare(const FaceMapEntry& fme)
66 {
67 return m_faceUri == fme.getFaceUri();
68 }
69
70private:
71 std::string m_faceUri;
72 uint32_t m_faceId;
73};
74
akmhoque157b0a42014-05-13 00:26:37 -050075class FaceMap {
76
77public:
78 FaceMap()
79 {
80 }
81
82 ~FaceMap()
83 {
84 }
85
86 inline void
87 update(const std::string& faceUri, uint32_t faceId)
88 {
89 FaceMapEntry fme(faceUri, faceId);
90 std::list<FaceMapEntry>::iterator it = std::find_if(m_table.begin(),
91 m_table.end(),
92 bind(&FaceMapEntry::compare,
93 &fme, _1));
94 if (it == m_table.end()) {
95 m_table.push_back(fme);
96 }
97 else {
98 (*it).setFaceId(fme.getFaceId());
99 }
100 }
101
102 inline uint32_t
103 getFaceId(const std::string& faceUri)
104 {
105 FaceMapEntry fme(faceUri, 0);
106 std::list<FaceMapEntry>::iterator it = std::find_if(m_table.begin(),
107 m_table.end(),
108 bind(&FaceMapEntry::compare,
109 &fme, _1));
110 if (it != m_table.end()) {
111 return (*it).getFaceId();
112 }
113 return 0;
114 }
115
akmhoque2f423352014-06-03 11:49:35 -0500116 void
117 writeLog();
akmhoque157b0a42014-05-13 00:26:37 -0500118
119private:
120 std::list<FaceMapEntry> m_table;
121};
122
123} //namespace nlsr
124
125#endif //NLSR_FACE_MAP_HPP