HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | // Name Tree Entry (i.e., Name Prefix Entry) |
| 8 | |
| 9 | #ifndef NFD_TABLE_NAME_TREE_ENTRY_HPP |
| 10 | #define NFD_TABLE_NAME_TREE_ENTRY_HPP |
| 11 | |
| 12 | #include "common.hpp" |
| 13 | #include "table/fib-entry.hpp" |
| 14 | #include "table/pit-entry.hpp" |
| 15 | #include "table/measurements-entry.hpp" |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 16 | #include "table/strategy-choice-entry.hpp" |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 17 | |
| 18 | namespace nfd { |
| 19 | |
| 20 | class NameTree; |
| 21 | |
| 22 | namespace name_tree { |
| 23 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 24 | // Forward declarations |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 25 | class Node; |
| 26 | class Entry; |
| 27 | |
| 28 | /** |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 29 | * \brief Name Tree Node Class |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 30 | */ |
| 31 | class Node |
| 32 | { |
| 33 | public: |
| 34 | Node(); |
| 35 | |
| 36 | ~Node(); |
| 37 | |
| 38 | public: |
| 39 | // variables are in public as this is just a data structure |
| 40 | shared_ptr<Entry> m_entry; // Name Tree Entry (i.e., Name Prefix Entry) |
| 41 | Node* m_prev; // Previous Name Tree Node (to resolve hash collision) |
| 42 | Node* m_next; // Next Name Tree Node (to resolve hash collision) |
| 43 | }; |
| 44 | |
| 45 | /** |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 46 | * \brief Name Tree Entry Class |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 47 | */ |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 48 | class Entry : public enable_shared_from_this<Entry>, noncopyable |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 49 | { |
| 50 | // Make private members accessible by Name Tree |
| 51 | friend class nfd::NameTree; |
| 52 | public: |
| 53 | explicit |
| 54 | Entry(const Name& prefix); |
| 55 | |
| 56 | ~Entry(); |
| 57 | |
| 58 | const Name& |
| 59 | getPrefix() const; |
| 60 | |
| 61 | void |
| 62 | setHash(uint32_t hash); |
| 63 | |
| 64 | uint32_t |
| 65 | getHash() const; |
| 66 | |
| 67 | void |
| 68 | setParent(shared_ptr<Entry> parent); |
| 69 | |
| 70 | shared_ptr<Entry> |
| 71 | getParent() const; |
| 72 | |
| 73 | std::vector<shared_ptr<Entry> >& |
| 74 | getChildren(); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 75 | |
| 76 | bool |
| 77 | hasChildren() const; |
| 78 | |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 79 | bool |
| 80 | isEmpty() const; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 81 | |
| 82 | void |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 83 | setFibEntry(shared_ptr<fib::Entry> fibEntry); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 84 | |
| 85 | shared_ptr<fib::Entry> |
| 86 | getFibEntry() const; |
| 87 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 88 | void |
| 89 | insertPitEntry(shared_ptr<pit::Entry> pit); |
| 90 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 91 | bool |
| 92 | hasPitEntries() const; |
| 93 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 94 | std::vector<shared_ptr<pit::Entry> >& |
| 95 | getPitEntries(); |
| 96 | |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame^] | 97 | const std::vector<shared_ptr<pit::Entry> >& |
| 98 | getPitEntries() const; |
| 99 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 100 | /** |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 101 | * \brief Erase a PIT Entry |
| 102 | * \details The address of this PIT Entry is required |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 103 | */ |
| 104 | bool |
| 105 | erasePitEntry(shared_ptr<pit::Entry> pit); |
| 106 | |
| 107 | void |
| 108 | setMeasurementsEntry(shared_ptr<measurements::Entry> measurements); |
| 109 | |
| 110 | shared_ptr<measurements::Entry> |
| 111 | getMeasurementsEntry() const; |
| 112 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 113 | void |
| 114 | setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry); |
| 115 | |
| 116 | shared_ptr<strategy_choice::Entry> |
| 117 | getStrategyChoiceEntry() const; |
| 118 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 119 | private: |
| 120 | uint32_t m_hash; |
| 121 | Name m_prefix; |
| 122 | shared_ptr<Entry> m_parent; // Pointing to the parent entry. |
| 123 | std::vector<shared_ptr<Entry> > m_children; // Children pointers. |
| 124 | shared_ptr<fib::Entry> m_fibEntry; |
| 125 | std::vector<shared_ptr<pit::Entry> > m_pitEntries; |
| 126 | shared_ptr<measurements::Entry> m_measurementsEntry; |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 127 | shared_ptr<strategy_choice::Entry> m_strategyChoiceEntry; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 128 | |
| 129 | // get the Name Tree Node that is associated with this Name Tree Entry |
| 130 | Node* m_node; |
| 131 | }; |
| 132 | |
| 133 | inline const Name& |
| 134 | Entry::getPrefix() const |
| 135 | { |
| 136 | return m_prefix; |
| 137 | } |
| 138 | |
| 139 | inline uint32_t |
| 140 | Entry::getHash() const |
| 141 | { |
| 142 | return m_hash; |
| 143 | } |
| 144 | |
| 145 | inline shared_ptr<Entry> |
| 146 | Entry::getParent() const |
| 147 | { |
| 148 | return m_parent; |
| 149 | } |
| 150 | |
| 151 | inline std::vector<shared_ptr<name_tree::Entry> >& |
| 152 | Entry::getChildren() |
| 153 | { |
| 154 | return m_children; |
| 155 | } |
| 156 | |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 157 | inline bool |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 158 | Entry::hasChildren() const |
| 159 | { |
| 160 | return !m_children.empty(); |
| 161 | } |
| 162 | |
| 163 | inline bool |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 164 | Entry::isEmpty() const |
| 165 | { |
| 166 | return m_children.empty() && |
| 167 | !static_cast<bool>(m_fibEntry) && |
| 168 | m_pitEntries.empty() && |
| 169 | !static_cast<bool>(m_measurementsEntry); |
| 170 | } |
| 171 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 172 | inline shared_ptr<fib::Entry> |
| 173 | Entry::getFibEntry() const |
| 174 | { |
| 175 | return m_fibEntry; |
| 176 | } |
| 177 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 178 | inline bool |
| 179 | Entry::hasPitEntries() const |
| 180 | { |
| 181 | return !m_pitEntries.empty(); |
| 182 | } |
| 183 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 184 | inline std::vector<shared_ptr<pit::Entry> >& |
| 185 | Entry::getPitEntries() |
| 186 | { |
| 187 | return m_pitEntries; |
| 188 | } |
| 189 | |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame^] | 190 | inline const std::vector<shared_ptr<pit::Entry> >& |
| 191 | Entry::getPitEntries() const |
| 192 | { |
| 193 | return m_pitEntries; |
| 194 | } |
| 195 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 196 | inline shared_ptr<measurements::Entry> |
| 197 | Entry::getMeasurementsEntry() const |
| 198 | { |
| 199 | return m_measurementsEntry; |
| 200 | } |
| 201 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 202 | inline shared_ptr<strategy_choice::Entry> |
| 203 | Entry::getStrategyChoiceEntry() const |
| 204 | { |
| 205 | return m_strategyChoiceEntry; |
| 206 | } |
| 207 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 208 | } // namespace name_tree |
| 209 | } // namespace nfd |
| 210 | |
| 211 | #endif // NFD_TABLE_NAME_TREE_ENTRY_HPP |