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 | |
| 97 | /** |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 98 | * \brief Erase a PIT Entry |
| 99 | * \details The address of this PIT Entry is required |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 100 | */ |
| 101 | bool |
| 102 | erasePitEntry(shared_ptr<pit::Entry> pit); |
| 103 | |
| 104 | void |
| 105 | setMeasurementsEntry(shared_ptr<measurements::Entry> measurements); |
| 106 | |
| 107 | shared_ptr<measurements::Entry> |
| 108 | getMeasurementsEntry() const; |
| 109 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 110 | void |
| 111 | setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry); |
| 112 | |
| 113 | shared_ptr<strategy_choice::Entry> |
| 114 | getStrategyChoiceEntry() const; |
| 115 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 116 | private: |
| 117 | uint32_t m_hash; |
| 118 | Name m_prefix; |
| 119 | shared_ptr<Entry> m_parent; // Pointing to the parent entry. |
| 120 | std::vector<shared_ptr<Entry> > m_children; // Children pointers. |
| 121 | shared_ptr<fib::Entry> m_fibEntry; |
| 122 | std::vector<shared_ptr<pit::Entry> > m_pitEntries; |
| 123 | shared_ptr<measurements::Entry> m_measurementsEntry; |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 124 | shared_ptr<strategy_choice::Entry> m_strategyChoiceEntry; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 125 | |
| 126 | // get the Name Tree Node that is associated with this Name Tree Entry |
| 127 | Node* m_node; |
| 128 | }; |
| 129 | |
| 130 | inline const Name& |
| 131 | Entry::getPrefix() const |
| 132 | { |
| 133 | return m_prefix; |
| 134 | } |
| 135 | |
| 136 | inline uint32_t |
| 137 | Entry::getHash() const |
| 138 | { |
| 139 | return m_hash; |
| 140 | } |
| 141 | |
| 142 | inline shared_ptr<Entry> |
| 143 | Entry::getParent() const |
| 144 | { |
| 145 | return m_parent; |
| 146 | } |
| 147 | |
| 148 | inline std::vector<shared_ptr<name_tree::Entry> >& |
| 149 | Entry::getChildren() |
| 150 | { |
| 151 | return m_children; |
| 152 | } |
| 153 | |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 154 | inline bool |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 155 | Entry::hasChildren() const |
| 156 | { |
| 157 | return !m_children.empty(); |
| 158 | } |
| 159 | |
| 160 | inline bool |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 161 | Entry::isEmpty() const |
| 162 | { |
| 163 | return m_children.empty() && |
| 164 | !static_cast<bool>(m_fibEntry) && |
| 165 | m_pitEntries.empty() && |
| 166 | !static_cast<bool>(m_measurementsEntry); |
| 167 | } |
| 168 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 169 | inline shared_ptr<fib::Entry> |
| 170 | Entry::getFibEntry() const |
| 171 | { |
| 172 | return m_fibEntry; |
| 173 | } |
| 174 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 175 | inline bool |
| 176 | Entry::hasPitEntries() const |
| 177 | { |
| 178 | return !m_pitEntries.empty(); |
| 179 | } |
| 180 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 181 | inline std::vector<shared_ptr<pit::Entry> >& |
| 182 | Entry::getPitEntries() |
| 183 | { |
| 184 | return m_pitEntries; |
| 185 | } |
| 186 | |
| 187 | inline shared_ptr<measurements::Entry> |
| 188 | Entry::getMeasurementsEntry() const |
| 189 | { |
| 190 | return m_measurementsEntry; |
| 191 | } |
| 192 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 193 | inline shared_ptr<strategy_choice::Entry> |
| 194 | Entry::getStrategyChoiceEntry() const |
| 195 | { |
| 196 | return m_strategyChoiceEntry; |
| 197 | } |
| 198 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 199 | } // namespace name_tree |
| 200 | } // namespace nfd |
| 201 | |
| 202 | #endif // NFD_TABLE_NAME_TREE_ENTRY_HPP |