Debian Codegraph @

CodeLite/cJSON.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2014 Eran Ifrah
5 // file name : cJSON.h
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25
26 /*
27 Copyright (c) 2009 Dave Gamble
28
29 Permission is hereby granted, free of charge, to any person obtaining a copy
30 of this software and associated documentation files (the "Software"), to deal
31 in the Software without restriction, including without limitation the rights
32 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
33 copies of the Software, and to permit persons to whom the Software is
34 furnished to do so, subject to the following conditions:
35
36 The above copyright notice and this permission notice shall be included in
37 all copies or substantial portions of the Software.
38
39 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
42 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
43 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
44 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
45 THE SOFTWARE.
46 */
47
48 #ifndef cJSON__h
49 #define cJSON__h
50
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54
55 /* cJSON Types: */
56 #define cJSON_False 0
57 #define cJSON_True 1
58 #define cJSON_NULL 2
59 #define cJSON_Number 3
60 #define cJSON_String 4
61 #define cJSON_Array 5
62 #define cJSON_Object 6
63
64 #define cJSON_IsReference 256
65
66 /* The cJSON structure: */
67 typedef struct cJSON
68 {
69 struct cJSON* next, *prev; /* next/prev allow you to walk array/object chains. Alternatively, use
70 GetArraySize/GetArrayItem/GetObjectItem */
71 struct cJSON*
72 child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
73
74 int type; /* The type of the item, as above. */
75
76 char* valuestring; /* The item's string, if type==cJSON_String */
77 int valueint; /* The item's number, if type==cJSON_Number */
78 double valuedouble; /* The item's number, if type==cJSON_Number */
79
80 char*
81 string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
82 } cJSON;
83
84 typedef struct cJSON_Hooks
85 {
86 void* (*malloc_fn)(size_t sz);
87 void (*free_fn)(void* ptr);
88 } cJSON_Hooks;
89
90 /* Supply malloc, realloc and free functions to cJSON */
91 extern void cJSON_InitHooks(cJSON_Hooks* hooks);
92
93 /* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
94 extern cJSON* cJSON_Parse(const char* value);
95 /* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */
96 extern char* cJSON_Print(cJSON* item);
97 /* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */
98 extern char* cJSON_PrintUnformatted(cJSON* item);
99 /* Delete a cJSON entity and all subentities. */
100 extern void cJSON_Delete(cJSON* c);
101
102 /* Returns the number of items in an array (or object). */
103 extern int cJSON_GetArraySize(cJSON* array);
104 /* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
105 extern cJSON* cJSON_GetArrayItem(cJSON* array, int item);
106 /* Get item "string" from object. Case insensitive. */
107 extern cJSON* cJSON_GetObjectItem(cJSON* object, const char* string);
108
109 /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back
110 * to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
111 extern const char* cJSON_GetErrorPtr();
112
113 /* These calls create a cJSON item of the appropriate type. */
114 extern cJSON* cJSON_CreateNull();
115 extern cJSON* cJSON_CreateTrue();
116 extern cJSON* cJSON_CreateFalse();
117 extern cJSON* cJSON_CreateBool(int b);
118 extern cJSON* cJSON_CreateNumber(double num);
119 extern cJSON* cJSON_CreateString(const char* string);
120 extern cJSON* cJSON_CreateArray();
121 extern cJSON* cJSON_CreateObject();
122
123 /* These utilities create an Array of count items. */
124 extern cJSON* cJSON_CreateIntArray(int* numbers, int count);
125 extern cJSON* cJSON_CreateFloatArray(float* numbers, int count);
126 extern cJSON* cJSON_CreateDoubleArray(double* numbers, int count);
127 extern cJSON* cJSON_CreateStringArray(const char** strings, int count);
128
129 /* Append item to the specified array/object. */
130 extern void cJSON_AddItemToArray(cJSON* array, cJSON* item);
131 extern void cJSON_AddItemToObject(cJSON* object, const char* string, cJSON* item);
132 /* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new
133 * cJSON, but don't want to corrupt your existing cJSON. */
134 extern void cJSON_AddItemReferenceToArray(cJSON* array, cJSON* item);
135 extern void cJSON_AddItemReferenceToObject(cJSON* object, const char* string, cJSON* item);
136
137 /* Remove/Detatch items from Arrays/Objects. */
138 extern cJSON* cJSON_DetachItemFromArray(cJSON* array, int which);
139 extern void cJSON_DeleteItemFromArray(cJSON* array, int which);
140 extern cJSON* cJSON_DetachItemFromObject(cJSON* object, const char* string);
141 extern void cJSON_DeleteItemFromObject(cJSON* object, const char* string);
142
143 /* Update array items. */
144 extern void cJSON_ReplaceItemInArray(cJSON* array, int which, cJSON* newitem);
145 extern void cJSON_ReplaceItemInObject(cJSON* object, const char* string, cJSON* newitem);
146
147 #define cJSON_AddNullToObject(object, name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
148 #define cJSON_AddTrueToObject(object, name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
149 #define cJSON_AddFalseToObject(object, name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
150 #define cJSON_AddNumberToObject(object, name, n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
151 #define cJSON_AddStringToObject(object, name, s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
152
153 #ifdef __cplusplus
154 }
155 #endif
156
157 #endif