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(); |
| 74 | |
| 75 | void |
| 76 | setFibEntry(shared_ptr<fib::Entry> fib); |
| 77 | |
| 78 | shared_ptr<fib::Entry> |
| 79 | getFibEntry() const; |
| 80 | |
| 81 | bool |
| 82 | eraseFibEntry(shared_ptr<fib::Entry> fib); |
| 83 | |
| 84 | void |
| 85 | insertPitEntry(shared_ptr<pit::Entry> pit); |
| 86 | |
| 87 | std::vector<shared_ptr<pit::Entry> >& |
| 88 | getPitEntries(); |
| 89 | |
| 90 | /** |
| 91 | * @brief Erase a PIT Entry |
| 92 | * @details The address of this PIT Entry is required |
| 93 | */ |
| 94 | bool |
| 95 | erasePitEntry(shared_ptr<pit::Entry> pit); |
| 96 | |
| 97 | void |
| 98 | setMeasurementsEntry(shared_ptr<measurements::Entry> measurements); |
| 99 | |
| 100 | shared_ptr<measurements::Entry> |
| 101 | getMeasurementsEntry() const; |
| 102 | |
| 103 | bool |
| 104 | eraseMeasurementsEntry(shared_ptr<measurements::Entry> measurements); |
| 105 | |
| 106 | private: |
| 107 | uint32_t m_hash; |
| 108 | Name m_prefix; |
| 109 | shared_ptr<Entry> m_parent; // Pointing to the parent entry. |
| 110 | std::vector<shared_ptr<Entry> > m_children; // Children pointers. |
| 111 | shared_ptr<fib::Entry> m_fibEntry; |
| 112 | std::vector<shared_ptr<pit::Entry> > m_pitEntries; |
| 113 | shared_ptr<measurements::Entry> m_measurementsEntry; |
| 114 | |
| 115 | // get the Name Tree Node that is associated with this Name Tree Entry |
| 116 | Node* m_node; |
| 117 | }; |
| 118 | |
| 119 | inline const Name& |
| 120 | Entry::getPrefix() const |
| 121 | { |
| 122 | return m_prefix; |
| 123 | } |
| 124 | |
| 125 | inline uint32_t |
| 126 | Entry::getHash() const |
| 127 | { |
| 128 | return m_hash; |
| 129 | } |
| 130 | |
| 131 | inline shared_ptr<Entry> |
| 132 | Entry::getParent() const |
| 133 | { |
| 134 | return m_parent; |
| 135 | } |
| 136 | |
| 137 | inline std::vector<shared_ptr<name_tree::Entry> >& |
| 138 | Entry::getChildren() |
| 139 | { |
| 140 | return m_children; |
| 141 | } |
| 142 | |
| 143 | inline shared_ptr<fib::Entry> |
| 144 | Entry::getFibEntry() const |
| 145 | { |
| 146 | return m_fibEntry; |
| 147 | } |
| 148 | |
| 149 | inline std::vector<shared_ptr<pit::Entry> >& |
| 150 | Entry::getPitEntries() |
| 151 | { |
| 152 | return m_pitEntries; |
| 153 | } |
| 154 | |
| 155 | inline shared_ptr<measurements::Entry> |
| 156 | Entry::getMeasurementsEntry() const |
| 157 | { |
| 158 | return m_measurementsEntry; |
| 159 | } |
| 160 | |
| 161 | } // namespace name_tree |
| 162 | } // namespace nfd |
| 163 | |
| 164 | #endif // NFD_TABLE_NAME_TREE_ENTRY_HPP |