ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
TMBOY
Date:
Tue Jul 18 16:54:45 2017 +0800
Revision:
47:9e361da97763
?

Who changed what in which revision?

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