• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2   Copyright (c) 2009 Dave Gamble
3   Copyright (c) 2015-2021 The Khronos Group Inc.
4   Copyright (c) 2015-2021 Valve Corporation
5   Copyright (c) 2015-2021 LunarG, Inc.
6 
7   Permission is hereby granted, free of charge, to any person obtaining a copy
8   of this software and associated documentation files (the "Software"), to deal
9   in the Software without restriction, including without limitation the rights
10   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11   copies of the Software, and to permit persons to whom the Software is
12   furnished to do so, subject to the following conditions:
13 
14   The above copyright notice and this permission notice shall be included in
15   all copies or substantial portions of the Software.
16 
17   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23   THE SOFTWARE.
24 */
25 
26 #pragma once
27 
28 #include "loader_common.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /* cJSON Types: */
35 #define cJSON_False 0
36 #define cJSON_True 1
37 #define cJSON_NULL 2
38 #define cJSON_Number 3
39 #define cJSON_String 4
40 #define cJSON_Array 5
41 #define cJSON_Object 6
42 
43 #define cJSON_IsReference 256
44 #define cJSON_StringIsConst 512
45 
46 /* The cJSON structure: */
47 typedef struct cJSON {
48     struct cJSON *next, *prev; /* next/prev allow you to walk array/object
49                                   chains. Alternatively, use
50                                   GetArraySize/GetArrayItem/GetObjectItem */
51     struct cJSON *child;       /* An array or object item will have a child pointer
52                                   pointing to a chain of the items in the
53                                   array/object. */
54 
55     int type; /* The type of the item, as above. */
56 
57     char *valuestring;  /* The item's string, if type==cJSON_String */
58     int valueint;       /* The item's number, if type==cJSON_Number */
59     double valuedouble; /* The item's number, if type==cJSON_Number */
60 
61     char *string; /* The item's name string, if this item is the child of, or is
62                      in the list of subitems of an object. */
63     /* pointer to the allocation callbacks to use */
64     VkAllocationCallbacks *pAllocator;
65 } cJSON;
66 
67 /* Supply a block of JSON, and this returns a cJSON object you can interrogate.
68  * Call cJSON_Delete when finished. */
69 cJSON *cJSON_Parse(const VkAllocationCallbacks *pAllocator, const char *value);
70 /* Render a cJSON entity to text for transfer/storage. Free the char* when
71  * finished. */
72 char *cJSON_Print(cJSON *item);
73 /* Render a cJSON entity to text for transfer/storage without any formatting.
74  * Free the char* when finished. */
75 char *cJSON_PrintUnformatted(cJSON *item);
76 /* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess
77  * at the final size. guessing well reduces reallocation. fmt=0 gives
78  * unformatted, =1 gives formatted */
79 char *cJSON_PrintBuffered(cJSON *item, int prebuffer, int fmt);
80 /* Delete a cJSON entity and all subentities. */
81 void cJSON_Delete(cJSON *c);
82 /* Delete an item allocated inside the JSON parser*/
83 void cJSON_Free(const VkAllocationCallbacks *pAllocator, void *p);
84 
85 /* Returns the number of items in an array (or object). */
86 int cJSON_GetArraySize(cJSON *array);
87 /* Retrieve item number "item" from array "array". Returns NULL if unsuccessful.
88  */
89 cJSON *cJSON_GetArrayItem(cJSON *array, int item);
90 /* Get item "string" from object. Case insensitive. */
91 cJSON *cJSON_GetObjectItem(cJSON *object, const char *string);
92 
93 /* For analysing failed parses. This returns a pointer to the parse error.
94  * You'll probably need to look a few chars back to make sense of it. Defined
95  * when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
96 const char *cJSON_GetErrorPtr(void);
97 
98 /* These calls create a cJSON item of the appropriate type. */
99 cJSON *cJSON_CreateNull(const VkAllocationCallbacks *pAllocator);
100 cJSON *cJSON_CreateTrue(const VkAllocationCallbacks *pAllocator);
101 cJSON *cJSON_CreateFalse(const VkAllocationCallbacks *pAllocator);
102 cJSON *cJSON_CreateBool(const VkAllocationCallbacks *pAllocator, int b);
103 cJSON *cJSON_CreateNumber(const VkAllocationCallbacks *pAllocator, double num);
104 cJSON *cJSON_CreateString(const VkAllocationCallbacks *pAllocator, const char *string);
105 cJSON *cJSON_CreateArray(const VkAllocationCallbacks *pAllocator);
106 cJSON *cJSON_CreateObject(const VkAllocationCallbacks *pAllocator);
107 
108 /* These utilities create an Array of count items. */
109 cJSON *cJSON_CreateIntArray(const VkAllocationCallbacks *pAllocator, const int *numbers, int count);
110 cJSON *cJSON_CreateFloatArray(const VkAllocationCallbacks *pAllocator, const float *numbers, int count);
111 cJSON *cJSON_CreateDoubleArray(const VkAllocationCallbacks *pAllocator, const double *numbers, int count);
112 cJSON *cJSON_CreateStringArray(const VkAllocationCallbacks *pAllocator, const char **strings, int count);
113 
114 /* Append item to the specified array/object. */
115 void cJSON_AddItemToArray(cJSON *array, cJSON *item);
116 void cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
117 /* Use this when string is definitely const  (i.e. a literal, or as good as), and
118  * will definitely survive the cJSON object */
119 void cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
120 /* Append reference to item to the specified array/object. Use this when you
121  * want to add an existing cJSON to a new cJSON, but don't want to corrupt your
122  * existing cJSON. */
123 void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
124 void cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
125 
126 /* Remove/Detach items from Arrays/Objects. */
127 cJSON *cJSON_DetachItemFromArray(cJSON *array, int which);
128 void cJSON_DeleteItemFromArray(cJSON *array, int which);
129 cJSON *cJSON_DetachItemFromObject(cJSON *object, const char *string);
130 void cJSON_DeleteItemFromObject(cJSON *object, const char *string);
131 
132 /* Update array items. */
133 void cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
134 void cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
135 void cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem);
136 
137 /* Duplicate a cJSON item */
138 cJSON *cJSON_Duplicate(cJSON *item, int recurse);
139 /* Duplicate will create a new, identical cJSON item to the one you pass, in new
140 memory that will
141 need to be released. With recurse!=0, it will duplicate any children connected
142 to the item.
143 The item->next and ->prev pointers are always zero on return from Duplicate. */
144 
145 /* ParseWithOpts allows you to require (and check) that the JSON is null
146  * terminated, and to retrieve the pointer to the final byte parsed. */
147 cJSON *cJSON_ParseWithOpts(const VkAllocationCallbacks *pAllocator, const char *value, const char **return_parse_end,
148                            int require_null_terminated);
149 
150 void cJSON_Minify(char *json);
151 
152 /* When assigning an integer value, it needs to be propagated to valuedouble
153  * too. */
154 #define cJSON_SetIntValue(object, val) ((object) ? (object)->valueint = (object)->valuedouble = (val) : (val))
155 #define cJSON_SetNumberValue(object, val) ((object) ? (object)->valueint = (object)->valuedouble = (val) : (val))
156 
157 #ifdef __cplusplus
158 }
159 #endif
160