Monado OpenXR Runtime
u_json.h
Go to the documentation of this file.
1 // Copyright 2019-2020, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Tiny JSON wrapper around cJSON header.
6  * @author Jakob Bornecrantz <jakob@collabora.com>
7  * @author Ryan Pavlik <ryan.pavlik@collabora.com>
8  * @ingroup aux_util
9  */
10 
11 #pragma once
12 
13 #include "xrt/xrt_compiler.h"
14 #include "xrt/xrt_defines.h"
15 
16 #include "cjson/cJSON.h"
17 
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif // __cplusplus
22 
23 
24 /*!
25  * @brief Parse a string from a JSON object into a char array.
26  *
27  * @return true if successful, false if string does not fit in
28  * array or any other error.
29  */
30 bool
31 u_json_get_string_into_array(const cJSON *json, char *out, size_t max_size);
32 
33 /*!
34  * @brief Parse an int from a JSON object.
35  *
36  * @return true if successful, false if not.
37  */
38 bool
39 u_json_get_int(const cJSON *json, int *out_int);
40 
41 /*!
42  * @brief Parse a float from a JSON object.
43  *
44  * @return true if successful, false if not.
45  */
46 bool
47 u_json_get_float(const cJSON *json, float *out_float);
48 
49 /*!
50  * @brief Parse a double from a JSON object.
51  *
52  * @return true if successful, false if not.
53  */
54 bool
55 u_json_get_double(const cJSON *json, double *out_double);
56 
57 /*!
58  * @brief Parse a vec3 from a JSON object.
59  *
60  * @return true if successful, false if not.
61  */
62 bool
63 u_json_get_vec3(const cJSON *json, struct xrt_vec3 *out_vec3);
64 
65 /*!
66  * @brief Parse a quaternion from a JSON object.
67  *
68  * @return true if successful, false if not.
69  */
70 bool
71 u_json_get_quat(const cJSON *json, struct xrt_quat *out_quat);
72 
73 /*!
74  * @brief Parse up to max_size floats from a JSON array.
75  *
76  * @return the number of elements set.
77  */
78 size_t
79 u_json_get_float_array(const cJSON *json_array,
80  float *out_array,
81  size_t max_size);
82 
83 /*!
84  * @brief Parse up to max_size doubles from a JSON array.
85  *
86  * @return the number of elements set.
87  */
88 size_t
89 u_json_get_double_array(const cJSON *json_array,
90  double *out_array,
91  size_t max_size);
92 
93 
94 #ifdef __cplusplus
95 } // extern "C"
96 #endif // __cplusplus
size_t u_json_get_float_array(const cJSON *json_array, float *out_array, size_t max_size)
Parse up to max_size floats from a JSON array.
Definition: u_json.c:155
A 3 element vector with single floats.
Definition: xrt_defines.h:131
bool u_json_get_quat(const cJSON *json, struct xrt_quat *out_quat)
Parse a quaternion from a JSON object.
Definition: u_json.c:124
bool u_json_get_float(const cJSON *json, float *out_float)
Parse a float from a JSON object.
Definition: u_json.c:82
A quaternion with single floats.
Definition: xrt_defines.h:97
Common defines and enums for XRT.
bool u_json_get_int(const cJSON *json, int *out_int)
Parse an int from a JSON object.
Definition: u_json.c:50
size_t u_json_get_double_array(const cJSON *json_array, double *out_array, size_t max_size)
Parse up to max_size doubles from a JSON array.
Definition: u_json.c:190
bool u_json_get_vec3(const cJSON *json, struct xrt_vec3 *out_vec3)
Parse a vec3 from a JSON object.
Definition: u_json.c:96
bool u_json_get_string_into_array(const cJSON *json, char *out, size_t max_size)
Parse a string from a JSON object into a char array.
Definition: u_json.c:28
Header holding common defines.
bool u_json_get_double(const cJSON *json, double *out_double)
Parse a double from a JSON object.
Definition: u_json.c:67