29 struct xmmsv_coll_St {
41 size_t idlist_allocated;
48 static int xmmsv_coll_idlist_resize (
xmmsv_coll_t *coll,
size_t newsize);
95 if (!(coll->idlist =
x_new0 (uint32_t, 1))) {
100 coll->idlist_size = 1;
101 coll->idlist_allocated = 1;
150 x_api_error_if (coll->ref < 1,
"with a freed collection",);
153 if (coll->ref == 0) {
154 xmmsv_coll_free (coll);
171 unsigned int size = 0;
175 while (ids[size] != 0) {
181 if (!(coll->idlist =
x_new0 (uint32_t, size))) {
186 for (i = 0; i < size; ++i) {
187 coll->idlist[i] = ids[i];
190 coll->idlist_size = size;
191 coll->idlist_allocated = size;
229 if (_xmmsv_coll_operand_find (it, op)) {
230 x_api_warning (
"with an operand already in operand list");
259 if (_xmmsv_coll_operand_find (it, op)) {
262 x_api_warning (
"with an operand not in operand list");
295 if (index >= coll->idlist_size) {
300 if (coll->idlist_size == coll->idlist_allocated) {
302 size_t double_size = coll->idlist_allocated * 2;
303 success = xmmsv_coll_idlist_resize (coll, double_size);
307 for (i = coll->idlist_size; i > index; i--) {
308 coll->idlist[i] = coll->idlist[i - 1];
311 coll->idlist[index] = id;
332 if ((index >= coll->idlist_size - 1) || (newindex >= coll->idlist_size - 1)) {
336 tmp = coll->idlist[index];
337 if (index < newindex) {
338 for (i = index; i < newindex; i++) {
339 coll->idlist[i] = coll->idlist[i + 1];
342 else if (index > newindex) {
343 for (i = index; i > newindex; i--) {
344 coll->idlist[i] = coll->idlist[i - 1];
347 coll->idlist[newindex] = tmp;
366 if (index >= coll->idlist_size - 1) {
371 for (i = index; i < coll->idlist_size; i++) {
372 coll->idlist[i] = coll->idlist[i + 1];
376 half_size = coll->idlist_allocated / 2;
377 if (coll->idlist_size <= half_size) {
378 xmmsv_coll_idlist_resize (coll, half_size);
392 unsigned int empty[] = { 0 };
413 if (index >= (coll->idlist_size - 1)) {
417 *val = coll->idlist[index];
434 if (index >= (coll->idlist_size - 1)) {
438 coll->idlist[index] = val;
453 return coll->idlist_size - 1;
493 return coll->operands;
501 return coll->attributes;
561 struct attr_fe_data {
567 attr_fe_func (
const char *key,
xmmsv_t *val,
void *user_data)
569 struct attr_fe_data *d = user_data;
576 d->func (key, v, d->userdata);
594 struct attr_fe_data d = {func, user_data};
624 xmmsv_coll_idlist_resize (
xmmsv_coll_t *coll,
size_t newsize)
628 newmem = realloc (coll->idlist, newsize * sizeof (uint32_t));
630 if (newmem == NULL) {
635 coll->idlist = newmem;
636 coll->idlist_allocated = newsize;
xmmsv_t * xmmsv_new_dict(void)
Allocates a new dict xmmsv_t.
int xmmsv_coll_idlist_append(xmmsv_coll_t *coll, unsigned int id)
Append a value to the idlist.
#define x_return_val_if_fail(expr, val)
void xmmsv_unref(xmmsv_t *val)
Decreases the references for the xmmsv_t When the number of references reaches 0 it will be freed...
int xmmsv_dict_set(xmmsv_t *dictv, const char *key, xmmsv_t *val)
Insert an element under the given key in the dict xmmsv_t.
int xmmsv_coll_attribute_get(xmmsv_coll_t *coll, const char *key, char **value)
Retrieve the value of the attribute of the given collection.
int xmmsv_dict_entry_get_string(xmmsv_t *val, const char *key, const char **r)
int xmmsv_get_list_iter(const xmmsv_t *val, xmmsv_list_iter_t **it)
Retrieves a list iterator from a list xmmsv_t.
int xmmsv_dict_remove(xmmsv_t *dictv, const char *key)
Remove the element corresponding to a given key in the dict xmmsv_t (if it exists).
int xmmsv_list_iter_entry(xmmsv_list_iter_t *it, xmmsv_t **val)
Get the element currently pointed at by the iterator.
void(* xmmsv_coll_attribute_foreach_func)(const char *key, const char *value, void *udata)
void xmmsv_coll_attribute_set(xmmsv_coll_t *coll, const char *key, const char *value)
Set an attribute in the given collection.
xmmsv_t * xmmsv_new_string(const char *s)
Allocates a new string xmmsv_t.
xmmsv_coll_t * xmmsv_coll_ref(xmmsv_coll_t *coll)
Increases the references for the xmmsv_coll_t.
int xmmsv_coll_attribute_remove(xmmsv_coll_t *coll, const char *key)
Remove an attribute from the given collection.
int xmmsv_list_append(xmmsv_t *listv, xmmsv_t *val)
Append an element to the end of the list xmmsv_t.
int xmmsv_coll_idlist_set_index(xmmsv_coll_t *coll, unsigned int index, uint32_t val)
Sets the value at the given position in the idlist.
struct xmmsv_St * xmmsv_coll_operands_get(xmmsv_coll_t *coll)
size_t xmmsv_coll_idlist_get_size(xmmsv_coll_t *coll)
Get the size of the idlist.
int xmmsv_dict_foreach(xmmsv_t *dictv, xmmsv_dict_foreach_func func, void *user_data)
Apply a function to each key-element pair in the list.
void xmmsv_list_iter_explicit_destroy(xmmsv_list_iter_t *it)
Explicitly free list iterator.
int xmmsv_get_coll(const xmmsv_t *val, xmmsv_coll_t **coll)
Retrieves a collection from the value.
xmmsv_t * xmmsv_new_coll(xmmsv_coll_t *coll)
Allocates a new collection xmmsv_t.
struct xmmsv_coll_St xmmsv_coll_t
int xmmsv_list_iter_remove(xmmsv_list_iter_t *it)
Remove the element in the list at the position pointed at by the iterator.
void xmmsv_list_iter_next(xmmsv_list_iter_t *it)
Advance the iterator to the next element in the list.
xmmsv_coll_t * xmmsv_coll_new(xmmsv_coll_type_t type)
Allocate a new collection of the given type.
int xmmsv_coll_idlist_get_index(xmmsv_coll_t *coll, unsigned int index, uint32_t *val)
Retrieves the value at the given position in the idlist.
struct xmmsv_St * xmmsv_coll_attributes_get(xmmsv_coll_t *coll)
void xmmsv_coll_add_operand(xmmsv_coll_t *coll, xmmsv_coll_t *op)
Add the operand to the given collection.
#define x_return_null_if_fail(expr)
void xmmsv_coll_remove_operand(xmmsv_coll_t *coll, xmmsv_coll_t *op)
Remove all the occurences of the operand in the given collection.
void xmmsv_coll_set_idlist(xmmsv_coll_t *coll, unsigned int ids[])
Set the list of ids in the given collection.
#define x_new0(type, num)
void xmmsv_coll_attribute_foreach(xmmsv_coll_t *coll, xmmsv_coll_attribute_foreach_func func, void *user_data) XMMS_DEPRECATED
Iterate over all key/value-pair of the collection attributes.
xmmsv_t * xmmsv_new_list(void)
Allocates a new list xmmsv_t.
int xmmsv_coll_idlist_insert(xmmsv_coll_t *coll, unsigned int index, unsigned int id)
Insert a value at a given position in the idlist.
#define x_return_if_fail(expr)
int xmmsv_get_string(const xmmsv_t *val, const char **r)
Retrieves a string from the value.
int xmmsv_list_restrict_type(xmmsv_t *listv, xmmsv_type_t type)
int xmmsv_coll_idlist_clear(xmmsv_coll_t *coll)
Empties the idlist.
uint32_t * xmmsv_coll_get_idlist(xmmsv_coll_t *coll)
Return the list of ids stored in the collection.
xmmsv_coll_type_t xmmsv_coll_get_type(xmmsv_coll_t *coll)
Return the type of the collection.
int xmmsv_coll_idlist_move(xmmsv_coll_t *coll, unsigned int index, unsigned int newindex)
Move a value of the idlist to a new position.
struct xmmsv_list_iter_St xmmsv_list_iter_t
int xmmsv_list_iter_valid(xmmsv_list_iter_t *it)
Check whether the iterator is valid and points to a valid element.
xmmsv_coll_t * xmmsv_coll_universe(void)
Return a collection referencing the whole media library, that is a reference to the "All Media" colle...
int xmmsv_coll_idlist_remove(xmmsv_coll_t *coll, unsigned int index)
Remove the value at a given index from the idlist.
void xmmsv_coll_unref(xmmsv_coll_t *coll)
Decreases the references for the xmmsv_coll_t When the number of references reaches 0 it will be free...