xref: /petsc/src/mat/tests/cJSON.h (revision 9d47de495d3c23378050c1b4a410c12a375cb6c6)
189928cc5SHong Zhang /*
289928cc5SHong Zhang   Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
389928cc5SHong Zhang 
489928cc5SHong Zhang   Permission is hereby granted, free of charge, to any person obtaining a copy
589928cc5SHong Zhang   of this software and associated documentation files (the "Software"), to deal
689928cc5SHong Zhang   in the Software without restriction, including without limitation the rights
789928cc5SHong Zhang   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
889928cc5SHong Zhang   copies of the Software, and to permit persons to whom the Software is
989928cc5SHong Zhang   furnished to do so, subject to the following conditions:
1089928cc5SHong Zhang 
1189928cc5SHong Zhang   The above copyright notice and this permission notice shall be included in
1289928cc5SHong Zhang   all copies or substantial portions of the Software.
1389928cc5SHong Zhang 
1489928cc5SHong Zhang   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1589928cc5SHong Zhang   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1689928cc5SHong Zhang   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1789928cc5SHong Zhang   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1889928cc5SHong Zhang   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1989928cc5SHong Zhang   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2089928cc5SHong Zhang   THE SOFTWARE.
2189928cc5SHong Zhang */
2289928cc5SHong Zhang 
23a4963045SJacob Faibussowitsch #pragma once
2489928cc5SHong Zhang 
2589928cc5SHong Zhang #ifdef __cplusplus
2689928cc5SHong Zhang extern "C" {
2789928cc5SHong Zhang #endif
2889928cc5SHong Zhang 
2989928cc5SHong Zhang #if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
3089928cc5SHong Zhang   #define __WINDOWS__
3189928cc5SHong Zhang #endif
3289928cc5SHong Zhang 
3389928cc5SHong Zhang #ifdef __WINDOWS__
3489928cc5SHong Zhang 
3589928cc5SHong Zhang /* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention.  For windows you have 3 define options:
3689928cc5SHong Zhang 
3789928cc5SHong Zhang CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
3889928cc5SHong Zhang CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
3989928cc5SHong Zhang CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
4089928cc5SHong Zhang 
4189928cc5SHong Zhang For *nix builds that support visibility attribute, you can define similar behavior by
4289928cc5SHong Zhang 
4389928cc5SHong Zhang setting default visibility to hidden by adding
4489928cc5SHong Zhang -fvisibility=hidden (for gcc)
4589928cc5SHong Zhang or
4689928cc5SHong Zhang -xldscope=hidden (for sun cc)
4789928cc5SHong Zhang to CFLAGS
4889928cc5SHong Zhang 
4989928cc5SHong Zhang then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
5089928cc5SHong Zhang 
5189928cc5SHong Zhang */
5289928cc5SHong Zhang 
5389928cc5SHong Zhang   #define CJSON_CDECL   __cdecl
5489928cc5SHong Zhang   #define CJSON_STDCALL __stdcall
5589928cc5SHong Zhang 
5689928cc5SHong Zhang   /* export symbols by default, this is necessary for copy pasting the C and header file */
5789928cc5SHong Zhang   #if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
5889928cc5SHong Zhang     #define CJSON_EXPORT_SYMBOLS
5989928cc5SHong Zhang   #endif
6089928cc5SHong Zhang 
6189928cc5SHong Zhang   #if defined(CJSON_HIDE_SYMBOLS)
6289928cc5SHong Zhang     #define CJSON_PUBLIC(type) type CJSON_STDCALL
6389928cc5SHong Zhang   #elif defined(CJSON_EXPORT_SYMBOLS)
6489928cc5SHong Zhang     #define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
6589928cc5SHong Zhang   #elif defined(CJSON_IMPORT_SYMBOLS)
6689928cc5SHong Zhang     #define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
6789928cc5SHong Zhang   #endif
6889928cc5SHong Zhang #else /* !__WINDOWS__ */
6989928cc5SHong Zhang   #define CJSON_CDECL
7089928cc5SHong Zhang   #define CJSON_STDCALL
7189928cc5SHong Zhang 
7289928cc5SHong Zhang   #if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
7389928cc5SHong Zhang     #define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
7489928cc5SHong Zhang   #else
7589928cc5SHong Zhang     #define CJSON_PUBLIC(type) type
7689928cc5SHong Zhang   #endif
7789928cc5SHong Zhang #endif
7889928cc5SHong Zhang 
7989928cc5SHong Zhang /* project version */
8089928cc5SHong Zhang #define CJSON_VERSION_MAJOR 1
8189928cc5SHong Zhang #define CJSON_VERSION_MINOR 7
8289928cc5SHong Zhang #define CJSON_VERSION_PATCH 15
8389928cc5SHong Zhang 
8489928cc5SHong Zhang #include <stddef.h>
8589928cc5SHong Zhang 
8689928cc5SHong Zhang /* cJSON Types: */
8789928cc5SHong Zhang #define cJSON_Invalid (0)
8889928cc5SHong Zhang #define cJSON_False   (1 << 0)
8989928cc5SHong Zhang #define cJSON_True    (1 << 1)
9089928cc5SHong Zhang #define cJSON_NULL    (1 << 2)
9189928cc5SHong Zhang #define cJSON_Number  (1 << 3)
9289928cc5SHong Zhang #define cJSON_String  (1 << 4)
9389928cc5SHong Zhang #define cJSON_Array   (1 << 5)
9489928cc5SHong Zhang #define cJSON_Object  (1 << 6)
9589928cc5SHong Zhang #define cJSON_Raw     (1 << 7) /* raw json */
9689928cc5SHong Zhang 
9789928cc5SHong Zhang #define cJSON_IsReference   256
9889928cc5SHong Zhang #define cJSON_StringIsConst 512
9989928cc5SHong Zhang 
10089928cc5SHong Zhang /* The cJSON structure: */
10189928cc5SHong Zhang typedef struct cJSON {
10289928cc5SHong Zhang   /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
10389928cc5SHong Zhang   struct cJSON *next;
10489928cc5SHong Zhang   struct cJSON *prev;
10589928cc5SHong Zhang   /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
10689928cc5SHong Zhang   struct cJSON *child;
10789928cc5SHong Zhang 
10889928cc5SHong Zhang   /* The type of the item, as above. */
10989928cc5SHong Zhang   int type;
11089928cc5SHong Zhang 
11189928cc5SHong Zhang   /* The item's string, if type==cJSON_String  and type == cJSON_Raw */
11289928cc5SHong Zhang   char *valuestring;
11389928cc5SHong Zhang   /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
11489928cc5SHong Zhang   int valueint;
11589928cc5SHong Zhang   /* The item's number, if type==cJSON_Number */
11689928cc5SHong Zhang   double valuedouble;
11789928cc5SHong Zhang 
11889928cc5SHong Zhang   /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
11989928cc5SHong Zhang   char *string;
12089928cc5SHong Zhang } cJSON;
12189928cc5SHong Zhang 
12289928cc5SHong Zhang typedef struct cJSON_Hooks {
12389928cc5SHong Zhang   /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
12489928cc5SHong Zhang   void *(CJSON_CDECL *malloc_fn)(size_t sz);
12589928cc5SHong Zhang   void(CJSON_CDECL *free_fn)(void *ptr);
12689928cc5SHong Zhang } cJSON_Hooks;
12789928cc5SHong Zhang 
12889928cc5SHong Zhang typedef int cJSON_bool;
12989928cc5SHong Zhang 
13089928cc5SHong Zhang /* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
13189928cc5SHong Zhang  * This is to prevent stack overflows. */
132*beceaeb6SBarry Smith #if !defined(CJSON_NESTING_LIMIT)
13389928cc5SHong Zhang   #define CJSON_NESTING_LIMIT 1000
13489928cc5SHong Zhang #endif
13589928cc5SHong Zhang 
13689928cc5SHong Zhang /* returns the version of cJSON as a string */
13789928cc5SHong Zhang CJSON_PUBLIC(const char *) cJSON_Version(void);
13889928cc5SHong Zhang 
13989928cc5SHong Zhang /* Supply malloc, realloc and free functions to cJSON */
14089928cc5SHong Zhang CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks);
14189928cc5SHong Zhang 
14289928cc5SHong Zhang /* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
14389928cc5SHong Zhang /* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
14489928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
14589928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
14689928cc5SHong Zhang /* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
14789928cc5SHong Zhang /* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
14889928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
14989928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
15089928cc5SHong Zhang 
15189928cc5SHong Zhang /* Render a cJSON entity to text for transfer/storage. */
15289928cc5SHong Zhang CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
15389928cc5SHong Zhang /* Render a cJSON entity to text for transfer/storage without any formatting. */
15489928cc5SHong Zhang CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
15589928cc5SHong Zhang /* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
15689928cc5SHong Zhang CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
15789928cc5SHong Zhang /* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
15889928cc5SHong Zhang /* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
15989928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
16089928cc5SHong Zhang /* Delete a cJSON entity and all subentities. */
16189928cc5SHong Zhang CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
16289928cc5SHong Zhang 
16389928cc5SHong Zhang /* Returns the number of items in an array (or object). */
16489928cc5SHong Zhang CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
16589928cc5SHong Zhang /* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
16689928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
16789928cc5SHong Zhang /* Get item "string" from object. Case insensitive. */
16889928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON *const object, const char *const string);
16989928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON *const object, const char *const string);
17089928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
17189928cc5SHong Zhang /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
17289928cc5SHong Zhang CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
17389928cc5SHong Zhang 
17489928cc5SHong Zhang /* Check item type and return its value */
17589928cc5SHong Zhang CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON *const item);
17689928cc5SHong Zhang CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON *const item);
17789928cc5SHong Zhang 
17889928cc5SHong Zhang /* These functions check the type of an item */
17989928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON *const item);
18089928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON *const item);
18189928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON *const item);
18289928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON *const item);
18389928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON *const item);
18489928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON *const item);
18589928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON *const item);
18689928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON *const item);
18789928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON *const item);
18889928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON *const item);
18989928cc5SHong Zhang 
19089928cc5SHong Zhang /* These calls create a cJSON item of the appropriate type. */
19189928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
19289928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
19389928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
19489928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
19589928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
19689928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
19789928cc5SHong Zhang /* raw json */
19889928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
19989928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
20089928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
20189928cc5SHong Zhang 
20289928cc5SHong Zhang /* Create a string where valuestring references a string so
20389928cc5SHong Zhang  * it will not be freed by cJSON_Delete */
20489928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
20589928cc5SHong Zhang /* Create an object/array that only references it's elements so
20689928cc5SHong Zhang  * they will not be freed by cJSON_Delete */
20789928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
20889928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
20989928cc5SHong Zhang 
21089928cc5SHong Zhang /* These utilities create an Array of count items.
21189928cc5SHong Zhang  * The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
21289928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
21389928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
21489928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
21589928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
21689928cc5SHong Zhang 
21789928cc5SHong Zhang /* Append item to the specified array/object. */
21889928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
21989928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
22089928cc5SHong Zhang /* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
22189928cc5SHong Zhang  * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
22289928cc5SHong Zhang  * writing to `item->string` */
22389928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
22489928cc5SHong Zhang /* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
22589928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
22689928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
22789928cc5SHong Zhang 
22889928cc5SHong Zhang /* Remove/Detach items from Arrays/Objects. */
22989928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item);
23089928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
23189928cc5SHong Zhang CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
23289928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
23389928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
23489928cc5SHong Zhang CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
23589928cc5SHong Zhang CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
23689928cc5SHong Zhang 
23789928cc5SHong Zhang /* Update array items. */
23889928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
23989928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, cJSON *replacement);
24089928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
24189928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem);
24289928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem);
24389928cc5SHong Zhang 
24489928cc5SHong Zhang /* Duplicate a cJSON item */
24589928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
24689928cc5SHong Zhang /* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
24789928cc5SHong Zhang  * need to be released. With recurse!=0, it will duplicate any children connected to the item.
24889928cc5SHong Zhang  * The item->next and ->prev pointers are always zero on return from Duplicate. */
24989928cc5SHong Zhang /* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
25089928cc5SHong Zhang  * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
25189928cc5SHong Zhang CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON *const a, const cJSON *const b, const cJSON_bool case_sensitive);
25289928cc5SHong Zhang 
25389928cc5SHong Zhang /* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
25489928cc5SHong Zhang  * The input pointer json cannot point to a read-only address area, such as a string constant,
25589928cc5SHong Zhang  * but should point to a readable and writable address area. */
25689928cc5SHong Zhang CJSON_PUBLIC(void) cJSON_Minify(char *json);
25789928cc5SHong Zhang 
25889928cc5SHong Zhang /* Helper functions for creating and adding items to an object at the same time.
25989928cc5SHong Zhang  * They return the added item or NULL on failure. */
26089928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_AddNullToObject(cJSON *const object, const char *const name);
26189928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_AddTrueToObject(cJSON *const object, const char *const name);
26289928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_AddFalseToObject(cJSON *const object, const char *const name);
26389928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_AddBoolToObject(cJSON *const object, const char *const name, const cJSON_bool boolean);
26489928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_AddNumberToObject(cJSON *const object, const char *const name, const double number);
26589928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_AddStringToObject(cJSON *const object, const char *const name, const char *const string);
26689928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_AddRawToObject(cJSON *const object, const char *const name, const char *const raw);
26789928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_AddObjectToObject(cJSON *const object, const char *const name);
26889928cc5SHong Zhang CJSON_PUBLIC(cJSON *) cJSON_AddArrayToObject(cJSON *const object, const char *const name);
26989928cc5SHong Zhang 
27089928cc5SHong Zhang /* When assigning an integer value, it needs to be propagated to valuedouble too. */
27189928cc5SHong Zhang #define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
27289928cc5SHong Zhang /* helper for the cJSON_SetNumberValue macro */
27389928cc5SHong Zhang CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
27489928cc5SHong Zhang #define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
27589928cc5SHong Zhang /* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
27689928cc5SHong Zhang CJSON_PUBLIC(char *) cJSON_SetValuestring(cJSON *object, const char *valuestring);
27789928cc5SHong Zhang 
27889928cc5SHong Zhang /* If the object is not a boolean type this does nothing and returns cJSON_Invalid else it returns the new type*/
27989928cc5SHong Zhang #define cJSON_SetBoolValue(object, boolValue) ((object != NULL && ((object)->type & (cJSON_False | cJSON_True))) ? (object)->type = ((object)->type & (~(cJSON_False | cJSON_True))) | ((boolValue) ? cJSON_True : cJSON_False) : cJSON_Invalid)
28089928cc5SHong Zhang 
28189928cc5SHong Zhang /* Macro for iterating over an array or object */
28289928cc5SHong Zhang #define cJSON_ArrayForEach(element, array) for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
28389928cc5SHong Zhang 
28489928cc5SHong Zhang /* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
28589928cc5SHong Zhang CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
28689928cc5SHong Zhang CJSON_PUBLIC(void) cJSON_free(void *object);
28789928cc5SHong Zhang 
28889928cc5SHong Zhang #ifdef __cplusplus
28989928cc5SHong Zhang }
29089928cc5SHong Zhang #endif
291