mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 23:32:09 +00:00
add array item removal
This commit is contained in:
parent
2a79f42eb5
commit
9cbac0bbc1
2 changed files with 35 additions and 0 deletions
|
@ -226,6 +226,17 @@ int PL_A_NumObjects (plitem_t *array);
|
|||
*/
|
||||
qboolean PL_A_InsertObjectAtIndex (plitem_t *array, plitem_t *item, int index);
|
||||
|
||||
/** Remove a value from an array object.
|
||||
The array items will be shuffled to fill the resulting hole.
|
||||
|
||||
\param array The array to get the value from
|
||||
\param index The index within the array to remove
|
||||
\return the value associated with the index, or NULL if not found or array
|
||||
isn't an array.
|
||||
\note You are responsible for freeing the returned object.
|
||||
*/
|
||||
plitem_t *PL_RemoveObjectAtIndex (plitem_t *array, int index);
|
||||
|
||||
plitem_t *PL_NewDictionary (void);
|
||||
plitem_t *PL_NewArray (void);
|
||||
plitem_t *PL_NewData (void *, int);
|
||||
|
|
|
@ -311,6 +311,30 @@ PL_A_NumObjects (plitem_t *array)
|
|||
return ((plarray_t *) array->data)->numvals;
|
||||
}
|
||||
|
||||
plitem_t *
|
||||
PL_RemoveObjectAtIndex (plitem_t *array, int index)
|
||||
{
|
||||
plarray_t *arr;
|
||||
plitem_t *item;
|
||||
|
||||
if (array->type != QFArray)
|
||||
return 0;
|
||||
|
||||
arr = (plarray_t *)array->data;
|
||||
|
||||
if (index < 0 || index >= arr->numvals)
|
||||
return 0;
|
||||
|
||||
item = arr->values[index];
|
||||
arr->numvals--;
|
||||
while (index < arr->numvals) {
|
||||
arr->values[index] = arr->values[index + 1];
|
||||
index++;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
static qboolean
|
||||
PL_SkipSpace (pldata_t *pl)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue