JST: JSON tools  1.0.0
JSON tools dynamic library for reading, manipulating and writing JSON tree
Data Structures | Typedefs | Functions | Variables
JST_list.h File Reference
#include "jstools.h"
Include dependency graph for JST_list.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  JST_Node_
 

Typedefs

typedef struct JST_Node_ JST_List
 
typedef void(* LST_assign_t) (void *dest, unsigned index, void *src)
 

Functions

JST_Error JST_List_push_back (JST_List **first, JST_List **current, void *data)
 
JST_Error JST_List_move_to (JST_List *from, void *dest, LST_assign_t assign)
 For each item in list, call assign to transfert ownership of items and free the list, node by node. More...
 

Variables

const JST_List JST_List_Zero
 

Typedef Documentation

◆ JST_List

typedef struct JST_Node_ JST_List

◆ LST_assign_t

typedef void( * LST_assign_t) (void *dest, unsigned index, void *src)

Definition at line 11 of file JST_list.h.

Function Documentation

◆ JST_List_move_to()

JST_Error JST_List_move_to ( JST_List from,
void *  dest,
LST_assign_t  assign 
)

For each item in list, call assign to transfert ownership of items and free the list, node by node.

Parameters
fromthe list to clear
destthe destination of transfert, a data structure (opaque here)
assignthe callback able to make the transfert from JST_List to another data structure (opaque here)
Returns
JST_ERR_NONE or JST_ERR_NULL_ARGUMENT when from, dest or assign are null.

Definition at line 25 of file JST_list.c.

25  {
26  if(( from == NULL )||( dest == NULL )||( assign == NULL )) {
27  return JST_ERR_NULL_ARGUMENT;
28  }
29  JST_List * iter = from;
30  for( unsigned i = 0; iter; ++i ) {
31  assign( dest, i, iter->item );
32  JST_List * next = iter->next;
33  free( iter );
34  iter = next;
35  }
36  return JST_ERR_NONE;
37 }
struct JST_Node_ * next
Definition: JST_list.h:6
void * item
Definition: JST_list.h:5
Function misused.
Definition: jstools.h:110

◆ JST_List_push_back()

JST_Error JST_List_push_back ( JST_List **  first,
JST_List **  current,
void *  data 
)
Returns
JST_ERR_NONE or JST_ERR_NULL_ARGUMENT when first or current are null.

Definition at line 7 of file JST_list.c.

7  {
8  if(( first == NULL )||( current == NULL )) {
10  }
11  if( *first == NULL ) {
12  *first = *current = calloc( 1, sizeof( JST_List ));
13  }
14  else {
15  if( *current == NULL ) {
16  return JST_ERR_NULL_ARGUMENT;
17  }
18  (*current)->next = calloc( 1, sizeof( JST_List ));
19  *current = (*current)->next;
20  }
21  (*current)->item = data;
22  return JST_ERR_NONE;
23 }
struct JST_Node_ * next
Definition: JST_list.h:6
void * item
Definition: JST_list.h:5
Function misused.
Definition: jstools.h:110

Variable Documentation

◆ JST_List_Zero

const JST_List JST_List_Zero

Definition at line 5 of file JST_list.c.