cJSON.h
Go to the documentation of this file.
00001 /*
00002   Copyright (c) 2009 Dave Gamble
00003  
00004   Permission is hereby granted, free of charge, to any person obtaining a copy
00005   of this software and associated documentation files (the "Software"), to deal
00006   in the Software without restriction, including without limitation the rights
00007   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008   copies of the Software, and to permit persons to whom the Software is
00009   furnished to do so, subject to the following conditions:
00010  
00011   The above copyright notice and this permission notice shall be included in
00012   all copies or substantial portions of the Software.
00013  
00014   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020   THE SOFTWARE.
00021 */
00022 
00023 #ifndef cJSON__h
00024 #define cJSON__h
00025 
00026 #include <pcl/pcl_macros.h>
00027 
00028 //make interop with c++ string easier
00029 #include <string>
00030 
00031 #ifdef __cplusplus
00032 extern "C"
00033 {
00034 #endif
00035 
00036 /* cJSON Types: */
00037 #define cJSON_False 0
00038 #define cJSON_True 1
00039 #define cJSON_NULL 2
00040 #define cJSON_Number 3
00041 #define cJSON_String 4
00042 #define cJSON_Array 5
00043 #define cJSON_Object 6
00044         
00045 #define cJSON_IsReference 256
00046 
00047 /* The cJSON structure: */
00048 typedef struct cJSON {
00049         struct cJSON *next,*prev;       /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
00050         struct cJSON *child;            /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
00051 
00052         int type;                                       /* The type of the item, as above. */
00053 
00054         char *valuestring;                      /* The item's string, if type==cJSON_String */
00055         int valueint;                           /* The item's number, if type==cJSON_Number */
00056         double valuedouble;                     /* The item's number, if type==cJSON_Number */
00057 
00058         char *string;                           /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
00059 } cJSON;
00060 
00061 typedef struct cJSON_Hooks {
00062       void *(*malloc_fn)(size_t sz);
00063       void (*free_fn)(void *ptr);
00064 } cJSON_Hooks;
00065 
00066 /* Supply malloc, realloc and free functions to cJSON */
00067 PCLAPI(void) cJSON_InitHooks(cJSON_Hooks* hooks);
00068 
00069 
00070 /* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
00071 PCLAPI(cJSON *) cJSON_Parse(const char *value);
00072 /* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */
00073 PCLAPI(char  *) cJSON_Print(cJSON *item);
00074 /* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */
00075 PCLAPI(char  *) cJSON_PrintUnformatted(cJSON *item);
00076 /* Delete a cJSON entity and all subentities. */
00077 PCLAPI(void)   cJSON_Delete(cJSON *c);
00078 /* Render a cJSON entity to text for transfer/storage. */
00079 PCLAPI(void) cJSON_PrintStr(cJSON *item, std::string& s);
00080 /* Render a cJSON entity to text for transfer/storage without any formatting. */
00081 PCLAPI(void) cJSON_PrintUnformattedStr(cJSON *item, std::string& s);
00082 
00083 /* Returns the number of items in an array (or object). */
00084 PCLAPI(int)       cJSON_GetArraySize(cJSON *array);
00085 /* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
00086 PCLAPI(cJSON *) cJSON_GetArrayItem(cJSON *array,int item);
00087 /* Get item "string" from object. Case insensitive. */
00088 PCLAPI(cJSON *) cJSON_GetObjectItem(cJSON *object,const char *string);
00089 
00090 /* 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. */
00091 PCLAPI(const char *) cJSON_GetErrorPtr();
00092         
00093 /* These calls create a cJSON item of the appropriate type. */
00094 PCLAPI(cJSON *) cJSON_CreateNull();
00095 PCLAPI(cJSON *) cJSON_CreateTrue();
00096 PCLAPI(cJSON *) cJSON_CreateFalse();
00097 PCLAPI(cJSON *) cJSON_CreateBool(int b);
00098 PCLAPI(cJSON *) cJSON_CreateNumber(double num);
00099 PCLAPI(cJSON *) cJSON_CreateString(const char *string);
00100 PCLAPI(cJSON *) cJSON_CreateArray();
00101 PCLAPI(cJSON *) cJSON_CreateObject();
00102 
00103 /* These utilities create an Array of count items. */
00104 PCLAPI(cJSON *) cJSON_CreateIntArray(int *numbers,int count);
00105 PCLAPI(cJSON *) cJSON_CreateFloatArray(float *numbers,int count);
00106 PCLAPI(cJSON *) cJSON_CreateDoubleArray(double *numbers,int count);
00107 PCLAPI(cJSON *) cJSON_CreateStringArray(const char **strings,int count);
00108 
00109 /* Append item to the specified array/object. */
00110 PCLAPI(void) cJSON_AddItemToArray(cJSON *array, cJSON *item);
00111 PCLAPI(void) cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item);
00112 /* 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. */
00113 PCLAPI(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
00114 PCLAPI(void) cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item);
00115 
00116 /* Remove/Detatch items from Arrays/Objects. */
00117 PCLAPI(cJSON *) cJSON_DetachItemFromArray(cJSON *array,int which);
00118 PCLAPI(void)    cJSON_DeleteItemFromArray(cJSON *array,int which);
00119 PCLAPI(cJSON *) cJSON_DetachItemFromObject(cJSON *object,const char *string);
00120 PCLAPI(void)    cJSON_DeleteItemFromObject(cJSON *object,const char *string);
00121         
00122 /* Update array items. */
00123 PCLAPI(void) cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem);
00124 PCLAPI(void) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
00125 
00126 #define cJSON_AddNullToObject(object,name)      cJSON_AddItemToObject(object, name, cJSON_CreateNull())
00127 #define cJSON_AddTrueToObject(object,name)      cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
00128 #define cJSON_AddFalseToObject(object,name)             cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
00129 #define cJSON_AddNumberToObject(object,name,n)  cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
00130 #define cJSON_AddStringToObject(object,name,s)  cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
00131 
00132 #ifdef __cplusplus
00133 }
00134 #endif
00135 
00136 #endif


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:22:36