-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjson.h
115 lines (82 loc) · 5.06 KB
/
json.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* ÕâÊÇANSIÎĵµ */
#ifndef __LIB__JSON__H__
#define __LIB__JSON__H__
#include "cJSON.h"
#ifdef __cplusplus
class Lib_Json
{
public:
~Lib_Json(void);
bool loadChildObject(const char *name, bool fromChild = true);
bool loadChildArray(const char *name, bool fromChild = true);
bool loadChildObjectFromChildArrayByIndex(const int index, bool fromChild = true);
void releaseChild(void);
bool putValueString(const char *name, const char *buffer, bool fromChild = true);
bool getValueBoolean(const char *name, bool fromChild = true);
bool putValueNumber(const char *name, int value, bool fromChild = true);
bool putValueNumber(const char *name, unsigned int value, bool fromChild = true);
bool putValueNumber(const char *name, long long int value, bool fromChild = true);
bool putValueNumber(const char *name, unsigned long long int value, bool fromChild = true);
bool putValueNumber(const char *name, double value, bool fromChild = true);
bool getValueString(const char *name, char *buffer, unsigned int size, bool fromChild = true);
bool getValueNumber(const char *name, short *value, bool fromChild = true);
bool getValueNumber(const char *name, unsigned short *value, bool fromChild = true);
bool getValueNumber(const char *name, int *value, bool fromChild = true);
bool getValueNumber(const char *name, unsigned int *value, bool fromChild = true);
bool getValueNumber(const char *name, long long int *value, bool fromChild = true);
bool getValueNumber(const char *name, unsigned long long int *value, bool fromChild = true);
bool getValueNumber(const char *name, double *value, bool fromChild = true);
bool getValueArray(const char *name, cJSON **value, bool fromChild = true);
bool getValueObject(const char *name, cJSON **value, bool fromChild = true, bool dup = false);
bool getValueNumberFromArray(int *value, unsigned int n, bool fromChild = true);
bool getValueNumberFromArray(unsigned int *value, unsigned int n, bool fromChild = true);
bool getValueNumberFromArray(long long int *value, unsigned int n, bool fromChild = true);
bool getValueNumberFromArray(unsigned long long int *value, unsigned int n, bool fromChild = true);
bool getValueNumberFromArray(double *value, unsigned int n, bool fromChild = true);
bool getValueStringFromArray(char **value, unsigned int size, unsigned int n, bool fromChild = true);
void dumpObject(bool fromChild = true);
void dumpArray(void);
int getLenght(void);
bool saveFile(const char *path, bool useFormat = true);
cJSON *cSJONDup(void);
// *** for static function *********************************************************************
static bool putValueString(cJSON *root, const char *name, const char *buffer);
static bool putValueNumber(cJSON *root, const char *name, int value);
static bool putValueNumber(cJSON *root, const char *name, unsigned int value);
static bool putValueNumber(cJSON *root, const char *name, long long int value);
static bool putValueNumber(cJSON *root, const char *name, unsigned long long int value);
static bool putValueNumber(cJSON *root, const char *name, double value);
static bool getValueString(cJSON *root, const char *name, char *buffer, unsigned int size);
static bool getValueBoolean(cJSON *root, const char *name);
static bool getValueNumber(cJSON *root, const char *name, short *value);
static bool getValueNumber(cJSON *root, const char *name, unsigned short *value);
static bool getValueNumber(cJSON *root, const char *name, int *value);
static bool getValueNumber(cJSON *root, const char *name, unsigned int *value);
static bool getValueNumber(cJSON *root, const char *name, long long int *value);
static bool getValueNumber(cJSON *root, const char *name, unsigned long long int *value);
static bool getValueNumber(cJSON *root, const char *name, double *value);
static bool getValueArray(cJSON *root, const char *name, cJSON **value);
static bool getValueObject(cJSON *root, const char *name, cJSON **value, bool dup = false);
static bool getValueNumberFromArray(cJSON *root, int *value, unsigned int n);
static bool getValueNumberFromArray(cJSON *root, unsigned int *value, unsigned int n);
static bool getValueNumberFromArray(cJSON *root, long long int *value, unsigned int n);
static bool getValueNumberFromArray(cJSON *root, unsigned long long int *value, unsigned int n);
static bool getValueNumberFromArray(cJSON *root, double *value, unsigned int n);
static bool getValueStringFromArray(cJSON *root, char **value, unsigned int size, unsigned int n);
static void dumpAll(cJSON *root, bool useFormat = true);
static int getLenght(cJSON *root);
static cJSON *loadFile(const char *path);
static bool saveFile(cJSON *root, const char *path, bool useFormat = true);
static void freeAll(cJSON **root);
static Lib_Json *getObject(void *root);
static Lib_Json *getObject(cJSON *root);
static Lib_Json *getObject(const char *buffer, int size);
static Lib_Json *getObject(const char *path);
private:
Lib_Json(void);
cJSON *root;
cJSON *child;
cJSON *array;
};
#endif
#endif