~ubuntu-branches/debian/stretch/opentyrian/stretch

« back to all changes in this revision

Viewing changes to src/cJSON.h

  • Committer: Package Import Robot
  • Author(s): Etienne Millon
  • Date: 2015-03-31 08:48:54 UTC
  • Revision ID: package-import@ubuntu.com-20150331084854-f5a4uoz7uv3vopk6
Tags: upstream-2.1.20130907+dfsg
ImportĀ upstreamĀ versionĀ 2.1.20130907+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (c) 2009 Dave Gamble
 
3
  Copyright (c) 2009 The OpenTyrian Development Team
 
4
 
 
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
 
6
  of this software and associated documentation files (the "Software"), to deal
 
7
  in the Software without restriction, including without limitation the rights
 
8
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
9
  copies of the Software, and to permit persons to whom the Software is
 
10
  furnished to do so, subject to the following conditions:
 
11
 
 
12
  The above copyright notice and this permission notice shall be included in
 
13
  all copies or substantial portions of the Software.
 
14
 
 
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
16
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
17
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
21
  THE SOFTWARE.
 
22
*/
 
23
 
 
24
#ifndef cJSON__h
 
25
#define cJSON__h
 
26
 
 
27
#ifdef __cplusplus
 
28
extern "C"
 
29
{
 
30
#endif
 
31
 
 
32
#include <stdbool.h>
 
33
#include <stdlib.h>
 
34
 
 
35
typedef enum
 
36
{
 
37
        cJSON_NULL,
 
38
        cJSON_False,
 
39
        cJSON_True,
 
40
        cJSON_Number,
 
41
        cJSON_String,
 
42
        cJSON_Array,
 
43
        cJSON_Object
 
44
}
 
45
cJSON_Type;
 
46
 
 
47
typedef struct cJSON
 
48
{
 
49
        cJSON_Type type;            // type of this item
 
50
        
 
51
        // next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem
 
52
        struct cJSON *next, *prev;  // sibling items in chain (parent item is array or object)
 
53
        struct cJSON *child;        // chain of child items (this item is array or object)
 
54
        
 
55
        char *string;               // identifying string of this item (parent item is object)
 
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
cJSON;
 
62
 
 
63
 
 
64
// Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished.
 
65
cJSON *cJSON_Parse(const char *value);
 
66
// Render a cJSON entity to text for transfer/storage. Free the char* when finished.
 
67
char *cJSON_Print(cJSON *item);
 
68
// Delete a cJSON entity and all subentities.
 
69
void cJSON_Delete(cJSON *c);
 
70
 
 
71
// Returns the number of items in an array (or object).
 
72
int cJSON_GetArraySize(cJSON *array);
 
73
// Retrieve item number "item" from array "array". Returns NULL if unsuccessful.
 
74
cJSON *cJSON_GetArrayItem(cJSON *array,int item);
 
75
// Get item "string" from object. Case insensitive.
 
76
cJSON *cJSON_GetObjectItem(cJSON *object,const char *string);
 
77
 
 
78
cJSON *cJSON_CreateOrGetObjectItem( cJSON *object, const char *string );
 
79
 
 
80
// These calls create a cJSON item of the appropriate type.
 
81
cJSON *cJSON_CreateNull( void );
 
82
cJSON *cJSON_CreateBoolean( bool );
 
83
cJSON *cJSON_CreateNumber( double );
 
84
cJSON *cJSON_CreateString( const char * );
 
85
cJSON *cJSON_CreateArray( void );
 
86
cJSON *cJSON_CreateObject( void );
 
87
 
 
88
void cJSON_ForceType( cJSON *, cJSON_Type );
 
89
 
 
90
void cJSON_SetBoolean( cJSON *, bool );
 
91
void cJSON_SetNumber( cJSON *, double );
 
92
void cJSON_SetString( cJSON *, const char * );
 
93
 
 
94
// These utilities create an Array of count items.
 
95
cJSON *cJSON_CreateIntArray(int *numbers,int count);
 
96
cJSON *cJSON_CreateFloatArray(float *numbers,int count);
 
97
cJSON *cJSON_CreateDoubleArray(double *numbers,int count);
 
98
cJSON *cJSON_CreateStringArray(const char **strings,int count);
 
99
 
 
100
// Append item to the specified array/object.
 
101
void cJSON_AddItemToArray(cJSON *array, cJSON *item);
 
102
void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item);
 
103
 
 
104
#define cJSON_AddNullToObject(object,name)      cJSON_AddItemToObject(object, name, cJSON_CreateNull())
 
105
#define cJSON_AddTrueToObject(object,name)      cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
 
106
#define cJSON_AddFalseToObject(object,name)             cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
 
107
#define cJSON_AddNumberToObject(object,name,n)  cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
 
108
#define cJSON_AddStringToObject(object,name,s)  cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
 
109
 
 
110
void cJSON_ClearArray( cJSON *array );
 
111
#define cJSON_ClearObject( object ) cJSON_ClearArray(object)
 
112
 
 
113
#ifdef __cplusplus
 
114
}
 
115
#endif
 
116
 
 
117
#endif