|
| 1 | +/***************************************************************************** |
| 2 | + * |
| 3 | + * MODULE: Grass json output interface |
| 4 | + * |
| 5 | + * PURPOSE: parson library function wrapper |
| 6 | + * part of the gparson library |
| 7 | + * |
| 8 | + * COPYRIGHT: (C) 2010 by the GRASS Development Team |
| 9 | + * |
| 10 | + * This program is free software under the GNU General Public |
| 11 | + * License (>=v2). Read the file COPYING that comes with GRASS |
| 12 | + * for details. |
| 13 | + * |
| 14 | + *****************************************************************************/ |
| 15 | + |
| 16 | +#if defined(HAVE_PARSON) |
| 17 | +#include <parson.h> |
| 18 | +#else |
| 19 | +#include <grass/parson.h> |
| 20 | +#endif |
| 21 | + |
| 22 | +/* *************************************************************** */ |
| 23 | +/* ***** WRAPPER FOR PARSON FUNCTIONS USED IN GRASS ************** */ |
| 24 | +/* *************************************************************** */ |
| 25 | + |
| 26 | +/* Serialization Functions */ |
| 27 | +char *G_json_serialize_to_string_pretty(const JSON_Value *value) |
| 28 | +{ |
| 29 | + return json_serialize_to_string_pretty(value); |
| 30 | +} |
| 31 | + |
| 32 | +void G_json_free_serialized_string(char *string) |
| 33 | +{ |
| 34 | + json_free_serialized_string(string); |
| 35 | +} |
| 36 | + |
| 37 | +/* JSON Object Access Functions */ |
| 38 | +JSON_Value *G_json_object_get_value(const JSON_Object *object, const char *name) |
| 39 | +{ |
| 40 | + return json_object_get_value(object, name); |
| 41 | +} |
| 42 | + |
| 43 | +const char *G_json_object_get_string(const JSON_Object *object, |
| 44 | + const char *name) |
| 45 | +{ |
| 46 | + return json_object_get_string(object, name); |
| 47 | +} |
| 48 | + |
| 49 | +JSON_Object *G_json_object_get_object(const JSON_Object *object, |
| 50 | + const char *name) |
| 51 | +{ |
| 52 | + return json_object_get_object(object, name); |
| 53 | +} |
| 54 | + |
| 55 | +JSON_Array *G_json_object_get_array(const JSON_Object *object, const char *name) |
| 56 | +{ |
| 57 | + return json_object_get_array(object, name); |
| 58 | +} |
| 59 | + |
| 60 | +double G_json_object_get_number(const JSON_Object *object, const char *name) |
| 61 | +{ |
| 62 | + return json_object_get_number(object, name); |
| 63 | +} |
| 64 | + |
| 65 | +int G_json_object_get_boolean(const JSON_Object *object, const char *name) |
| 66 | +{ |
| 67 | + return json_object_get_boolean(object, name); |
| 68 | +} |
| 69 | + |
| 70 | +JSON_Value *G_json_object_get_wrapping_value(const JSON_Object *object) |
| 71 | +{ |
| 72 | + return json_object_get_wrapping_value(object); |
| 73 | +} |
| 74 | + |
| 75 | +/* JSON Object Modification Functions */ |
| 76 | +JSON_Status G_json_object_set_value(JSON_Object *object, const char *name, |
| 77 | + JSON_Value *value) |
| 78 | +{ |
| 79 | + return json_object_set_value(object, name, value); |
| 80 | +} |
| 81 | + |
| 82 | +JSON_Status G_json_object_set_string(JSON_Object *object, const char *name, |
| 83 | + const char *string) |
| 84 | +{ |
| 85 | + return json_object_set_string(object, name, string); |
| 86 | +} |
| 87 | + |
| 88 | +JSON_Status G_json_object_set_number(JSON_Object *object, const char *name, |
| 89 | + double number) |
| 90 | +{ |
| 91 | + return json_object_set_number(object, name, number); |
| 92 | +} |
| 93 | + |
| 94 | +JSON_Status G_json_object_set_boolean(JSON_Object *object, const char *name, |
| 95 | + int boolean) |
| 96 | +{ |
| 97 | + return json_object_set_boolean(object, name, boolean); |
| 98 | +} |
| 99 | + |
| 100 | +JSON_Status G_json_object_set_null(JSON_Object *object, const char *name) |
| 101 | +{ |
| 102 | + return json_object_set_null(object, name); |
| 103 | +} |
| 104 | + |
| 105 | +JSON_Status G_json_object_dotset_string(JSON_Object *object, const char *name, |
| 106 | + const char *string) |
| 107 | +{ |
| 108 | + return json_object_dotset_string(object, name, string); |
| 109 | +} |
| 110 | + |
| 111 | +JSON_Status G_json_object_dotset_number(JSON_Object *object, const char *name, |
| 112 | + double number) |
| 113 | +{ |
| 114 | + return json_object_dotset_number(object, name, number); |
| 115 | +} |
| 116 | + |
| 117 | +/* JSON Array Functions */ |
| 118 | +JSON_Status G_json_array_append_value(JSON_Array *array, JSON_Value *value) |
| 119 | +{ |
| 120 | + return json_array_append_value(array, value); |
| 121 | +} |
| 122 | + |
| 123 | +JSON_Status G_json_array_append_string(JSON_Array *array, const char *string) |
| 124 | +{ |
| 125 | + return json_array_append_string(array, string); |
| 126 | +} |
| 127 | + |
| 128 | +JSON_Status G_json_array_append_number(JSON_Array *array, double number) |
| 129 | +{ |
| 130 | + return json_array_append_number(array, number); |
| 131 | +} |
| 132 | + |
| 133 | +JSON_Status G_json_array_append_boolean(JSON_Array *array, int boolean) |
| 134 | +{ |
| 135 | + return json_array_append_boolean(array, boolean); |
| 136 | +} |
| 137 | + |
| 138 | +JSON_Status G_json_array_append_null(JSON_Array *array) |
| 139 | +{ |
| 140 | + return json_array_append_null(array); |
| 141 | +} |
| 142 | + |
| 143 | +/* JSON Value Creation and Freeing */ |
| 144 | +JSON_Value *G_json_value_init_object(void) |
| 145 | +{ |
| 146 | + return json_value_init_object(); |
| 147 | +} |
| 148 | + |
| 149 | +JSON_Object *G_json_value_get_object(const JSON_Value *value) |
| 150 | +{ |
| 151 | + return json_value_get_object(value); |
| 152 | +} |
| 153 | + |
| 154 | +JSON_Object *G_json_object(const JSON_Value *value) |
| 155 | +{ |
| 156 | + return json_object(value); |
| 157 | +} |
| 158 | + |
| 159 | +JSON_Array *G_json_array(const JSON_Value *value) |
| 160 | +{ |
| 161 | + return json_array(value); |
| 162 | +} |
| 163 | + |
| 164 | +JSON_Value *G_json_array_get_value(const JSON_Array *array, size_t index) |
| 165 | +{ |
| 166 | + return json_array_get_value(array, index); |
| 167 | +} |
| 168 | + |
| 169 | +JSON_Value *G_json_value_init_array(void) |
| 170 | +{ |
| 171 | + return json_value_init_array(); |
| 172 | +} |
| 173 | + |
| 174 | +JSON_Value *G_json_value_init_string(const char *string) |
| 175 | +{ |
| 176 | + return json_value_init_string(string); |
| 177 | +} |
| 178 | + |
| 179 | +JSON_Value *G_json_value_init_number(double number) |
| 180 | +{ |
| 181 | + return json_value_init_number(number); |
| 182 | +} |
| 183 | + |
| 184 | +JSON_Value *G_json_value_init_boolean(int boolean) |
| 185 | +{ |
| 186 | + return json_value_init_boolean(boolean); |
| 187 | +} |
| 188 | + |
| 189 | +void G_json_value_free(JSON_Value *value) |
| 190 | +{ |
| 191 | + json_value_free(value); |
| 192 | +} |
0 commit comments