face-table.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2024, Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of NFD (Named Data Networking Forwarding Daemon).
12  * See AUTHORS.md for complete list of NFD authors and contributors.
13  *
14  * NFD is free software: you can redistribute it and/or modify it under the terms
15  * of the GNU General Public License as published by the Free Software Foundation,
16  * either version 3 of the License, or (at your option) any later version.
17  *
18  * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20  * PURPOSE. See the GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along with
23  * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #ifndef NFD_DAEMON_FW_FACE_TABLE_HPP
27 #define NFD_DAEMON_FW_FACE_TABLE_HPP
28 
29 #include "face/face.hpp"
30 
31 #include <boost/range/adaptor/indirected.hpp>
32 #include <boost/range/adaptor/map.hpp>
33 
34 #include <map>
35 
36 namespace nfd {
37 
41 class FaceTable : noncopyable
42 {
43 public:
49  void
50  add(shared_ptr<Face> face);
51 
54  void
55  addReserved(shared_ptr<Face> face, FaceId faceId);
56 
61  Face*
62  get(FaceId id) const noexcept;
63 
66  size_t
67  size() const noexcept;
68 
69 public: // enumeration
70  using FaceMap = std::map<FaceId, shared_ptr<Face>>;
71  using ForwardRange = boost::indirected_range<const boost::select_second_const_range<FaceMap>>;
72  using const_iterator = boost::range_iterator<ForwardRange>::type;
73 
75  begin() const;
76 
78  end() const;
79 
80 public: // signals
83  signal::Signal<FaceTable, Face> afterAdd;
84 
89  signal::Signal<FaceTable, Face> beforeRemove;
90 
91 private:
92  void
93  addImpl(shared_ptr<Face> face, FaceId faceId);
94 
95  void
96  remove(FaceId faceId);
97 
99  getForwardRange() const;
100 
101 private:
102  FaceId m_lastFaceId = face::FACEID_RESERVED_MAX;
103  FaceMap m_faces;
104 };
105 
106 } // namespace nfd
107 
108 #endif // NFD_DAEMON_FW_FACE_TABLE_HPP
Container of all faces.
Definition: face-table.hpp:42
const_iterator end() const
Definition: face-table.cpp:121
size_t size() const noexcept
Return the total number of faces.
Definition: face-table.cpp:45
signal::Signal< FaceTable, Face > beforeRemove
Fires immediately before a face is removed.
Definition: face-table.hpp:89
std::map< FaceId, shared_ptr< Face > > FaceMap
Definition: face-table.hpp:70
signal::Signal< FaceTable, Face > afterAdd
Fires immediately after a face is added.
Definition: face-table.hpp:83
boost::indirected_range< const boost::select_second_const_range< FaceMap > > ForwardRange
Definition: face-table.hpp:71
Face * get(FaceId id) const noexcept
Get face by FaceId.
Definition: face-table.cpp:38
const_iterator begin() const
Definition: face-table.cpp:115
void add(shared_ptr< Face > face)
Add a face.
Definition: face-table.cpp:51
void addReserved(shared_ptr< Face > face, FaceId faceId)
Add a special face with a reserved FaceId.
Definition: face-table.cpp:64
boost::range_iterator< ForwardRange >::type const_iterator
Definition: face-table.hpp:72
Generalization of a network interface.
Definition: face.hpp:118
constexpr FaceId FACEID_RESERVED_MAX
Upper bound of reserved FaceIds.
Definition: face-common.hpp:59
uint64_t FaceId
Identifies a face.
Definition: face-common.hpp:48
-status-http-server
Definition: common.hpp:71