Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 1 | /* -*- 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 | |
| 31 | namespace nfd { |
| 32 | namespace rib { |
| 33 | |
| 34 | /** \class RibEntry |
| 35 | * \brief represents a namespace |
| 36 | */ |
| 37 | class RibEntry : public enable_shared_from_this<RibEntry> |
| 38 | { |
| 39 | public: |
| 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 | |
| 113 | private: |
| 114 | void |
| 115 | setParent(shared_ptr<RibEntry> parent); |
| 116 | |
| 117 | private: |
| 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 | |
| 125 | inline void |
| 126 | RibEntry::setName(const Name& prefix) |
| 127 | { |
| 128 | m_name = prefix; |
| 129 | } |
| 130 | |
| 131 | inline const Name& |
| 132 | RibEntry::getName() const |
| 133 | { |
| 134 | return m_name; |
| 135 | } |
| 136 | |
| 137 | inline void |
| 138 | RibEntry::setParent(shared_ptr<RibEntry> parent) |
| 139 | { |
| 140 | m_parent = parent; |
| 141 | } |
| 142 | |
| 143 | inline shared_ptr<RibEntry> |
| 144 | RibEntry::getParent() const |
| 145 | { |
| 146 | return m_parent; |
| 147 | } |
| 148 | |
| 149 | inline std::list<shared_ptr<RibEntry> >& |
| 150 | RibEntry::getChildren() |
| 151 | { |
| 152 | return m_children; |
| 153 | } |
| 154 | |
| 155 | inline RibEntry::FaceList& |
| 156 | RibEntry::getFaces() |
| 157 | { |
| 158 | return m_faces; |
| 159 | } |
| 160 | |
| 161 | inline RibEntry::const_iterator |
| 162 | RibEntry::cbegin() const |
| 163 | { |
| 164 | return m_faces.begin(); |
| 165 | } |
| 166 | |
| 167 | inline RibEntry::const_iterator |
| 168 | RibEntry::cend() const |
| 169 | { |
| 170 | return m_faces.end(); |
| 171 | } |
| 172 | |
| 173 | inline RibEntry::iterator |
| 174 | RibEntry::begin() |
| 175 | { |
| 176 | return m_faces.begin(); |
| 177 | } |
| 178 | |
| 179 | inline RibEntry::iterator |
| 180 | RibEntry::end() |
| 181 | { |
| 182 | return m_faces.end(); |
| 183 | } |
| 184 | |
| 185 | } // namespace rib |
| 186 | } // namespace nfd |
| 187 | |
| 188 | #endif // NFD_RIB_RIB_ENTRY_HPP |