2020-01-17 22:48:42 +00:00
|
|
|
// Copyright 2019-2020, Collabora, Ltd.
|
2019-11-08 11:25:36 +00:00
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief Tiny JSON wrapper around cJSON header.
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
2020-01-17 22:48:42 +00:00
|
|
|
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
|
2019-11-08 11:25:36 +00:00
|
|
|
* @ingroup aux_util
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "xrt/xrt_compiler.h"
|
2020-01-27 06:48:30 +00:00
|
|
|
#include "xrt/xrt_defines.h"
|
2019-11-08 11:25:36 +00:00
|
|
|
|
|
|
|
#include "cjson/cJSON.h"
|
2020-01-17 22:48:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif // __cplusplus
|
|
|
|
|
2020-04-23 18:01:05 +00:00
|
|
|
/*!
|
|
|
|
* @brief Get a JSON object by string from a JSON object.
|
|
|
|
*
|
|
|
|
* @return The JSON object with the given name if successful, NULL if not.
|
|
|
|
*/
|
|
|
|
const cJSON *
|
|
|
|
u_json_get(const cJSON *json, const char *f);
|
2020-01-27 06:48:30 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Parse a string from a JSON object into a char array.
|
|
|
|
*
|
|
|
|
* @return true if successful, false if string does not fit in
|
|
|
|
* array or any other error.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
u_json_get_string_into_array(const cJSON *json, char *out, size_t max_size);
|
|
|
|
|
2020-04-06 10:17:50 +00:00
|
|
|
/*!
|
|
|
|
* @brief Parse an bool from a JSON object.
|
|
|
|
*
|
|
|
|
* @return true if successful, false if not.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
u_json_get_bool(const cJSON *json, bool *out_bool);
|
|
|
|
|
2020-01-27 06:48:30 +00:00
|
|
|
/*!
|
|
|
|
* @brief Parse an int from a JSON object.
|
|
|
|
*
|
|
|
|
* @return true if successful, false if not.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
u_json_get_int(const cJSON *json, int *out_int);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Parse a float from a JSON object.
|
|
|
|
*
|
|
|
|
* @return true if successful, false if not.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
u_json_get_float(const cJSON *json, float *out_float);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Parse a double from a JSON object.
|
|
|
|
*
|
|
|
|
* @return true if successful, false if not.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
u_json_get_double(const cJSON *json, double *out_double);
|
|
|
|
|
|
|
|
/*!
|
2021-08-13 19:53:34 +00:00
|
|
|
* @brief Parse an xrt_vec3 from a JSON object.
|
2020-01-27 06:48:30 +00:00
|
|
|
*
|
|
|
|
* @return true if successful, false if not.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
u_json_get_vec3(const cJSON *json, struct xrt_vec3 *out_vec3);
|
|
|
|
|
2020-06-26 11:03:19 +00:00
|
|
|
/*!
|
2021-08-13 19:53:34 +00:00
|
|
|
* @brief Parse an xrt_vec3 from a JSON array.
|
2020-06-26 11:03:19 +00:00
|
|
|
*
|
|
|
|
* @return true if successful, false if not.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
u_json_get_vec3_array(const cJSON *json, struct xrt_vec3 *out_vec3);
|
|
|
|
|
2021-08-13 19:53:34 +00:00
|
|
|
/*!
|
|
|
|
* @brief Parse an xrt_vec3_f64 from a JSON array.
|
|
|
|
*
|
|
|
|
* @return true if successful, false if not.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
u_json_get_vec3_f64_array(const cJSON *json, struct xrt_vec3_f64 *out_vec3);
|
|
|
|
|
2020-01-27 06:48:30 +00:00
|
|
|
/*!
|
|
|
|
* @brief Parse a quaternion from a JSON object.
|
|
|
|
*
|
|
|
|
* @return true if successful, false if not.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
u_json_get_quat(const cJSON *json, struct xrt_quat *out_quat);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Parse up to max_size floats from a JSON array.
|
|
|
|
*
|
|
|
|
* @return the number of elements set.
|
|
|
|
*/
|
|
|
|
size_t
|
2021-01-14 14:13:48 +00:00
|
|
|
u_json_get_float_array(const cJSON *json_array, float *out_array, size_t max_size);
|
2020-01-27 06:48:30 +00:00
|
|
|
|
2020-01-17 22:48:42 +00:00
|
|
|
/*!
|
|
|
|
* @brief Parse up to max_size doubles from a JSON array.
|
|
|
|
*
|
|
|
|
* @return the number of elements set.
|
|
|
|
*/
|
|
|
|
size_t
|
2021-01-14 14:13:48 +00:00
|
|
|
u_json_get_double_array(const cJSON *json_array, double *out_array, size_t max_size);
|
2020-01-27 06:48:30 +00:00
|
|
|
|
2020-07-02 12:16:36 +00:00
|
|
|
/*!
|
|
|
|
* @brief Parse a matrix_3x3 from a JSON object.
|
|
|
|
*
|
|
|
|
* @return true if successful, false if not.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
u_json_get_matrix_3x3(const cJSON *json, struct xrt_matrix_3x3 *out_matrix);
|
|
|
|
|
2020-01-27 06:48:30 +00:00
|
|
|
|
2020-01-17 22:48:42 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif // __cplusplus
|