json_object.h
Go to the documentation of this file.
00001 /*
00002  * $Id: json_object.h,v 1.12 2006/01/30 23:07:57 mclark Exp $
00003  *
00004  * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
00005  * Michael Clark <michael@metaparadigm.com>
00006  *
00007  * This library is free software; you can redistribute it and/or modify
00008  * it under the terms of the MIT license. See COPYING for details.
00009  *
00010  */
00011 
00012 #ifndef _json_object_h_
00013 #define _json_object_h_
00014 
00015 #define JSON_OBJECT_DEF_HASH_ENTIRES 16
00016 
00017 #undef FALSE
00018 #define FALSE ((boolean)0)
00019 
00020 #undef TRUE
00021 #define TRUE ((boolean)1)
00022 
00023 extern const char *json_number_chars;
00024 extern const char *json_hex_chars;
00025 
00026 /* forward structure definitions */
00027 
00028 typedef int boolean;
00029 struct printbuf;
00030 struct lh_table;
00031 struct array_list;
00032 struct json_object;
00033 struct json_object_iter;
00034 
00035 /* supported object types */
00036 
00037 enum json_type {
00038   json_type_null,
00039   json_type_boolean,
00040   json_type_double,
00041   json_type_int,
00042   json_type_object,
00043   json_type_array,
00044   json_type_string
00045 };
00046 
00047 /* reference counting functions */
00048 
00049 
00050 
00051 
00056 extern struct json_object* json_object_get(struct json_object *obj);
00057 
00062 extern void json_object_put(struct json_object *obj);
00063 
00064 
00076 /*extern int json_object_is_type(struct json_object *obj, enum json_type type);*/
00077 extern int json_object_is_type(struct json_object *obj, int type);
00078 
00090 extern enum json_type json_object_get_type(struct json_object *obj);
00091 
00092 
00097 extern const char* json_object_to_json_string(struct json_object *obj);
00098 
00099 
00100 /* object type methods */
00101 
00105 extern struct json_object* json_object_new_object(void);
00106 
00111 extern struct lh_table* json_object_get_object(struct json_object *obj);
00112 
00123 extern void json_object_object_add(struct json_object* obj, const char *key,
00124                                    struct json_object *val);
00125 
00131 extern struct json_object* json_object_object_get(struct json_object* obj,
00132                                                   const char *key);
00133 
00141 extern void json_object_object_del(struct json_object* obj, const char *key);
00142 
00148 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
00149 # define json_object_object_foreach(obj,key,val) \
00150  char *key; struct json_object *val; \
00151  for(struct lh_entry *entry = json_object_get_object(obj)->head; ({ if(entry) { key = (char*)entry->k; val = (struct json_object*)entry->v; } ; entry; }); entry = entry->next )
00152 
00153 #else /* ANSI C or MSC */
00154 
00155 # define json_object_object_foreach(obj,key,val) \
00156  char *key; struct json_object *val; struct lh_entry *entry; \
00157  for(entry = json_object_get_object(obj)->head; (entry ? (key = (char*)entry->k, val = (struct json_object*)entry->v, entry) : 0); entry = entry->next)
00158 
00159 #endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) */
00160 
00165 #define json_object_object_foreachC(obj,iter) \
00166  for(iter.entry = json_object_get_object(obj)->head; (iter.entry ? (iter.key = (char*)iter.entry->k, iter.val = (struct json_object*)iter.entry->v, iter.entry) : 0); iter.entry = iter.entry->next)
00167 
00168 /* Array type methods */
00169 
00173 extern struct json_object* json_object_new_array(void);
00174 
00179 extern struct array_list* json_object_get_array(struct json_object *obj);
00180 
00185 extern int json_object_array_length(struct json_object *obj);
00186 
00196 extern int json_object_array_add(struct json_object *obj,
00197                                  struct json_object *val);
00198 
00214 extern int json_object_array_put_idx(struct json_object *obj, int idx,
00215                                      struct json_object *val);
00216 
00222 extern struct json_object* json_object_array_get_idx(struct json_object *obj,
00223                                                      int idx);
00224 
00225 /* boolean type methods */
00226 
00231 extern struct json_object* json_object_new_boolean(boolean b);
00232 
00244 extern boolean json_object_get_boolean(struct json_object *obj);
00245 
00246 
00247 /* int type methods */
00248 
00253 extern struct json_object* json_object_new_int(int i);
00254 
00264 extern int json_object_get_int(struct json_object *obj);
00265 
00266 
00267 /* double type methods */
00268 
00273 extern struct json_object* json_object_new_double(double d);
00274 
00284 extern double json_object_get_double(struct json_object *obj);
00285 
00286 
00287 /* string type methods */
00288 
00296 extern struct json_object* json_object_new_string(const char *s);
00297 
00298 extern struct json_object* json_object_new_string_len(const char *s, int len);
00299 
00311 extern char* json_object_get_string(struct json_object *obj);
00312 
00313 extern void json_set_float_format(const char*f);
00314 
00315 #endif


csm
Author(s): Andrea Censi
autogenerated on Fri May 17 2019 02:28:33