@@ -67,6 +67,19 @@ class ContiguousMemoryLinkedListBase
6767 insertAt (reserveAddress (), value_t (std::forward<Args>(args)...));
6868 }
6969
70+ /* *
71+ * @brief Resets list to initial state.
72+ */
73+ inline void clear ()
74+ {
75+ disposeAll ();
76+
77+ m_addressAllocator = std::unique_ptr<address_allocator_t >(new address_allocator_t (m_reservedSpace, 0u , 0u , 1u , m_cap, 1u ));
78+ m_back = invalid_iterator;
79+ m_begin = invalid_iterator;
80+
81+ }
82+
7083 // remove the last element in the list
7184 virtual void popBack () = 0;
7285
@@ -117,17 +130,7 @@ class ContiguousMemoryLinkedListBase
117130
118131 ~ContiguousMemoryLinkedListBase ()
119132 {
120- if (m_dispose_f && m_begin != invalid_iterator)
121- {
122- auto * begin = getBegin ();
123- auto * back = getBack ();
124- while (begin != back)
125- {
126- m_dispose_f (begin->data );
127- begin = get (begin->next );
128- }
129- m_dispose_f (back->data );
130- }
133+ disposeAll ();
131134 _NBL_ALIGNED_FREE (m_reservedSpace);
132135 }
133136
@@ -148,6 +151,24 @@ class ContiguousMemoryLinkedListBase
148151 return addr;
149152 }
150153
154+ /* *
155+ * @brief Calls disposal function on all elements of the list.
156+ */
157+ inline void disposeAll ()
158+ {
159+ if (m_dispose_f && m_begin != invalid_iterator)
160+ {
161+ auto * begin = getBegin ();
162+ auto * back = getBack ();
163+ while (begin != back)
164+ {
165+ m_dispose_f (begin->data );
166+ begin = get (begin->next );
167+ }
168+ m_dispose_f (back->data );
169+ }
170+ }
171+
151172 // create a new node which stores data at already allocated address,
152173 virtual void insertAt (uint32_t addr, value_t && val) = 0;
153174
0 commit comments