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-2022, 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 namespace nfd {
35 
39 class FaceTable : noncopyable
40 {
41 public:
47  void
48  add(shared_ptr<Face> face);
49 
52  void
53  addReserved(shared_ptr<Face> face, FaceId faceId);
54 
59  Face*
60  get(FaceId id) const noexcept;
61 
64  size_t
65  size() const noexcept;
66 
67 public: // enumeration
68  using FaceMap = std::map<FaceId, shared_ptr<Face>>;
69  using ForwardRange = boost::indirected_range<const boost::select_second_const_range<FaceMap>>;
70  using const_iterator = boost::range_iterator<ForwardRange>::type;
71 
73  begin() const;
74 
76  end() const;
77 
78 public: // signals
81  signal::Signal<FaceTable, Face> afterAdd;
82 
87  signal::Signal<FaceTable, Face> beforeRemove;
88 
89 private:
90  void
91  addImpl(shared_ptr<Face> face, FaceId faceId);
92 
93  void
94  remove(FaceId faceId);
95 
97  getForwardRange() const;
98 
99 private:
100  FaceId m_lastFaceId = face::FACEID_RESERVED_MAX;
101  FaceMap m_faces;
102 };
103 
104 } // namespace nfd
105 
106 #endif // NFD_DAEMON_FW_FACE_TABLE_HPP
Container of all faces.
Definition: face-table.hpp:40
const_iterator end() const
Definition: face-table.cpp:123
size_t size() const noexcept
Return the total number of faces.
Definition: face-table.cpp:47
signal::Signal< FaceTable, Face > beforeRemove
Fires immediately before a face is removed.
Definition: face-table.hpp:87
std::map< FaceId, shared_ptr< Face > > FaceMap
Definition: face-table.hpp:68
signal::Signal< FaceTable, Face > afterAdd
Fires immediately after a face is added.
Definition: face-table.hpp:81
boost::indirected_range< const boost::select_second_const_range< FaceMap > > ForwardRange
Definition: face-table.hpp:69
Face * get(FaceId id) const noexcept
Get face by FaceId.
Definition: face-table.cpp:40
const_iterator begin() const
Definition: face-table.cpp:117
void add(shared_ptr< Face > face)
Add a face.
Definition: face-table.cpp:53
void addReserved(shared_ptr< Face > face, FaceId faceId)
Add a special face with a reserved FaceId.
Definition: face-table.cpp:66
boost::range_iterator< ForwardRange >::type const_iterator
Definition: face-table.hpp:70
Generalization of a network interface.
Definition: face.hpp:56
constexpr FaceId FACEID_RESERVED_MAX
Upper bound of reserved FaceIds.
Definition: face-common.hpp:58
uint64_t FaceId
Identifies a face.
Definition: face-common.hpp:47
Definition: common.hpp:77