File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -191,6 +191,26 @@ Simple arrays are accessed via the :cpp:class:`ConfigDB::Array` class. All eleme
191191
192192The :cpp:class: `ConfigDB::ObjectArray ` type can be used for arrays of objects or unions. Default values are not currently supported for these.
193193
194+ .. important ::
195+
196+ Be very careful when removing items from an array (via :cpp:func: `Array::removeItem `).
197+ Don't hold Object or Property references to items in the array during the operation as they may become invalid if the array ordering changes.
198+ Do not rely on the item index for removing multiple items since indices change when removeItem is called.
199+
200+ Do not rely on the item index for removal, but instead use the content of the object or item as criteria. For example:
201+
202+ .. code-block :: c++
203+
204+ for(unsigned index=0; index < array.getItemCount();) {
205+ auto item = array[index];
206+ if (want_to_delete(item)) {
207+ // This causes subsquent items to shift down one, so leave index where it is
208+ array.removeItem(index);
209+ } else {
210+ ++index;
211+ }
212+ }
213+
194214
195215Unions
196216~~~~~~
Original file line number Diff line number Diff line change @@ -37,6 +37,11 @@ class ArrayBase : public Object
3737 return getId () ? getArray ().getCount () : 0 ;
3838 }
3939
40+ /*
41+ * @brief Remove an item from the array.
42+ * @note Be very careful dealing with `ObjectArray` item removal as all
43+ * items after this one will be shifted and their references no longer valid.
44+ */
4045 bool removeItem (unsigned index)
4146 {
4247 return getArray ().remove (index);
You can’t perform that action at this time.
0 commit comments