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" |
| 16 | |
| 17 | namespace nfd { |
| 18 | |
| 19 | class NameTree; |
| 20 | |
| 21 | namespace name_tree { |
| 22 | |
| 23 | // Forward declaration |
| 24 | class Node; |
| 25 | class Entry; |
| 26 | |
| 27 | /** |
| 28 | * @brief Name Tree Node Class |
| 29 | */ |
| 30 | class Node |
| 31 | { |
| 32 | public: |
| 33 | Node(); |
| 34 | |
| 35 | ~Node(); |
| 36 | |
| 37 | public: |
| 38 | // variables are in public as this is just a data structure |
| 39 | shared_ptr<Entry> m_entry; // Name Tree Entry (i.e., Name Prefix Entry) |
| 40 | Node* m_prev; // Previous Name Tree Node (to resolve hash collision) |
| 41 | Node* m_next; // Next Name Tree Node (to resolve hash collision) |
| 42 | }; |
| 43 | |
| 44 | /** |
| 45 | * @brief Name Tree Entry Class |
| 46 | */ |
| 47 | class Entry |
| 48 | { |
| 49 | // Make private members accessible by Name Tree |
| 50 | friend class nfd::NameTree; |
| 51 | public: |
| 52 | explicit |
| 53 | Entry(const Name& prefix); |
| 54 | |
| 55 | ~Entry(); |
| 56 | |
| 57 | const Name& |
| 58 | getPrefix() const; |
| 59 | |
| 60 | void |
| 61 | setHash(uint32_t hash); |
| 62 | |
| 63 | uint32_t |
| 64 | getHash() const; |
| 65 | |
| 66 | void |
| 67 | setParent(shared_ptr<Entry> parent); |
| 68 | |
| 69 | shared_ptr<Entry> |
| 70 | getParent() const; |
| 71 | |
| 72 | std::vector<shared_ptr<Entry> >& |
| 73 | getChildren(); |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 74 | |
| 75 | bool |
| 76 | isEmpty() const; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 77 | |
| 78 | void |
| 79 | setFibEntry(shared_ptr<fib::Entry> fib); |
| 80 | |
| 81 | shared_ptr<fib::Entry> |
| 82 | getFibEntry() const; |
| 83 | |
| 84 | bool |
| 85 | eraseFibEntry(shared_ptr<fib::Entry> fib); |
| 86 | |
| 87 | void |
| 88 | insertPitEntry(shared_ptr<pit::Entry> pit); |
| 89 | |
| 90 | std::vector<shared_ptr<pit::Entry> >& |
| 91 | getPitEntries(); |
| 92 | |
| 93 | /** |
| 94 | * @brief Erase a PIT Entry |
| 95 | * @details The address of this PIT Entry is required |
| 96 | */ |
| 97 | bool |
| 98 | erasePitEntry(shared_ptr<pit::Entry> pit); |
| 99 | |
| 100 | void |
| 101 | setMeasurementsEntry(shared_ptr<measurements::Entry> measurements); |
| 102 | |
| 103 | shared_ptr<measurements::Entry> |
| 104 | getMeasurementsEntry() const; |
| 105 | |
| 106 | bool |
| 107 | eraseMeasurementsEntry(shared_ptr<measurements::Entry> measurements); |
| 108 | |
| 109 | private: |
| 110 | uint32_t m_hash; |
| 111 | Name m_prefix; |
| 112 | shared_ptr<Entry> m_parent; // Pointing to the parent entry. |
| 113 | std::vector<shared_ptr<Entry> > m_children; // Children pointers. |
| 114 | shared_ptr<fib::Entry> m_fibEntry; |
| 115 | std::vector<shared_ptr<pit::Entry> > m_pitEntries; |
| 116 | shared_ptr<measurements::Entry> m_measurementsEntry; |
| 117 | |
| 118 | // get the Name Tree Node that is associated with this Name Tree Entry |
| 119 | Node* m_node; |
| 120 | }; |
| 121 | |
| 122 | inline const Name& |
| 123 | Entry::getPrefix() const |
| 124 | { |
| 125 | return m_prefix; |
| 126 | } |
| 127 | |
| 128 | inline uint32_t |
| 129 | Entry::getHash() const |
| 130 | { |
| 131 | return m_hash; |
| 132 | } |
| 133 | |
| 134 | inline shared_ptr<Entry> |
| 135 | Entry::getParent() const |
| 136 | { |
| 137 | return m_parent; |
| 138 | } |
| 139 | |
| 140 | inline std::vector<shared_ptr<name_tree::Entry> >& |
| 141 | Entry::getChildren() |
| 142 | { |
| 143 | return m_children; |
| 144 | } |
| 145 | |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 146 | inline bool |
| 147 | Entry::isEmpty() const |
| 148 | { |
| 149 | return m_children.empty() && |
| 150 | !static_cast<bool>(m_fibEntry) && |
| 151 | m_pitEntries.empty() && |
| 152 | !static_cast<bool>(m_measurementsEntry); |
| 153 | } |
| 154 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 155 | inline shared_ptr<fib::Entry> |
| 156 | Entry::getFibEntry() const |
| 157 | { |
| 158 | return m_fibEntry; |
| 159 | } |
| 160 | |
| 161 | inline std::vector<shared_ptr<pit::Entry> >& |
| 162 | Entry::getPitEntries() |
| 163 | { |
| 164 | return m_pitEntries; |
| 165 | } |
| 166 | |
| 167 | inline shared_ptr<measurements::Entry> |
| 168 | Entry::getMeasurementsEntry() const |
| 169 | { |
| 170 | return m_measurementsEntry; |
| 171 | } |
| 172 | |
| 173 | } // namespace name_tree |
| 174 | } // namespace nfd |
| 175 | |
| 176 | #endif // NFD_TABLE_NAME_TREE_ENTRY_HPP |