@@ -67,6 +67,19 @@ class ContiguousMemoryLinkedListBase
67
67
insertAt (reserveAddress (), value_t (std::forward<Args>(args)...));
68
68
}
69
69
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
+
70
83
// remove the last element in the list
71
84
virtual void popBack () = 0;
72
85
@@ -117,17 +130,7 @@ class ContiguousMemoryLinkedListBase
117
130
118
131
~ContiguousMemoryLinkedListBase ()
119
132
{
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 ();
131
134
_NBL_ALIGNED_FREE (m_reservedSpace);
132
135
}
133
136
@@ -148,6 +151,24 @@ class ContiguousMemoryLinkedListBase
148
151
return addr;
149
152
}
150
153
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
+
151
172
// create a new node which stores data at already allocated address,
152
173
virtual void insertAt (uint32_t addr, value_t && val) = 0;
153
174
0 commit comments