Point Cloud Library (PCL)  1.14.0-dev
cJSON.h
1 /*
2  Copyright (c) 2009 Dave Gamble
3 
4  Permission is hereby granted, free of charge, to any person obtaining a copy
5  of this software and associated documentation files (the "Software"), to deal
6  in the Software without restriction, including without limitation the rights
7  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  copies of the Software, and to permit persons to whom the Software is
9  furnished to do so, subject to the following conditions:
10 
11  The above copyright notice and this permission notice shall be included in
12  all copies or substantial portions of the Software.
13 
14  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  THE SOFTWARE.
21 */
22 
23 #pragma once
24 
25 #include <pcl/pcl_macros.h>
26 
27 //make interop with c++ string easier
28 #include <string>
29 
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif
34 
35 /* cJSON Types: */
36 #define cJSON_False 0
37 #define cJSON_True 1
38 #define cJSON_NULL 2
39 #define cJSON_Number 3
40 #define cJSON_String 4
41 #define cJSON_Array 5
42 #define cJSON_Object 6
43 
44 #define cJSON_IsReference 256
45 
46 /* The cJSON structure: */
47 typedef struct cJSON { // NOLINT
48  struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
49  struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
50 
51  int type; /* The type of the item, as above. */
52 
53  char *valuestring; /* The item's string, if type==cJSON_String */
54  int valueint; /* The item's number, if type==cJSON_Number */
55  double valuedouble; /* The item's number, if type==cJSON_Number */
56 
57  char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
58 } cJSON;
59 
60 typedef struct cJSON_Hooks { // NOLINT
61  void *(*malloc_fn)(std::size_t sz);
62  void (*free_fn)(void *ptr);
63 } cJSON_Hooks;
64 
65 /* Supply malloc, realloc and free functions to cJSON */
66 PCLAPI(void) cJSON_InitHooks(cJSON_Hooks* hooks);
67 
68 
69 /* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
70 PCLAPI(cJSON *) cJSON_Parse(const char *value);
71 /* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */
72 PCLAPI(char *) cJSON_Print(cJSON *item);
73 /* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */
74 PCLAPI(char *) cJSON_PrintUnformatted(cJSON *item);
75 /* Delete a cJSON entity and all subentities. */
76 PCLAPI(void) cJSON_Delete(cJSON *c);
77 /* Render a cJSON entity to text for transfer/storage. */
78 PCLAPI(void) cJSON_PrintStr(cJSON *item, std::string& s);
79 /* Render a cJSON entity to text for transfer/storage without any formatting. */
80 PCLAPI(void) cJSON_PrintUnformattedStr(cJSON *item, std::string& s);
81 
82 /* Returns the number of items in an array (or object). */
83 PCLAPI(int) cJSON_GetArraySize(cJSON *array);
84 /* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
85 PCLAPI(cJSON *) cJSON_GetArrayItem(cJSON *array,int item);
86 /* Get item "string" from object. Case insensitive. */
87 PCLAPI(cJSON *) cJSON_GetObjectItem(cJSON *object,const char *string);
88 
89 /* 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. */
90 PCLAPI(const char *) cJSON_GetErrorPtr();
91 
92 /* These calls create a cJSON item of the appropriate type. */
93 PCLAPI(cJSON *) cJSON_CreateNull();
94 PCLAPI(cJSON *) cJSON_CreateTrue();
95 PCLAPI(cJSON *) cJSON_CreateFalse();
96 PCLAPI(cJSON *) cJSON_CreateBool(int b);
97 PCLAPI(cJSON *) cJSON_CreateNumber(double num);
98 PCLAPI(cJSON *) cJSON_CreateString(const char *string);
99 PCLAPI(cJSON *) cJSON_CreateArray();
100 PCLAPI(cJSON *) cJSON_CreateObject();
101 
102 /* These utilities create an Array of count items. */
103 PCLAPI(cJSON *) cJSON_CreateIntArray(int *numbers,int count);
104 PCLAPI(cJSON *) cJSON_CreateFloatArray(float *numbers,int count);
105 PCLAPI(cJSON *) cJSON_CreateDoubleArray(double *numbers,int count);
106 PCLAPI(cJSON *) cJSON_CreateStringArray(const char **strings,int count);
107 
108 /* Append item to the specified array/object. */
109 PCLAPI(void) cJSON_AddItemToArray(cJSON *array, cJSON *item);
110 PCLAPI(void) cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item);
111 /* 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. */
112 PCLAPI(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
113 PCLAPI(void) cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item);
114 
115 /* Remove/Detach items from Arrays/Objects. */
116 PCLAPI(cJSON *) cJSON_DetachItemFromArray(cJSON *array,int which);
117 PCLAPI(void) cJSON_DeleteItemFromArray(cJSON *array,int which);
118 PCLAPI(cJSON *) cJSON_DetachItemFromObject(cJSON *object,const char *string);
119 PCLAPI(void) cJSON_DeleteItemFromObject(cJSON *object,const char *string);
120 
121 /* Update array items. */
122 PCLAPI(void) cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem);
123 PCLAPI(void) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
124 
125 #define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
126 #define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
127 #define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
128 #define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
129 #define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
130 
131 #ifdef __cplusplus
132 }
133 #endif
Defines all the PCL and non-PCL macros used.
#define PCLAPI(rettype)
Definition: pcl_macros.h:338
void(* free_fn)(void *ptr)
Definition: cJSON.h:62
Definition: cJSON.h:47
int valueint
Definition: cJSON.h:54
struct cJSON * child
Definition: cJSON.h:49
double valuedouble
Definition: cJSON.h:55
char * string
Definition: cJSON.h:57
int type
Definition: cJSON.h:51
char * valuestring
Definition: cJSON.h:53
struct cJSON * prev
Definition: cJSON.h:48
struct cJSON * next
Definition: cJSON.h:48