JST: JSON tools  1.0.0
JSON tools dynamic library for reading, manipulating and writing JSON tree
Functions
JST_delete.c File Reference
#include "jstools.h"
#include <stdlib.h>
Include dependency graph for JST_delete.c:

Go to the source code of this file.

Functions

JST_Error JST_delete_pair (JST_Pair *pair)
 
JST_Error JST_delete_object (JST_Object *object)
 
JST_Error JST_delete_array_item (JST_ArrayItem *item)
 
JST_Error JST_delete_array (JST_Array *array)
 
JST_Error JST_delete_element (JST_Element *element)
 

Function Documentation

◆ JST_delete_array()

JST_Error JST_delete_array ( JST_Array array)

Definition at line 40 of file JST_delete.c.

40  {
41  if( array == NULL ) {
42  return JST_ERR_NULL_ARGUMENT;
43  }
44  JST_Error error = JST_ERR_NONE;
45  for( unsigned i = 0; ( error == JST_ERR_NONE )&&( i < array->count ); ++i ) {
46  error = JST_delete_array_item( array->items[i] );
47  }
48  free( array->items );
49  array->parent = NULL;
50  array->count = 0;
51  array->items = NULL;
52  return error;
53 }
JST_Error
When things goes wrong, an error information is given.
Definition: jstools.h:108
JST_Error JST_delete_array_item(JST_ArrayItem *item)
Definition: JST_delete.c:31
Function misused.
Definition: jstools.h:110
struct JST_ArrayItem_ ** items
Array of JST_ArrayItem.
Definition: jstools.h:11
unsigned count
Cardinality of the previous array.
Definition: jstools.h:12
struct JST_Element_ * parent
of type JST_ArrayItem or JST_Pair, case selector is parent->type
Definition: jstools.h:13
Here is the call graph for this function:
Here is the caller graph for this function:

◆ JST_delete_array_item()

JST_Error JST_delete_array_item ( JST_ArrayItem item)

Definition at line 31 of file JST_delete.c.

31  {
32  if( item == NULL ) {
33  return JST_ERR_NULL_ARGUMENT;
34  }
35  JST_Error error = JST_delete_element( &(item->element));
36  free( item );
37  return error;
38 }
JST_Element element
Definition: jstools.h:85
JST_Error
When things goes wrong, an error information is given.
Definition: jstools.h:108
Function misused.
Definition: jstools.h:110
JST_Error JST_delete_element(JST_Element *element)
Definition: JST_delete.c:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ JST_delete_element()

JST_Error JST_delete_element ( JST_Element element)

Definition at line 55 of file JST_delete.c.

55  {
56  if( element == NULL ) {
57  return JST_ERR_NULL_ARGUMENT;
58  }
59  switch( element->type ) {
60  case JST_OBJECT: JST_delete_object( &(element->value.object)); break;
61  case JST_ARRAY : JST_delete_array( &(element->value.array)); break;
62  case JST_STRING: free( element->value.string ); break;
63  default: break;
64  }
65  element->type = JST_NULL;
66  element->value.string = NULL;
67  return JST_ERR_NONE;
68 }
char * string
Definition: jstools.h:46
JST_Object object
Definition: jstools.h:41
JST_Value value
Definition: jstools.h:72
JST_Error JST_delete_array(JST_Array *array)
Definition: JST_delete.c:40
JST_Array array
Definition: jstools.h:42
Function misused.
Definition: jstools.h:110
JST_Error JST_delete_object(JST_Object *object)
Definition: JST_delete.c:15
JST_ValueType type
Definition: jstools.h:71
Here is the call graph for this function:
Here is the caller graph for this function:

◆ JST_delete_object()

JST_Error JST_delete_object ( JST_Object object)

Definition at line 15 of file JST_delete.c.

15  {
16  if( object == NULL ) {
17  return JST_ERR_NULL_ARGUMENT;
18  }
19  JST_Error error = JST_ERR_NONE;
20  for( unsigned i = 0; ( error == JST_ERR_NONE )&&( i < object->count ); ++i ) {
21  error = JST_delete_pair( object->items[i] );
22  }
23  free( object->items );
24  object->parent = NULL;
25  object->count = 0;
26  object->first = NULL;
27  object->items = NULL;
28  return error;
29 }
struct JST_Pair_ ** items
Array of JST_Pair, ordered by JST_Pair.name to ease search with bsearch()
Definition: jstools.h:25
JST_Error
When things goes wrong, an error information is given.
Definition: jstools.h:108
JST_Error JST_delete_pair(JST_Pair *pair)
Definition: JST_delete.c:5
Function misused.
Definition: jstools.h:110
Here is the call graph for this function:
Here is the caller graph for this function:

◆ JST_delete_pair()

JST_Error JST_delete_pair ( JST_Pair pair)

Definition at line 5 of file JST_delete.c.

5  {
6  if( pair == NULL ) {
8  }
9  JST_Error error = JST_delete_element( &(pair->element));
10  free( pair->name );
11  free( pair );
12  return error;
13 }
char * name
This property&#39;s name.
Definition: jstools.h:96
JST_Error
When things goes wrong, an error information is given.
Definition: jstools.h:108
Function misused.
Definition: jstools.h:110
JST_Error JST_delete_element(JST_Element *element)
Definition: JST_delete.c:55
JST_Element element
The value associated with the name.
Definition: jstools.h:95
Here is the call graph for this function:
Here is the caller graph for this function: