mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
change the dict and array add functions to return true/false and add some
more docs
This commit is contained in:
parent
e8fb5ba83b
commit
9c92a916ff
5 changed files with 44 additions and 27 deletions
|
@ -155,9 +155,26 @@ plitem_t *PL_ObjectAtIndex (plitem_t *, int);
|
|||
*/
|
||||
plitem_t *PL_D_AllKeys (plitem_t *);
|
||||
|
||||
plitem_t *PL_D_AddObject (plitem_t *, plitem_t *, plitem_t *);
|
||||
plitem_t *PL_A_AddObject (plitem_t *, plitem_t *);
|
||||
plitem_t *PL_A_InsertObjectAtIndex (plitem_t *, plitem_t *, int ind);
|
||||
//@{
|
||||
/**
|
||||
\fn plitem_t *PL_D_AddObject (plitem_t *dict, plitem_t *key, plitem_t *value)
|
||||
\fn plitem_t *PL_A_AddObject (plitem_t *array, plitem_t *item)
|
||||
\fn plitem_t *PL_A_InsertObjectAtIndex (plitem_t *array, plitem_t *item, int ind)
|
||||
|
||||
\param dict The dictionary to add the key/value pair to
|
||||
\param array The array to add the item to
|
||||
\param item The item to be added to the array
|
||||
\param key The key of the key/value pair to be added to the dictionary
|
||||
\param value The value of the key/value pair to be added to the dictionary
|
||||
|
||||
\return true on success, false on failure
|
||||
|
||||
Note: the dictionary or array becomes the owner of the added item/pair.
|
||||
*/
|
||||
int PL_D_AddObject (plitem_t *, plitem_t *, plitem_t *);
|
||||
int PL_A_AddObject (plitem_t *, plitem_t *);
|
||||
int PL_A_InsertObjectAtIndex (plitem_t *, plitem_t *, int ind);
|
||||
//@}
|
||||
|
||||
plitem_t *PL_NewDictionary (void);
|
||||
plitem_t *PL_NewArray (void);
|
||||
|
|
|
@ -106,24 +106,24 @@ bi_PL_ObjectAtIndex (progs_t *pr)
|
|||
static void
|
||||
bi_PL_D_AddObject (progs_t *pr)
|
||||
{
|
||||
return_plitem (pr, PL_D_AddObject (p_plitem (pr, 0),
|
||||
remove_plitem (pr, p_plitem (pr, 1)),
|
||||
remove_plitem (pr, p_plitem (pr, 2))));
|
||||
R_INT (pr) = PL_D_AddObject (p_plitem (pr, 0),
|
||||
remove_plitem (pr, p_plitem (pr, 1)),
|
||||
remove_plitem (pr, p_plitem (pr, 2)));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_PL_A_AddObject (progs_t *pr)
|
||||
{
|
||||
return_plitem (pr, PL_A_AddObject (p_plitem (pr, 0),
|
||||
remove_plitem (pr, p_plitem (pr, 1))));
|
||||
R_INT (pr) = PL_A_AddObject (p_plitem (pr, 0),
|
||||
remove_plitem (pr, p_plitem (pr, 1)));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_PL_A_InsertObjectAtIndex (progs_t *pr)
|
||||
{
|
||||
return_plitem (pr, PL_A_InsertObjectAtIndex (p_plitem (pr, 0),
|
||||
R_INT (pr) = PL_A_InsertObjectAtIndex (p_plitem (pr, 0),
|
||||
remove_plitem (pr, p_plitem (pr, 1)),
|
||||
P_INT (pr, 2)));
|
||||
P_INT (pr, 2));
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -190,16 +190,16 @@ PL_ObjectAtIndex (plitem_t *item, int index)
|
|||
return index >= 0 && index < array->numvals ? array->values[index] : NULL;
|
||||
}
|
||||
|
||||
plitem_t *
|
||||
int
|
||||
PL_D_AddObject (plitem_t *dict, plitem_t *key, plitem_t *value)
|
||||
{
|
||||
dictkey_t *k;
|
||||
|
||||
if (dict->type != QFDictionary)
|
||||
return NULL;
|
||||
return 0;
|
||||
|
||||
if (key->type != QFString)
|
||||
return NULL;
|
||||
return 0;
|
||||
|
||||
if ((k = Hash_Find ((hashtab_t *)dict->data, key->data))) {
|
||||
PL_Free ((plitem_t *) k->value);
|
||||
|
@ -208,23 +208,23 @@ PL_D_AddObject (plitem_t *dict, plitem_t *key, plitem_t *value)
|
|||
k = malloc (sizeof (dictkey_t));
|
||||
|
||||
if (!k)
|
||||
return NULL;
|
||||
return 0;
|
||||
|
||||
k->key = strdup ((char *) key->data);
|
||||
k->value = value;
|
||||
|
||||
Hash_Add ((hashtab_t *)dict->data, k);
|
||||
}
|
||||
return dict;
|
||||
return 1;
|
||||
}
|
||||
|
||||
plitem_t *
|
||||
int
|
||||
PL_A_InsertObjectAtIndex (plitem_t *array_item, plitem_t *item, int index)
|
||||
{
|
||||
plarray_t *array;
|
||||
|
||||
if (array_item->type != QFArray)
|
||||
return NULL;
|
||||
return 0;
|
||||
|
||||
array = (plarray_t *)array_item->data;
|
||||
|
||||
|
@ -233,7 +233,7 @@ PL_A_InsertObjectAtIndex (plitem_t *array_item, plitem_t *item, int index)
|
|||
plitem_t **tmp = realloc (array->values, size);
|
||||
|
||||
if (!tmp)
|
||||
return NULL;
|
||||
return 0;
|
||||
array->maxvals += 128;
|
||||
array->values = tmp;
|
||||
memset (array->values + array->numvals, 0,
|
||||
|
@ -244,16 +244,16 @@ PL_A_InsertObjectAtIndex (plitem_t *array_item, plitem_t *item, int index)
|
|||
index = array->numvals;
|
||||
|
||||
if (index < 0 || index > array->numvals)
|
||||
return NULL;
|
||||
return 0;
|
||||
|
||||
memmove (array->values + index + 1, array->values + index,
|
||||
(array->numvals - index) * sizeof (plitem_t *));
|
||||
array->values[index] = item;
|
||||
array->numvals++;
|
||||
return array_item;
|
||||
return 1;
|
||||
}
|
||||
|
||||
plitem_t *
|
||||
int
|
||||
PL_A_AddObject (plitem_t *array_item, plitem_t *item)
|
||||
{
|
||||
return PL_A_InsertObjectAtIndex (array_item, item, -1);
|
||||
|
|
|
@ -8,9 +8,9 @@ typedef struct plitem_s plitem_t;
|
|||
@extern plitem_t (plitem_t item, string key) PL_ObjectForKey;
|
||||
@extern plitem_t (plitem_t item, integer index) PL_ObjectAtIndex;
|
||||
|
||||
@extern plitem_t (plitem_t dict, plitem_t key, plitem_t value) PL_D_AddObject;
|
||||
@extern plitem_t (plitem_t array_item, plitem_t item) PL_A_AddObject;
|
||||
@extern plitem_t (plitem_t array_item, plitem_t item, integer index) PL_A_InsertObjectAtIndex;
|
||||
@extern integer (plitem_t dict, plitem_t key, plitem_t value) PL_D_AddObject;
|
||||
@extern integer (plitem_t array_item, plitem_t item) PL_A_AddObject;
|
||||
@extern integer (plitem_t array_item, plitem_t item, integer index) PL_A_InsertObjectAtIndex;
|
||||
|
||||
@extern plitem_t () PL_NewDictionary;
|
||||
@extern plitem_t () PL_NewArray;
|
||||
|
|
|
@ -4,9 +4,9 @@ plitem_t (string str) PL_GetPropertyList = #0;
|
|||
plitem_t (plitem_t item, string key) PL_ObjectForKey = #0;
|
||||
plitem_t (plitem_t item, integer index) PL_ObjectAtIndex = #0;
|
||||
|
||||
plitem_t (plitem_t dict, plitem_t key, plitem_t value) PL_D_AddObject = #0;
|
||||
plitem_t (plitem_t array_item, plitem_t item) PL_A_AddObject = #0;
|
||||
plitem_t (plitem_t array_item, plitem_t item, integer index) PL_A_InsertObjectAtIndex = #0;
|
||||
integer (plitem_t dict, plitem_t key, plitem_t value) PL_D_AddObject = #0;
|
||||
integer (plitem_t array_item, plitem_t item) PL_A_AddObject = #0;
|
||||
integer (plitem_t array_item, plitem_t item, integer index) PL_A_InsertObjectAtIndex = #0;
|
||||
|
||||
plitem_t () PL_NewDictionary = #0;
|
||||
plitem_t () PL_NewArray = #0;
|
||||
|
|
Loading…
Reference in a new issue