akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | c6a8522 | 2017-01-03 16:54:34 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, The University of Memphis, |
Nick Gordon | f8b5bcd | 2016-08-11 15:06:50 -0500 | [diff] [blame] | 4 | * Regents of the University of California |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 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 | * |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 20 | **/ |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 21 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 22 | #ifndef NLSR_FACE_MAP_HPP |
| 23 | #define NLSR_FACE_MAP_HPP |
| 24 | |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 25 | #include "common.hpp" |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 26 | |
Nick Gordon | b716847 | 2016-09-21 13:57:17 -0500 | [diff] [blame] | 27 | #include <map> |
| 28 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 29 | namespace nlsr { |
| 30 | |
Nick Gordon | 7b5872e | 2016-08-11 16:27:36 -0500 | [diff] [blame] | 31 | class FaceMapEntry |
| 32 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 33 | |
| 34 | public: |
| 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 | |
| 71 | private: |
| 72 | std::string m_faceUri; |
| 73 | uint32_t m_faceId; |
| 74 | }; |
| 75 | |
Nick Gordon | 7b5872e | 2016-08-11 16:27:36 -0500 | [diff] [blame] | 76 | class FaceMap |
| 77 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 78 | |
| 79 | public: |
| 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 Gordon | b716847 | 2016-09-21 13:57:17 -0500 | [diff] [blame] | 92 | std::map<std::string, FaceMapEntry>::iterator it = m_table.find(faceUri); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 93 | if (it == m_table.end()) { |
Nick Gordon | b716847 | 2016-09-21 13:57:17 -0500 | [diff] [blame] | 94 | m_table.emplace(faceUri, fme); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 95 | } |
| 96 | else { |
Nick Gordon | b716847 | 2016-09-21 13:57:17 -0500 | [diff] [blame] | 97 | (it->second).setFaceId(fme.getFaceId()); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
| 101 | inline uint32_t |
| 102 | getFaceId(const std::string& faceUri) |
| 103 | { |
| 104 | FaceMapEntry fme(faceUri, 0); |
Nick Gordon | b716847 | 2016-09-21 13:57:17 -0500 | [diff] [blame] | 105 | std::map<std::string, FaceMapEntry>::iterator it = m_table.find(faceUri); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 106 | if (it != m_table.end()) { |
Nick Gordon | b716847 | 2016-09-21 13:57:17 -0500 | [diff] [blame] | 107 | return (it->second).getFaceId(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 108 | } |
| 109 | return 0; |
| 110 | } |
| 111 | |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 112 | void |
| 113 | writeLog(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 114 | |
| 115 | private: |
Nick Gordon | b716847 | 2016-09-21 13:57:17 -0500 | [diff] [blame] | 116 | std::map<std::string, FaceMapEntry> m_table; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 117 | }; |
| 118 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 119 | } // namespace nlsr |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 120 | |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 121 | #endif // NLSR_FACE_MAP_HPP |