#ifndef __JSON_H__
#define __JSON_H__ 1
#endif
#define True 1
#define False 0
#define BASEDATA_MALLOC_FAILD -1111
#define STRING_LEN_ERR -1112
#define BASE_TYPE_MAX 4
typedef enum JSON_TYPE_
{
JSON_NULL = 1,
JSON_BOOL = 2,
JSON_INT = 3,
JSON_FLOAT = 4,
JSON_STRING = 5,
JSON_ARRAY = 6,
JSON_OBJECT = 7,
}JSON_TYPE;
typedef short Jbool;
typedef long Jnumber;
typedef double Jfloat;
typedef char* Jstring;
typedef union BaseValue_{
Jnumber intVal;
Jfloat doubleVal;
Jstring strVal;
Jbool boolVal;
}BaseValue;
typedef struct RefValue_ Refvalue;
typedef struct RefValue_{
BaseValue baseVal;
Jbool isRef;
Jnumber refCount;
}Refvalue;
typedef struct JsonValue_ JsonValue;
struct JsonValue_{
JSON_TYPE jsonType;
Refvalue *refValue;
Jstring key;
JsonValue *child;
JsonValue *next;
Refvalue *global_head[BASE_TYPE_MAX];
};
typedef struct Json_{
Jnumber objCount;
Jnumber totalCount;
JsonValue *head;
JsonValue *tail;
Refvalue *global_head[BASE_TYPE_MAX];
int (*match)(const JsonValue *key1,const JsonValue *key2);
void (*create)(void *data);
void (*destroy)(void *data);
}Json;
JsonValue* jcreate(short create_data);
void jdestroy(JsonValue* value);
void json_init(Json *json,void (*create)(void *data),
void (*destroy)(void *data));
int json_match(const JsonValue *key1,const JsonValue *key2);
JsonValue* jcreate_null();
JsonValue* jcreate_bool(Jbool val);
JsonValue* jcreate_int(Jnumber val);
JsonValue* jcreate_float(Jfloat val);
JsonValue* jcreate_string(const Jstring);
int jcreate_array();
int jarray_insert(JsonValue *jarray, JsonValue *jvalue1,const JsonValue *jvalue2);
int jarray_rm(JsonValue *jarray,const JsonValue *jvalue1,const JsonValue **jvalue2);
int print_jarray(JsonValue *jarray);
int jcreate_object();
int json_append(Json *json,JsonValue *pj,JsonValue *jvalue);
int json_remove(Json *json,JsonValue *pj,JsonValue **jvalue);
int json_destroy(Json *json);
char* parser_to_str(Json *json);
Json* parser_to_json(char *str);
#define jbase_value(jval) ((jval)->refValue)->baseVal
#define jbase_is_ref(jval) ((jval)->refValue)->isRef
#define jbase_is_refcount(jval) ((jval)->refValue)->refCount
#define jbase_bool(jval) (((jval)->refValue)->baseVal).boolVal
#define jbase_number(jval) (((jval)->refValue)->baseVal).intVal
#define jbase_double(jval) (((jval)->refValue)->baseVal).doubleVal
#define jbase_string(jval) (((jval)->refValue)->baseVal).strVal
#define json_count(json) ((json)->totalCount)
#define json_obj_count(json) ((json)->objCount)