blob: 24155682653478c323f80bf730cd8bc8dcfa0a0f [file] [log] [blame]
Junxiao Shia4f2be82014-03-02 22:56:41 -07001/* -*- 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
13namespace nfd
14{
15
16class Forwarder;
17
18/** \brief container of all Faces
19 */
20class FaceTable
21{
22public:
23 explicit
24 FaceTable(Forwarder& forwarder);
25
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070026 VIRTUAL_WITH_TESTS
27 ~FaceTable();
28
29 VIRTUAL_WITH_TESTS void
Junxiao Shia4f2be82014-03-02 22:56:41 -070030 add(shared_ptr<Face> face);
31
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070032 VIRTUAL_WITH_TESTS void
Junxiao Shia4f2be82014-03-02 22:56:41 -070033 remove(shared_ptr<Face> face);
34
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070035 VIRTUAL_WITH_TESTS shared_ptr<Face>
Junxiao Shia4f2be82014-03-02 22:56:41 -070036 get(FaceId id) const;
37
38 size_t
39 size() const;
40
41public: // enumeration
42 typedef std::map<FaceId, shared_ptr<Face> > FaceMap;
43
44 /** \brief ForwarderIterator for shared_ptr<Face>
45 */
46 typedef MapValueIterator<FaceMap> const_iterator;
47
48 const_iterator
49 begin() const;
50
51 const_iterator
52 end() const;
53
54private:
55 Forwarder& m_forwarder;
56 FaceId m_lastFaceId;
57 FaceMap m_faces;
58};
59
60inline shared_ptr<Face>
61FaceTable::get(FaceId id) const
62{
63 std::map<FaceId, shared_ptr<Face> >::const_iterator i = m_faces.find(id);
64 return (i == m_faces.end()) ? (shared_ptr<Face>()) : (i->second);
65}
66
67inline size_t
68FaceTable::size() const
69{
70 return m_faces.size();
71}
72
73inline FaceTable::const_iterator
74FaceTable::begin() const
75{
76 return const_iterator(m_faces.begin());
77}
78
79inline FaceTable::const_iterator
80FaceTable::end() const
81{
82 return const_iterator(m_faces.end());
83}
84
85} // namespace nfd
86
87#endif // NFD_FW_FACE_TABLE_HPP