lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #ifndef cJSON__h |
| 2 | #define cJSON__h |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" |
| 6 | { |
| 7 | #endif |
| 8 | |
| 9 | |
| 10 | #define cJSON_False 0 |
| 11 | #define cJSON_True 1 |
| 12 | #define cJSON_NULL 2 |
| 13 | #define cJSON_Number 3 |
| 14 | #define cJSON_String 4 |
| 15 | #define cJSON_Array 5 |
| 16 | #define cJSON_Object 6 |
| 17 | |
| 18 | #define cJSON_IsReference 256 |
| 19 | |
| 20 | typedef struct cJSON_Hooks { |
| 21 | void *(*malloc_fn)(size_t sz); |
| 22 | void (*free_fn)(void *ptr); |
| 23 | } cJSON_Hooks; |
| 24 | |
| 25 | typedef struct cJSON { |
| 26 | struct cJSON *next, *prev; |
| 27 | struct cJSON *child; |
| 28 | |
| 29 | int type; |
| 30 | |
| 31 | char *valuestring; |
| 32 | int valueint; |
| 33 | double valuedouble; |
| 34 | |
| 35 | char *string; |
| 36 | } cJSON; |
| 37 | |
| 38 | |
| 39 | extern void cJSON_InitHooks(cJSON_Hooks* hooks); |
| 40 | |
| 41 | extern cJSON *cJSON_Parse(const char *value); |
| 42 | extern char *cJSON_Print(cJSON *item); |
| 43 | extern char *cJSON_PrintUnformatted(cJSON *item); |
| 44 | |
| 45 | extern int cJSON_GetArraySize(cJSON *array); |
| 46 | extern cJSON *cJSON_GetArrayItem(cJSON *array, int item); |
| 47 | extern cJSON *cJSON_GetObjectItem(cJSON *object, const char *string); |
| 48 | |
| 49 | extern const char *cJSON_GetErrorPtr(void); |
| 50 | |
| 51 | extern cJSON *cJSON_CreateNull(void); |
| 52 | extern cJSON *cJSON_CreateTrue(void); |
| 53 | extern cJSON *cJSON_CreateFalse(void); |
| 54 | extern cJSON *cJSON_CreateBool(int b); |
| 55 | extern cJSON *cJSON_CreateNumber(double num); |
| 56 | extern cJSON *cJSON_CreateString(const char *string); |
| 57 | extern cJSON *cJSON_CreateArray(void); |
| 58 | extern cJSON *cJSON_CreateObject(void); |
| 59 | |
| 60 | extern cJSON *cJSON_CreateIntArray(const int *numbers, int count); |
| 61 | extern cJSON *cJSON_CreateFloatArray(const float *numbers, int count); |
| 62 | extern cJSON *cJSON_CreateDoubleArray(const double *numbers, int count); |
| 63 | extern cJSON *cJSON_CreateStringArray(const char **strings, int count); |
| 64 | |
| 65 | extern void cJSON_AddItemToArray(cJSON *array, cJSON *item); |
| 66 | extern void cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); |
| 67 | extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); |
| 68 | extern void cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); |
| 69 | |
| 70 | extern void cJSON_Delete(cJSON *c); |
| 71 | |
| 72 | extern cJSON *cJSON_DetachItemFromArray(cJSON *array, int which); |
| 73 | extern void cJSON_DeleteItemFromArray(cJSON *array, int which); |
| 74 | extern cJSON *cJSON_DetachItemFromObject(cJSON *object, const char *string); |
| 75 | extern void cJSON_DeleteItemFromObject(cJSON *object, const char *string); |
| 76 | |
| 77 | extern void cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); |
| 78 | extern void cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem); |
| 79 | |
| 80 | extern cJSON *cJSON_Duplicate(cJSON *item, int recurse); |
| 81 | extern cJSON *cJSON_ParseWithOpts(const char *value, const char **return_parse_end, int require_null_terminated); |
| 82 | |
| 83 | extern void cJSON_Minify(char *json); |
| 84 | |
| 85 | #define cJSON_SetIntValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val)) |
| 86 | |
| 87 | #define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull()) |
| 88 | #define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue()) |
| 89 | #define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse()) |
| 90 | #define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b)) |
| 91 | #define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n)) |
| 92 | #define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s)) |
| 93 | |
| 94 | |
| 95 | #ifdef __cplusplus |
| 96 | } |
| 97 | #endif |
| 98 | |
| 99 | #endif |