Browse Source

Add const qualifiers to several functions that don't modify the json_object.

tags/json-c-0.13-20171207
Eric Haszlakiewicz 9 years ago
parent
commit
537f8bcbdb
2 changed files with 31 additions and 31 deletions
  1. +15
    -15
      json_object.c
  2. +16
    -16
      json_object.h

+ 15
- 15
json_object.c View File

@@ -98,7 +98,7 @@ static void json_object_fini(void)
/* helper for accessing the optimized string data component in json_object /* helper for accessing the optimized string data component in json_object
*/ */
static const char * static const char *
get_string_component(struct json_object *jso)
get_string_component(const struct json_object *jso)
{ {
return (jso->o.c_string.len < LEN_DIRECT_STRING_DATA) ? return (jso->o.c_string.len < LEN_DIRECT_STRING_DATA) ?
jso->o.c_string.str.data : jso->o.c_string.str.ptr; jso->o.c_string.str.data : jso->o.c_string.str.ptr;
@@ -221,14 +221,14 @@ static struct json_object* json_object_new(enum json_type o_type)


/* type checking functions */ /* type checking functions */


int json_object_is_type(struct json_object *jso, enum json_type type)
int json_object_is_type(const struct json_object *jso, enum json_type type)
{ {
if (!jso) if (!jso)
return (type == json_type_null); return (type == json_type_null);
return (jso->o_type == type); return (jso->o_type == type);
} }


enum json_type json_object_get_type(struct json_object *jso)
enum json_type json_object_get_type(const struct json_object *jso)
{ {
if (!jso) if (!jso)
return json_type_null; return json_type_null;
@@ -406,7 +406,7 @@ struct json_object* json_object_new_object(void)
return jso; return jso;
} }


struct lh_table* json_object_get_object(struct json_object *jso)
struct lh_table* json_object_get_object(const struct json_object *jso)
{ {
if (!jso) if (!jso)
return NULL; return NULL;
@@ -470,19 +470,19 @@ int json_object_object_add(struct json_object* jso, const char *key,
} }




int json_object_object_length(struct json_object *jso)
int json_object_object_length(const struct json_object *jso)
{ {
return lh_table_length(jso->o.c_object); return lh_table_length(jso->o.c_object);
} }


struct json_object* json_object_object_get(struct json_object* jso, const char *key)
struct json_object* json_object_object_get(const struct json_object* jso, const char *key)
{ {
struct json_object *result = NULL; struct json_object *result = NULL;
json_object_object_get_ex(jso, key, &result); json_object_object_get_ex(jso, key, &result);
return result; return result;
} }


json_bool json_object_object_get_ex(struct json_object* jso, const char *key, struct json_object **value)
json_bool json_object_object_get_ex(const struct json_object* jso, const char *key, struct json_object **value)
{ {
if (value != NULL) if (value != NULL)
*value = NULL; *value = NULL;
@@ -530,7 +530,7 @@ struct json_object* json_object_new_boolean(json_bool b)
return jso; return jso;
} }


json_bool json_object_get_boolean(struct json_object *jso)
json_bool json_object_get_boolean(const struct json_object *jso)
{ {
if (!jso) if (!jso)
return FALSE; return FALSE;
@@ -570,7 +570,7 @@ struct json_object* json_object_new_int(int32_t i)
return jso; return jso;
} }


int32_t json_object_get_int(struct json_object *jso)
int32_t json_object_get_int(const struct json_object *jso)
{ {
int64_t cint64; int64_t cint64;
enum json_type o_type; enum json_type o_type;
@@ -619,7 +619,7 @@ struct json_object* json_object_new_int64(int64_t i)
return jso; return jso;
} }


int64_t json_object_get_int64(struct json_object *jso)
int64_t json_object_get_int64(const struct json_object *jso)
{ {
int64_t cint; int64_t cint;


@@ -726,7 +726,7 @@ void json_object_free_userdata(struct json_object *jso, void *userdata)
free(userdata); free(userdata);
} }


double json_object_get_double(struct json_object *jso)
double json_object_get_double(const struct json_object *jso)
{ {
double cdouble; double cdouble;
char *errPtr = NULL; char *errPtr = NULL;
@@ -857,7 +857,7 @@ const char* json_object_get_string(struct json_object *jso)
} }
} }


int json_object_get_string_len(struct json_object *jso)
int json_object_get_string_len(const struct json_object *jso)
{ {
if (!jso) if (!jso)
return 0; return 0;
@@ -937,7 +937,7 @@ struct json_object* json_object_new_array(void)
return jso; return jso;
} }


struct array_list* json_object_get_array(struct json_object *jso)
struct array_list* json_object_get_array(const struct json_object *jso)
{ {
if (!jso) if (!jso)
return NULL; return NULL;
@@ -970,7 +970,7 @@ struct json_object* json_object_array_bsearch(
return *result; return *result;
} }


int json_object_array_length(struct json_object *jso)
int json_object_array_length(const struct json_object *jso)
{ {
return array_list_length(jso->o.c_array); return array_list_length(jso->o.c_array);
} }
@@ -986,7 +986,7 @@ int json_object_array_put_idx(struct json_object *jso, int idx,
return array_list_put_idx(jso->o.c_array, idx, val); return array_list_put_idx(jso->o.c_array, idx, val);
} }


struct json_object* json_object_array_get_idx(struct json_object *jso,
struct json_object* json_object_array_get_idx(const struct json_object *jso,
int idx) int idx)
{ {
return (struct json_object*)array_list_get_idx(jso->o.c_array, idx); return (struct json_object*)array_list_get_idx(jso->o.c_array, idx);


+ 16
- 16
json_object.h View File

@@ -183,7 +183,7 @@ int json_object_put(struct json_object *obj);
json_type_array, json_type_array,
json_type_string json_type_string
*/ */
extern int json_object_is_type(struct json_object *obj, enum json_type type);
extern int json_object_is_type(const struct json_object *obj, enum json_type type);


/** /**
* Get the type of the json_object. See also json_type_to_name() to turn this * Get the type of the json_object. See also json_type_to_name() to turn this
@@ -199,7 +199,7 @@ extern int json_object_is_type(struct json_object *obj, enum json_type type);
json_type_array, json_type_array,
json_type_string json_type_string
*/ */
extern enum json_type json_object_get_type(struct json_object *obj);
extern enum json_type json_object_get_type(const struct json_object *obj);




/** Stringify object to json format. /** Stringify object to json format.
@@ -292,12 +292,12 @@ extern struct json_object* json_object_new_object(void);
* @param obj the json_object instance * @param obj the json_object instance
* @returns a linkhash * @returns a linkhash
*/ */
extern struct lh_table* json_object_get_object(struct json_object *obj);
extern struct lh_table* json_object_get_object(const struct json_object *obj);


/** Get the size of an object in terms of the number of fields it has. /** Get the size of an object in terms of the number of fields it has.
* @param obj the json_object whose length to return * @param obj the json_object whose length to return
*/ */
extern int json_object_object_length(struct json_object* obj);
extern int json_object_object_length(const struct json_object* obj);


/** Add an object field to a json_object of type json_type_object /** Add an object field to a json_object of type json_type_object
* *
@@ -354,7 +354,7 @@ extern void json_object_object_add_ex(struct json_object* obj, const char *key,
* @returns the json_object associated with the given field name * @returns the json_object associated with the given field name
* @deprecated Please use json_object_object_get_ex * @deprecated Please use json_object_object_get_ex
*/ */
THIS_FUNCTION_IS_DEPRECATED(extern struct json_object* json_object_object_get(struct json_object* obj,
THIS_FUNCTION_IS_DEPRECATED(extern struct json_object* json_object_object_get(const struct json_object* obj,
const char *key)); const char *key));


/** Get the json_object associated with a given object field. /** Get the json_object associated with a given object field.
@@ -375,9 +375,9 @@ THIS_FUNCTION_IS_DEPRECATED(extern struct json_object* json_object_object_get(st
* It is safe to pass a NULL value. * It is safe to pass a NULL value.
* @returns whether or not the key exists * @returns whether or not the key exists
*/ */
extern json_bool json_object_object_get_ex(struct json_object* obj,
const char *key,
struct json_object **value);
extern json_bool json_object_object_get_ex(const struct json_object* obj,
const char *key,
struct json_object **value);


/** Delete the given json_object field /** Delete the given json_object field
* *
@@ -451,13 +451,13 @@ extern struct json_object* json_object_new_array(void);
* @param obj the json_object instance * @param obj the json_object instance
* @returns an arraylist * @returns an arraylist
*/ */
extern struct array_list* json_object_get_array(struct json_object *obj);
extern struct array_list* json_object_get_array(const struct json_object *obj);


/** Get the length of a json_object of type json_type_array /** Get the length of a json_object of type json_type_array
* @param obj the json_object instance * @param obj the json_object instance
* @returns an int * @returns an int
*/ */
extern int json_object_array_length(struct json_object *obj);
extern int json_object_array_length(const struct json_object *obj);


/** Sorts the elements of jso of type json_type_array /** Sorts the elements of jso of type json_type_array
* *
@@ -523,7 +523,7 @@ extern int json_object_array_put_idx(struct json_object *obj, int idx,
* @param idx the index to get the element at * @param idx the index to get the element at
* @returns the json_object at the specified index (or NULL) * @returns the json_object at the specified index (or NULL)
*/ */
extern struct json_object* json_object_array_get_idx(struct json_object *obj,
extern struct json_object* json_object_array_get_idx(const struct json_object *obj,
int idx); int idx);


/* json_bool type methods */ /* json_bool type methods */
@@ -545,7 +545,7 @@ extern struct json_object* json_object_new_boolean(json_bool b);
* @param obj the json_object instance * @param obj the json_object instance
* @returns a json_bool * @returns a json_bool
*/ */
extern json_bool json_object_get_boolean(struct json_object *obj);
extern json_bool json_object_get_boolean(const struct json_object *obj);




/* int type methods */ /* int type methods */
@@ -580,7 +580,7 @@ extern struct json_object* json_object_new_int64(int64_t i);
* @param obj the json_object instance * @param obj the json_object instance
* @returns an int * @returns an int
*/ */
extern int32_t json_object_get_int(struct json_object *obj);
extern int32_t json_object_get_int(const struct json_object *obj);


/** Get the int value of a json_object /** Get the int value of a json_object
* *
@@ -595,7 +595,7 @@ extern int32_t json_object_get_int(struct json_object *obj);
* @param obj the json_object instance * @param obj the json_object instance
* @returns an int64 * @returns an int64
*/ */
extern int64_t json_object_get_int64(struct json_object *obj);
extern int64_t json_object_get_int64(const struct json_object *obj);




/* double type methods */ /* double type methods */
@@ -652,7 +652,7 @@ extern struct json_object* json_object_new_double_s(double d, const char *ds);
* @param obj the json_object instance * @param obj the json_object instance
* @returns a double floating point number * @returns a double floating point number
*/ */
extern double json_object_get_double(struct json_object *obj);
extern double json_object_get_double(const struct json_object *obj);




/* string type methods */ /* string type methods */
@@ -689,7 +689,7 @@ extern const char* json_object_get_string(struct json_object *obj);
* @param obj the json_object instance * @param obj the json_object instance
* @returns int * @returns int
*/ */
extern int json_object_get_string_len(struct json_object *obj);
extern int json_object_get_string_len(const struct json_object *obj);


#ifdef __cplusplus #ifdef __cplusplus
} }


Loading…
Cancel
Save