akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 1 | #ifndef NLSR_FACE_MAP_HPP |
| 2 | #define NLSR_FACE_MAP_HPP |
| 3 | |
| 4 | namespace nlsr { |
| 5 | |
| 6 | class FaceMapEntry { |
| 7 | |
| 8 | public: |
| 9 | FaceMapEntry(const std::string& faceUri, uint32_t faceId) |
| 10 | : m_faceUri(faceUri) |
| 11 | , m_faceId(faceId) |
| 12 | { |
| 13 | } |
| 14 | |
| 15 | void |
| 16 | setFaceUri(const std::string& faceUri) |
| 17 | { |
| 18 | m_faceUri = faceUri; |
| 19 | } |
| 20 | |
| 21 | const std::string& |
| 22 | getFaceUri() const |
| 23 | { |
| 24 | return m_faceUri; |
| 25 | } |
| 26 | |
| 27 | void |
| 28 | setFaceId(uint32_t faceId) |
| 29 | { |
| 30 | m_faceId = faceId; |
| 31 | } |
| 32 | |
| 33 | uint32_t |
| 34 | getFaceId() const |
| 35 | { |
| 36 | return m_faceId; |
| 37 | } |
| 38 | |
| 39 | bool |
| 40 | compare(const FaceMapEntry& fme) |
| 41 | { |
| 42 | return m_faceUri == fme.getFaceUri(); |
| 43 | } |
| 44 | |
| 45 | private: |
| 46 | std::string m_faceUri; |
| 47 | uint32_t m_faceId; |
| 48 | }; |
| 49 | |
| 50 | inline std::ostream& |
| 51 | operator<<(std::ostream& os, const FaceMapEntry& fme) |
| 52 | { |
| 53 | os << "Face Map Entry (FaceUri: " << fme.getFaceUri() << " Face Id: "; |
| 54 | os << fme.getFaceId() << ")" << std::endl; |
| 55 | return os; |
| 56 | } |
| 57 | |
| 58 | class FaceMap { |
| 59 | |
| 60 | public: |
| 61 | FaceMap() |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | ~FaceMap() |
| 66 | { |
| 67 | } |
| 68 | |
| 69 | inline void |
| 70 | update(const std::string& faceUri, uint32_t faceId) |
| 71 | { |
| 72 | FaceMapEntry fme(faceUri, faceId); |
| 73 | std::list<FaceMapEntry>::iterator it = std::find_if(m_table.begin(), |
| 74 | m_table.end(), |
| 75 | bind(&FaceMapEntry::compare, |
| 76 | &fme, _1)); |
| 77 | if (it == m_table.end()) { |
| 78 | m_table.push_back(fme); |
| 79 | } |
| 80 | else { |
| 81 | (*it).setFaceId(fme.getFaceId()); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | inline uint32_t |
| 86 | getFaceId(const std::string& faceUri) |
| 87 | { |
| 88 | FaceMapEntry fme(faceUri, 0); |
| 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 | return (*it).getFaceId(); |
| 95 | } |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | inline void |
| 100 | print() |
| 101 | { |
| 102 | std::cout << "------- Face Map-----------" << std::endl; |
| 103 | for(std::list<FaceMapEntry>::iterator it = m_table.begin(); |
| 104 | it != m_table.end(); ++it) { |
| 105 | std::cout << (*it); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | private: |
| 110 | std::list<FaceMapEntry> m_table; |
| 111 | }; |
| 112 | |
| 113 | } //namespace nlsr |
| 114 | |
| 115 | #endif //NLSR_FACE_MAP_HPP |