akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- 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 | **/ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 23 | #ifndef NLSR_FACE_MAP_HPP |
| 24 | #define NLSR_FACE_MAP_HPP |
| 25 | |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame^] | 26 | #include <ndn-cxx/common.hpp> |
| 27 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 28 | namespace nlsr { |
| 29 | |
| 30 | class FaceMapEntry { |
| 31 | |
| 32 | public: |
| 33 | FaceMapEntry(const std::string& faceUri, uint32_t faceId) |
| 34 | : m_faceUri(faceUri) |
| 35 | , m_faceId(faceId) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | void |
| 40 | setFaceUri(const std::string& faceUri) |
| 41 | { |
| 42 | m_faceUri = faceUri; |
| 43 | } |
| 44 | |
| 45 | const std::string& |
| 46 | getFaceUri() const |
| 47 | { |
| 48 | return m_faceUri; |
| 49 | } |
| 50 | |
| 51 | void |
| 52 | setFaceId(uint32_t faceId) |
| 53 | { |
| 54 | m_faceId = faceId; |
| 55 | } |
| 56 | |
| 57 | uint32_t |
| 58 | getFaceId() const |
| 59 | { |
| 60 | return m_faceId; |
| 61 | } |
| 62 | |
| 63 | bool |
| 64 | compare(const FaceMapEntry& fme) |
| 65 | { |
| 66 | return m_faceUri == fme.getFaceUri(); |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | std::string m_faceUri; |
| 71 | uint32_t m_faceId; |
| 72 | }; |
| 73 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 74 | class FaceMap { |
| 75 | |
| 76 | public: |
| 77 | FaceMap() |
| 78 | { |
| 79 | } |
| 80 | |
| 81 | ~FaceMap() |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | inline void |
| 86 | update(const std::string& faceUri, uint32_t faceId) |
| 87 | { |
| 88 | FaceMapEntry fme(faceUri, faceId); |
| 89 | std::list<FaceMapEntry>::iterator it = std::find_if(m_table.begin(), |
| 90 | m_table.end(), |
| 91 | bind(&FaceMapEntry::compare, |
| 92 | &fme, _1)); |
| 93 | if (it == m_table.end()) { |
| 94 | m_table.push_back(fme); |
| 95 | } |
| 96 | else { |
| 97 | (*it).setFaceId(fme.getFaceId()); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | inline uint32_t |
| 102 | getFaceId(const std::string& faceUri) |
| 103 | { |
| 104 | FaceMapEntry fme(faceUri, 0); |
| 105 | std::list<FaceMapEntry>::iterator it = std::find_if(m_table.begin(), |
| 106 | m_table.end(), |
| 107 | bind(&FaceMapEntry::compare, |
| 108 | &fme, _1)); |
| 109 | if (it != m_table.end()) { |
| 110 | return (*it).getFaceId(); |
| 111 | } |
| 112 | return 0; |
| 113 | } |
| 114 | |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame^] | 115 | void |
| 116 | writeLog(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 117 | |
| 118 | private: |
| 119 | std::list<FaceMapEntry> m_table; |
| 120 | }; |
| 121 | |
| 122 | } //namespace nlsr |
| 123 | |
| 124 | #endif //NLSR_FACE_MAP_HPP |