mcl_json_util.h
Go to the documentation of this file.
1 /*!**********************************************************************
2 *
3 * @copyright Copyright (C) 2017 Siemens Aktiengesellschaft.\n
4 * All rights reserved.
5 *
6 *************************************************************************
7 *
8 * @file mcl_json_util.h
9 * @date Feb 2, 2017
10 * @brief Json utility module interface header file.
11 *
12 * This module is used for json handling like json parsing and json generating.
13 *
14 ************************************************************************/
15 
16 #ifndef MCL_JSON_UTIL_H_
17 #define MCL_JSON_UTIL_H_
18 
19 #include "mcl/mcl_common.h"
20 
21 #ifdef __cplusplus
22 extern "C"
23 {
24 #endif
25 
29  typedef struct mcl_json_t mcl_json_t;
30 
34  typedef enum E_MCL_JSON_TYPE
35  {
39 
52  extern MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_initialize(E_MCL_JSON_TYPE json_type, mcl_json_t **root);
53 
68  extern MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_start_array(mcl_json_t *root, const char *array_name, mcl_json_t **json_array);
69 
84 
97 
112  extern MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_start_object(mcl_json_t *root, const char *object_name, mcl_json_t **json_object);
113 
131  extern MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_string(mcl_json_t *root, const char *object_name, const char *object_value);
132 
149  extern MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_uint(mcl_json_t *root, const char *object_name, const mcl_size_t number);
150 
166  extern MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_float(mcl_json_t *root, const char *object_name, const float number);
167 
182  extern MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_double(mcl_json_t *root, const char *object_name, const double number);
183 
198  extern MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_bool(mcl_json_t *root, const char *object_name, const mcl_bool_t bool_value);
199 
213  extern MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_null(mcl_json_t *root, const char *object_name);
214 
228  extern MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_object(mcl_json_t *root, const char *object_name, mcl_json_t *object);
229 
242 
257  extern MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_object_item(mcl_json_t *json_parent, const char *child_name, mcl_json_t **json_child);
258 
271 
284 
296  extern MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_double_value(mcl_json_t *json, double *double_value);
297 
310 
323  extern MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_string(mcl_json_t *json_item, char **string_value);
324 
337  extern MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_to_string(mcl_json_t *root, char **json_string);
338 
353  extern MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_parse(const char *json_string, mcl_json_t **root);
354 
362  extern MCL_EXPORT void mcl_json_util_finish_array(mcl_json_t **json_array);
363 
371  extern MCL_EXPORT void mcl_json_util_finish_object(mcl_json_t **json_object);
372 
380  extern MCL_EXPORT void mcl_json_util_destroy(mcl_json_t **root);
381 
382 #ifdef __cplusplus
383 }
384 #endif
385 
386 #endif //MCL_JSON_UTIL_H_
struct mcl_json_t mcl_json_t
This struct is used for json handling.
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_bool_value(mcl_json_t *json, mcl_bool_t *bool_value)
This function gets the boolean value of a given json object.
Definition: json_util.c:660
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_object_item(mcl_json_t *json_parent, const char *child_name, mcl_json_t **json_child)
This function gives the value of json_child object, when the child_name in json_parent object is give...
Definition: json_util.c:549
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_item_to_array(mcl_json_t *root, mcl_json_t *object)
This function adds object to root array.
Definition: json_util.c:527
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_to_string(mcl_json_t *root, char **json_string)
This function gives the string of root in json format.
Definition: json_util.c:722
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_start_array(mcl_json_t *root, const char *array_name, mcl_json_t **json_array)
This function creates an array in root.
Definition: json_util.c:84
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_uint(mcl_json_t *root, const char *object_name, const mcl_size_t number)
This function adds integer number to root which can be object or array.
Definition: json_util.c:271
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_bool(mcl_json_t *root, const char *object_name, const mcl_bool_t bool_value)
This function adds bool_value to root which can be object or array.
Definition: json_util.c:392
#define MCL_EXPORT
Common module interface header file.
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_initialize(E_MCL_JSON_TYPE json_type, mcl_json_t **root)
This function initializes the given root json.
Definition: json_util.c:39
Json object.
Definition: mcl_json_util.h:37
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_double_value(mcl_json_t *json, double *double_value)
This function gets the double value of a given json object.
Definition: json_util.c:638
MCL_EXPORT void mcl_json_util_destroy(mcl_json_t **root)
This function destroys root.
Definition: json_util.c:854
Json array.
Definition: mcl_json_util.h:36
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_array_size(mcl_json_t *array, mcl_size_t *size)
This function returns the size of array.
Definition: json_util.c:160
MCL_EXPORT void mcl_json_util_finish_object(mcl_json_t **json_object)
This function destroys json_object data struct. But the object still exists in root json object...
Definition: json_util.c:836
E_MCL_ERROR_CODE
MCL Error code definitions. Every function returning an error code uses this enum values...
Definition: mcl_common.h:137
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_object(mcl_json_t *root, const char *object_name, mcl_json_t *object)
This function adds object to root.
Definition: json_util.c:488
E_MCL_JSON_TYPE
Json type definitions.
Definition: mcl_json_util.h:34
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_array_item(mcl_json_t *array, int index, mcl_json_t **item)
This function gets the item at given index from array.
Definition: json_util.c:126
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_double(mcl_json_t *root, const char *object_name, const double number)
This function adds double number to root which can be object or array.
Definition: json_util.c:344
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_string(mcl_json_t *json_item, char **string_value)
This function gets the string value of a given json object.
Definition: json_util.c:689
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_string(mcl_json_t *root, const char *object_name, const char *object_value)
This function adds string to root which can be object or array.
Definition: json_util.c:222
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_number_value(mcl_json_t *json, mcl_int32_t *number_value)
This function gets the number value of a given json object.
Definition: json_util.c:616
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_parse(const char *json_string, mcl_json_t **root)
This function parses the given string to the given json object.
Definition: json_util.c:748
size_t mcl_size_t
Definition: mcl_common.h:38
MCL_EXPORT void mcl_json_util_finish_array(mcl_json_t **json_array)
This function destroys json_array data struct. But the array still exists in root json object...
Definition: json_util.c:818
mcl_uint8_t mcl_bool_t
Definition: mcl_common.h:47
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_has_child(mcl_json_t *root, mcl_bool_t *result)
This function checks whether root object has child object or not.
Definition: json_util.c:587
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_float(mcl_json_t *root, const char *object_name, const float number)
This function adds floating number to root.
Definition: json_util.c:319
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_null(mcl_json_t *root, const char *object_name)
This function adds null to root which can be object or array.
Definition: json_util.c:440
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_start_object(mcl_json_t *root, const char *object_name, mcl_json_t **json_object)
This function creates an object in root.
Definition: json_util.c:182
int32_t mcl_int32_t
Definition: mcl_common.h:41