Simple JSON  0.1
A free simple json library for C
simple_json_list.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "simple_json_list.h"
#include "simple_json_error.h"
Include dependency graph for simple_json_list.c:

Go to the source code of this file.

Functions

void sj_list_delete (SJList *list)
 deletes a list that has been previously allocated More...
 
SJListsj_list_new ()
 create a new list More...
 
SJListsj_list_new_size (unsigned int count)
 allocate a new empty list of size 'count' More...
 
void * sj_list_get_nth (SJList *list, unsigned int n)
 get the data stored at the nth element More...
 
SJListsj_list_expand (SJList *list)
 
void sj_list_append (SJList *list, void *data)
 add an element to the end of the list More...
 
SJListsj_list_prepend (SJList *list, void *data)
 
SJListsj_list_insert (SJList *list, void *data, unsigned int n)
 instert a new element at the position provided More...
 
SJListsj_list_delete_first (SJList *list)
 
SJListsj_list_delete_last (SJList *list)
 
int sj_list_delete_data (SJList *list, void *data)
 delete the first element in the list pointing to the address of data More...
 
SJListsj_list_delete_nth (SJList *list, unsigned int n)
 delete the element at the nth position in the list More...
 
unsigned int sj_list_get_count (SJList *list)
 get the number of tracked elements in the list More...
 
void sj_list_foreach (SJList *list, void(*function)(void *data, void *context), void *contextData)
 

Function Documentation

void sj_list_append ( SJList list,
void *  data 
)

add an element to the end of the list

Parameters
listthe list to add to
datathe data to assign to the new element

Definition at line 83 of file simple_json_list.c.

void sj_list_delete ( SJList list)

deletes a list that has been previously allocated

Parameters
listthe list to delete;

Definition at line 7 of file simple_json_list.c.

int sj_list_delete_data ( SJList list,
void *  data 
)

delete the first element in the list pointing to the address of data

Note
does not delete the data itself
Parameters
listthe list to delete the element from
dataused to match against which element to delete
Returns
0 on complete, error otherwise

Definition at line 148 of file simple_json_list.c.

SJList* sj_list_delete_first ( SJList list)

Definition at line 133 of file simple_json_list.c.

SJList* sj_list_delete_last ( SJList list)

Definition at line 138 of file simple_json_list.c.

SJList* sj_list_delete_nth ( SJList list,
unsigned int  n 
)

delete the element at the nth position in the list

Parameters
listthe list to delete out of
nthe element to delete. This is no-op if the nth element is beyond the scope of the list (event is logged)
Returns
the list provided

Definition at line 170 of file simple_json_list.c.

SJList* sj_list_expand ( SJList list)

Definition at line 60 of file simple_json_list.c.

void sj_list_foreach ( SJList list,
void(*)(void *data, void *context)  function,
void *  contextData 
)

Definition at line 198 of file simple_json_list.c.

unsigned int sj_list_get_count ( SJList list)

get the number of tracked elements in the list

Parameters
listthe list the check
Returns
the count in the list. Will be zero if list was NULL

Definition at line 192 of file simple_json_list.c.

void* sj_list_get_nth ( SJList list,
unsigned int  n 
)

get the data stored at the nth element

Parameters
listthe list to pull data from
nwhich element to look out
Returns
NULL on error (such as if n > the element count) or the address of the data otherwise

Definition at line 49 of file simple_json_list.c.

SJList* sj_list_insert ( SJList list,
void *  data,
unsigned int  n 
)

instert a new element at the position provided

Parameters
listthe list to insert into
datathe data to assin to the new element
Returns
the address of the list. In the event that the list needed to expand this will be different from the list provided

Definition at line 109 of file simple_json_list.c.

SJList* sj_list_new ( )

create a new list

Returns
NULL on memory error or an initialized list

Definition at line 17 of file simple_json_list.c.

SJList* sj_list_new_size ( unsigned int  count)

allocate a new empty list of size 'count'

Parameters
counthow many elements you wish to support in this list.
Returns
NULL on memory error or a new empty list

Definition at line 22 of file simple_json_list.c.

SJList* sj_list_prepend ( SJList list,
void *  data 
)

Definition at line 104 of file simple_json_list.c.