equal
deleted
inserted
replaced
61 enum { |
61 enum { |
62 SIZE = TAGS_MAX_SIZE |
62 SIZE = TAGS_MAX_SIZE |
63 }; |
63 }; |
64 private: |
64 private: |
65 struct TagData { |
65 struct TagData { |
66 struct TagData *m_next; |
66 uint8_t m_data[Tags::SIZE]; |
67 uint32_t m_id; |
67 struct TagData *m_next; |
68 uint32_t m_count; |
68 uint32_t m_id; |
69 uint8_t *m_data; |
69 uint32_t m_count; |
70 }; |
70 }; |
71 |
71 |
72 bool Remove (uint32_t id); |
72 bool Remove (uint32_t id); |
73 struct Tags::TagData *AllocData (uint32_t size) const; |
73 struct Tags::TagData *AllocData (void) const; |
74 void FreeData (struct TagData *data) const; |
74 void FreeData (struct TagData *data) const; |
|
75 |
|
76 static struct Tags::TagData *gFree; |
|
77 static uint32_t gN_free; |
75 |
78 |
76 struct TagData *m_next; |
79 struct TagData *m_next; |
77 }; |
80 }; |
78 |
81 |
79 } // namespace ns3 |
82 } // namespace ns3 |
103 // ensure this id was not yet added |
106 // ensure this id was not yet added |
104 for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) |
107 for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) |
105 { |
108 { |
106 NS_ASSERT (cur->m_id != T::GetUid ()); |
109 NS_ASSERT (cur->m_id != T::GetUid ()); |
107 } |
110 } |
108 struct TagData *newStart = AllocData (Tags::SIZE); |
111 struct TagData *newStart = AllocData (); |
109 newStart->m_count = 1; |
112 newStart->m_count = 1; |
110 newStart->m_next = 0; |
113 newStart->m_next = 0; |
111 newStart->m_id = T::GetUid (); |
114 newStart->m_id = T::GetUid (); |
112 void *buf = newStart->m_data; |
115 void *buf = &newStart->m_data; |
113 new (buf) T (tag); |
116 new (buf) T (tag); |
114 newStart->m_next = m_next; |
117 newStart->m_next = m_next; |
115 const_cast<Tags *> (this)->m_next = newStart; |
118 const_cast<Tags *> (this)->m_next = newStart; |
116 } |
119 } |
117 |
120 |
147 for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) |
150 for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) |
148 { |
151 { |
149 if (cur->m_id == T::GetUid ()) |
152 if (cur->m_id == T::GetUid ()) |
150 { |
153 { |
151 /* found tag */ |
154 /* found tag */ |
152 T *data = reinterpret_cast<T *> (cur->m_data); |
155 T *data = reinterpret_cast<T *> (&cur->m_data); |
153 tag = T (*data); |
156 tag = T (*data); |
154 return true; |
157 return true; |
155 } |
158 } |
156 } |
159 } |
157 /* no tag found */ |
160 /* no tag found */ |