HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 24 | |
| 25 | // Name Tree Entry (i.e., Name Prefix Entry) |
| 26 | |
| 27 | #ifndef NFD_TABLE_NAME_TREE_ENTRY_HPP |
| 28 | #define NFD_TABLE_NAME_TREE_ENTRY_HPP |
| 29 | |
| 30 | #include "common.hpp" |
| 31 | #include "table/fib-entry.hpp" |
| 32 | #include "table/pit-entry.hpp" |
| 33 | #include "table/measurements-entry.hpp" |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 34 | #include "table/strategy-choice-entry.hpp" |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 35 | |
| 36 | namespace nfd { |
| 37 | |
| 38 | class NameTree; |
| 39 | |
| 40 | namespace name_tree { |
| 41 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 42 | // Forward declarations |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 43 | class Node; |
| 44 | class Entry; |
| 45 | |
| 46 | /** |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 47 | * \brief Name Tree Node Class |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 48 | */ |
| 49 | class Node |
| 50 | { |
| 51 | public: |
| 52 | Node(); |
| 53 | |
| 54 | ~Node(); |
| 55 | |
| 56 | public: |
| 57 | // variables are in public as this is just a data structure |
| 58 | shared_ptr<Entry> m_entry; // Name Tree Entry (i.e., Name Prefix Entry) |
| 59 | Node* m_prev; // Previous Name Tree Node (to resolve hash collision) |
| 60 | Node* m_next; // Next Name Tree Node (to resolve hash collision) |
| 61 | }; |
| 62 | |
| 63 | /** |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 64 | * \brief Name Tree Entry Class |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 65 | */ |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 66 | class Entry : public enable_shared_from_this<Entry>, noncopyable |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 67 | { |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 68 | public: |
| 69 | explicit |
| 70 | Entry(const Name& prefix); |
| 71 | |
| 72 | ~Entry(); |
| 73 | |
| 74 | const Name& |
| 75 | getPrefix() const; |
| 76 | |
| 77 | void |
| 78 | setHash(uint32_t hash); |
| 79 | |
| 80 | uint32_t |
| 81 | getHash() const; |
| 82 | |
| 83 | void |
| 84 | setParent(shared_ptr<Entry> parent); |
| 85 | |
| 86 | shared_ptr<Entry> |
| 87 | getParent() const; |
| 88 | |
| 89 | std::vector<shared_ptr<Entry> >& |
| 90 | getChildren(); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 91 | |
| 92 | bool |
| 93 | hasChildren() const; |
| 94 | |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 95 | bool |
| 96 | isEmpty() const; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 97 | |
| 98 | void |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 99 | setFibEntry(shared_ptr<fib::Entry> fibEntry); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 100 | |
| 101 | shared_ptr<fib::Entry> |
| 102 | getFibEntry() const; |
| 103 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 104 | void |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 105 | insertPitEntry(shared_ptr<pit::Entry> pitEntry); |
| 106 | |
| 107 | void |
| 108 | erasePitEntry(shared_ptr<pit::Entry> pitEntry); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 109 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 110 | bool |
| 111 | hasPitEntries() const; |
| 112 | |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 113 | const std::vector<shared_ptr<pit::Entry> >& |
| 114 | getPitEntries() const; |
| 115 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 116 | void |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 117 | setMeasurementsEntry(shared_ptr<measurements::Entry> measurementsEntry); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 118 | |
| 119 | shared_ptr<measurements::Entry> |
| 120 | getMeasurementsEntry() const; |
| 121 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 122 | void |
| 123 | setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry); |
| 124 | |
| 125 | shared_ptr<strategy_choice::Entry> |
| 126 | getStrategyChoiceEntry() const; |
| 127 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 128 | private: |
| 129 | uint32_t m_hash; |
| 130 | Name m_prefix; |
| 131 | shared_ptr<Entry> m_parent; // Pointing to the parent entry. |
| 132 | std::vector<shared_ptr<Entry> > m_children; // Children pointers. |
| 133 | shared_ptr<fib::Entry> m_fibEntry; |
| 134 | std::vector<shared_ptr<pit::Entry> > m_pitEntries; |
| 135 | shared_ptr<measurements::Entry> m_measurementsEntry; |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 136 | shared_ptr<strategy_choice::Entry> m_strategyChoiceEntry; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 137 | |
| 138 | // get the Name Tree Node that is associated with this Name Tree Entry |
| 139 | Node* m_node; |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 140 | // Make private members accessible by Name Tree |
| 141 | friend class nfd::NameTree; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | inline const Name& |
| 145 | Entry::getPrefix() const |
| 146 | { |
| 147 | return m_prefix; |
| 148 | } |
| 149 | |
| 150 | inline uint32_t |
| 151 | Entry::getHash() const |
| 152 | { |
| 153 | return m_hash; |
| 154 | } |
| 155 | |
| 156 | inline shared_ptr<Entry> |
| 157 | Entry::getParent() const |
| 158 | { |
| 159 | return m_parent; |
| 160 | } |
| 161 | |
| 162 | inline std::vector<shared_ptr<name_tree::Entry> >& |
| 163 | Entry::getChildren() |
| 164 | { |
| 165 | return m_children; |
| 166 | } |
| 167 | |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 168 | inline bool |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 169 | Entry::hasChildren() const |
| 170 | { |
| 171 | return !m_children.empty(); |
| 172 | } |
| 173 | |
| 174 | inline bool |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 175 | Entry::isEmpty() const |
| 176 | { |
| 177 | return m_children.empty() && |
| 178 | !static_cast<bool>(m_fibEntry) && |
| 179 | m_pitEntries.empty() && |
| 180 | !static_cast<bool>(m_measurementsEntry); |
| 181 | } |
| 182 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 183 | inline shared_ptr<fib::Entry> |
| 184 | Entry::getFibEntry() const |
| 185 | { |
| 186 | return m_fibEntry; |
| 187 | } |
| 188 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 189 | inline bool |
| 190 | Entry::hasPitEntries() const |
| 191 | { |
| 192 | return !m_pitEntries.empty(); |
| 193 | } |
| 194 | |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 195 | inline const std::vector<shared_ptr<pit::Entry> >& |
| 196 | Entry::getPitEntries() const |
| 197 | { |
| 198 | return m_pitEntries; |
| 199 | } |
| 200 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 201 | inline shared_ptr<measurements::Entry> |
| 202 | Entry::getMeasurementsEntry() const |
| 203 | { |
| 204 | return m_measurementsEntry; |
| 205 | } |
| 206 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 207 | inline shared_ptr<strategy_choice::Entry> |
| 208 | Entry::getStrategyChoiceEntry() const |
| 209 | { |
| 210 | return m_strategyChoiceEntry; |
| 211 | } |
| 212 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 213 | } // namespace name_tree |
| 214 | } // namespace nfd |
| 215 | |
| 216 | #endif // NFD_TABLE_NAME_TREE_ENTRY_HPP |