Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NFD_FW_FACE_TABLE_HPP |
| 8 | #define NFD_FW_FACE_TABLE_HPP |
| 9 | |
| 10 | #include "face/face.hpp" |
| 11 | #include "core/map-value-iterator.hpp" |
| 12 | |
| 13 | namespace nfd |
| 14 | { |
| 15 | |
| 16 | class Forwarder; |
| 17 | |
| 18 | /** \brief container of all Faces |
| 19 | */ |
| 20 | class FaceTable |
| 21 | { |
| 22 | public: |
| 23 | explicit |
| 24 | FaceTable(Forwarder& forwarder); |
| 25 | |
| 26 | void |
| 27 | add(shared_ptr<Face> face); |
| 28 | |
| 29 | void |
| 30 | remove(shared_ptr<Face> face); |
| 31 | |
| 32 | shared_ptr<Face> |
| 33 | get(FaceId id) const; |
| 34 | |
| 35 | size_t |
| 36 | size() const; |
| 37 | |
| 38 | public: // enumeration |
| 39 | typedef std::map<FaceId, shared_ptr<Face> > FaceMap; |
| 40 | |
| 41 | /** \brief ForwarderIterator for shared_ptr<Face> |
| 42 | */ |
| 43 | typedef MapValueIterator<FaceMap> const_iterator; |
| 44 | |
| 45 | const_iterator |
| 46 | begin() const; |
| 47 | |
| 48 | const_iterator |
| 49 | end() const; |
| 50 | |
| 51 | private: |
| 52 | Forwarder& m_forwarder; |
| 53 | FaceId m_lastFaceId; |
| 54 | FaceMap m_faces; |
| 55 | }; |
| 56 | |
| 57 | inline shared_ptr<Face> |
| 58 | FaceTable::get(FaceId id) const |
| 59 | { |
| 60 | std::map<FaceId, shared_ptr<Face> >::const_iterator i = m_faces.find(id); |
| 61 | return (i == m_faces.end()) ? (shared_ptr<Face>()) : (i->second); |
| 62 | } |
| 63 | |
| 64 | inline size_t |
| 65 | FaceTable::size() const |
| 66 | { |
| 67 | return m_faces.size(); |
| 68 | } |
| 69 | |
| 70 | inline FaceTable::const_iterator |
| 71 | FaceTable::begin() const |
| 72 | { |
| 73 | return const_iterator(m_faces.begin()); |
| 74 | } |
| 75 | |
| 76 | inline FaceTable::const_iterator |
| 77 | FaceTable::end() const |
| 78 | { |
| 79 | return const_iterator(m_faces.end()); |
| 80 | } |
| 81 | |
| 82 | } // namespace nfd |
| 83 | |
| 84 | #endif // NFD_FW_FACE_TABLE_HPP |