blob: 4726a040e6bf25de0564daca2ff1ef9a76a4b098 [file] [log] [blame]
Vince12e49462014-06-09 13:29:32 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, 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_RIB_RIB_ENTRY_HPP
27#define NFD_RIB_RIB_ENTRY_HPP
28
29#include "face-entry.hpp"
30
31namespace nfd {
32namespace rib {
33
34/** \class RibEntry
35 * \brief represents a namespace
36 */
37class RibEntry : public enable_shared_from_this<RibEntry>
38{
39public:
40 typedef std::list<FaceEntry> FaceList;
41 typedef FaceList::iterator iterator;
42 typedef FaceList::const_iterator const_iterator;
43
44 RibEntry()
45 {
46 }
47
48 void
49 setName(const Name& prefix);
50
51 const Name&
52 getName() const;
53
54 shared_ptr<RibEntry>
55 getParent() const;
56
57 bool
58 hasParent() const;
59
60 void
61 addChild(shared_ptr<RibEntry> child);
62
63 void
64 removeChild(shared_ptr<RibEntry> child);
65
66 std::list<shared_ptr<RibEntry> >&
67 getChildren();
68
69 bool
70 hasChildren() const;
71
72 /** \brief inserts a new face into the entry's face list
73 * If another entry already exists with the same faceId and origin,
74 * the new face is not inserted.
75 * \return{ true if the face is inserted, false otherwise }
76 */
77 bool
78 insertFace(const FaceEntry& face);
79
80 /** \brief erases a FaceEntry with the same faceId and origin
81 * \return{ true if the face is removed, false otherwise }
82 */
83 bool
84 eraseFace(const FaceEntry& face);
85
86 /** \brief erases a FaceEntry with the passed iterator
87 * \return{ an iterator to the element that followed the erased iterator }
88 */
89 iterator
90 eraseFace(FaceList::iterator face);
91
92 bool
93 hasFaceId(const uint64_t faceId) const;
94
95 FaceList&
96 getFaces();
97
98 iterator
99 findFace(const FaceEntry& face);
100
101 const_iterator
102 cbegin() const;
103
104 const_iterator
105 cend() const;
106
107 iterator
108 begin();
109
110 iterator
111 end();
112
113private:
114 void
115 setParent(shared_ptr<RibEntry> parent);
116
117private:
118 Name m_name;
119 std::list<shared_ptr<RibEntry> > m_children;
120 shared_ptr<RibEntry> m_parent;
121 FaceList m_faces;
122 FaceList m_inheritedFaces;
123};
124
125inline void
126RibEntry::setName(const Name& prefix)
127{
128 m_name = prefix;
129}
130
131inline const Name&
132RibEntry::getName() const
133{
134 return m_name;
135}
136
137inline void
138RibEntry::setParent(shared_ptr<RibEntry> parent)
139{
140 m_parent = parent;
141}
142
143inline shared_ptr<RibEntry>
144RibEntry::getParent() const
145{
146 return m_parent;
147}
148
149inline std::list<shared_ptr<RibEntry> >&
150RibEntry::getChildren()
151{
152 return m_children;
153}
154
155inline RibEntry::FaceList&
156RibEntry::getFaces()
157{
158 return m_faces;
159}
160
161inline RibEntry::const_iterator
162RibEntry::cbegin() const
163{
164 return m_faces.begin();
165}
166
167inline RibEntry::const_iterator
168RibEntry::cend() const
169{
170 return m_faces.end();
171}
172
173inline RibEntry::iterator
174RibEntry::begin()
175{
176 return m_faces.begin();
177}
178
179inline RibEntry::iterator
180RibEntry::end()
181{
182 return m_faces.end();
183}
184
185} // namespace rib
186} // namespace nfd
187
188#endif // NFD_RIB_RIB_ENTRY_HPP