Commit | Line | Data |
---|---|---|
e1e02a22 | 1 | /* |
0235b0db MJ |
2 | * SPDX-License-Identifier: MIT |
3 | * | |
e1e02a22 PP |
4 | * Copyright (c) 2015-2017 EfficiOS Inc. and Linux Foundation |
5 | * Copyright (c) 2015-2017 Philippe Proulx <pproulx@efficios.com> | |
e1e02a22 PP |
6 | */ |
7 | ||
0235b0db MJ |
8 | #ifndef BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H |
9 | #define BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H | |
10 | ||
217cf9d3 | 11 | #include <babeltrace2-ctf-writer/types.h> |
91d81473 MJ |
12 | |
13 | #include "common/macros.h" | |
e1e02a22 PP |
14 | |
15 | struct bt_ctf_value; | |
16 | struct bt_ctf_private_value; | |
17 | ||
18 | /** | |
19 | @brief Status codes. | |
20 | */ | |
21 | enum bt_ctf_value_status { | |
22 | /// Operation canceled. | |
23 | BT_CTF_VALUE_STATUS_CANCELED = 125, | |
24 | ||
25 | /// Cannot allocate memory. | |
26 | BT_CTF_VALUE_STATUS_NOMEM = -12, | |
27 | ||
28 | /// Okay, no error. | |
29 | BT_CTF_VALUE_STATUS_OK = 0, | |
30 | }; | |
31 | ||
e1e02a22 PP |
32 | enum bt_ctf_value_status _bt_ctf_value_freeze(struct bt_ctf_value *object); |
33 | ||
34 | #ifdef BT_DEV_MODE | |
35 | # define bt_ctf_value_freeze _bt_ctf_value_freeze | |
36 | #else | |
37 | # define bt_ctf_value_freeze(_value) | |
38 | #endif /* BT_DEV_MODE */ | |
39 | ||
b78363ea | 40 | extern struct bt_ctf_value *const bt_ctf_value_null; |
e1e02a22 PP |
41 | |
42 | enum bt_ctf_value_type { | |
43 | /// Null value object. | |
44 | BT_CTF_VALUE_TYPE_NULL = 0, | |
45 | ||
00409097 | 46 | /// Boolean value object (holds #BT_CTF_TRUE or #BT_CTF_FALSE). |
e1e02a22 PP |
47 | BT_CTF_VALUE_TYPE_BOOL = 1, |
48 | ||
49 | /// Integer value object (holds a signed 64-bit integer raw value). | |
50 | BT_CTF_VALUE_TYPE_INTEGER = 2, | |
51 | ||
52 | /// Floating point number value object (holds a \c double raw value). | |
53 | BT_CTF_VALUE_TYPE_REAL = 3, | |
54 | ||
55 | /// String value object. | |
56 | BT_CTF_VALUE_TYPE_STRING = 4, | |
57 | ||
58 | /// Array value object. | |
59 | BT_CTF_VALUE_TYPE_ARRAY = 5, | |
60 | ||
61 | /// Map value object. | |
62 | BT_CTF_VALUE_TYPE_MAP = 6, | |
63 | }; | |
64 | ||
e1e02a22 PP |
65 | enum bt_ctf_value_type bt_ctf_value_get_type(const struct bt_ctf_value *object); |
66 | ||
67 | static inline | |
00409097 | 68 | bt_ctf_bool bt_ctf_value_is_null(const struct bt_ctf_value *object) |
e1e02a22 PP |
69 | { |
70 | return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_NULL; | |
71 | } | |
72 | ||
73 | static inline | |
00409097 | 74 | bt_ctf_bool bt_ctf_value_is_bool(const struct bt_ctf_value *object) |
e1e02a22 PP |
75 | { |
76 | return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_BOOL; | |
77 | } | |
78 | ||
79 | static inline | |
00409097 | 80 | bt_ctf_bool bt_ctf_value_is_integer(const struct bt_ctf_value *object) |
e1e02a22 PP |
81 | { |
82 | return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_INTEGER; | |
83 | } | |
84 | ||
85 | static inline | |
00409097 | 86 | bt_ctf_bool bt_ctf_value_is_real(const struct bt_ctf_value *object) |
e1e02a22 PP |
87 | { |
88 | return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_REAL; | |
89 | } | |
90 | ||
91 | static inline | |
00409097 | 92 | bt_ctf_bool bt_ctf_value_is_string(const struct bt_ctf_value *object) |
e1e02a22 PP |
93 | { |
94 | return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_STRING; | |
95 | } | |
96 | ||
97 | static inline | |
00409097 | 98 | bt_ctf_bool bt_ctf_value_is_array(const struct bt_ctf_value *object) |
e1e02a22 PP |
99 | { |
100 | return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_ARRAY; | |
101 | } | |
102 | ||
103 | static inline | |
00409097 | 104 | bt_ctf_bool bt_ctf_value_is_map(const struct bt_ctf_value *object) |
e1e02a22 PP |
105 | { |
106 | return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_MAP; | |
107 | } | |
108 | ||
e1e02a22 PP |
109 | enum bt_ctf_value_status bt_ctf_value_copy(struct bt_ctf_private_value **copy, |
110 | const struct bt_ctf_value *object); | |
111 | ||
00409097 | 112 | bt_ctf_bool bt_ctf_value_compare(const struct bt_ctf_value *object_a, |
e1e02a22 PP |
113 | const struct bt_ctf_value *object_b); |
114 | ||
00409097 | 115 | bt_ctf_bool bt_ctf_value_bool_get(const struct bt_ctf_value *bool_obj); |
e1e02a22 | 116 | |
e1e02a22 PP |
117 | int64_t bt_ctf_value_integer_get(const struct bt_ctf_value *integer_obj); |
118 | ||
e1e02a22 PP |
119 | double bt_ctf_value_real_get(const struct bt_ctf_value *real_obj); |
120 | ||
e1e02a22 PP |
121 | const char *bt_ctf_value_string_get(const struct bt_ctf_value *string_obj); |
122 | ||
393729a6 | 123 | uint64_t bt_ctf_value_array_get_length(const struct bt_ctf_value *array_obj); |
e1e02a22 PP |
124 | |
125 | static inline | |
00409097 | 126 | bt_ctf_bool bt_ctf_value_array_is_empty(const struct bt_ctf_value *array_obj) |
e1e02a22 | 127 | { |
393729a6 | 128 | return bt_ctf_value_array_get_length(array_obj) == 0; |
e1e02a22 PP |
129 | } |
130 | ||
e1e02a22 PP |
131 | struct bt_ctf_value *bt_ctf_value_array_borrow_element_by_index( |
132 | const struct bt_ctf_value *array_obj, uint64_t index); | |
133 | ||
e1e02a22 PP |
134 | uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value *map_obj); |
135 | ||
136 | static inline | |
00409097 | 137 | bt_ctf_bool bt_ctf_value_map_is_empty(const struct bt_ctf_value *map_obj) |
e1e02a22 PP |
138 | { |
139 | return bt_ctf_value_map_get_size(map_obj) == 0; | |
140 | } | |
141 | ||
e1e02a22 PP |
142 | struct bt_ctf_value *bt_ctf_value_map_borrow_entry_value( |
143 | const struct bt_ctf_value *map_obj, const char *key); | |
144 | ||
00409097 | 145 | typedef bt_ctf_bool (* bt_ctf_value_map_foreach_entry_cb)(const char *key, |
e1e02a22 PP |
146 | struct bt_ctf_value *object, void *data); |
147 | ||
e1e02a22 PP |
148 | enum bt_ctf_value_status bt_ctf_value_map_foreach_entry( |
149 | const struct bt_ctf_value *map_obj, | |
150 | bt_ctf_value_map_foreach_entry_cb cb, void *data); | |
151 | ||
00409097 | 152 | bt_ctf_bool bt_ctf_value_map_has_entry(const struct bt_ctf_value *map_obj, |
e1e02a22 PP |
153 | const char *key); |
154 | ||
e1e02a22 PP |
155 | enum bt_ctf_value_status bt_ctf_value_map_extend( |
156 | struct bt_ctf_private_value **extended_map_obj, | |
157 | const struct bt_ctf_value *base_map_obj, | |
158 | const struct bt_ctf_value *extension_map_obj); | |
159 | ||
160 | ||
161 | struct bt_ctf_value; | |
162 | struct bt_ctf_private_value; | |
163 | ||
b78363ea | 164 | extern struct bt_ctf_private_value *const bt_ctf_private_value_null; |
e1e02a22 PP |
165 | |
166 | static inline | |
167 | struct bt_ctf_value *bt_ctf_private_value_as_value( | |
168 | struct bt_ctf_private_value *priv_value) | |
169 | { | |
170 | return (void *) priv_value; | |
171 | } | |
172 | ||
e1e02a22 PP |
173 | struct bt_ctf_private_value *bt_ctf_private_value_bool_create(void); |
174 | ||
00409097 | 175 | struct bt_ctf_private_value *bt_ctf_private_value_bool_create_init(bt_ctf_bool val); |
e1e02a22 | 176 | |
e1e02a22 | 177 | void bt_ctf_private_value_bool_set(struct bt_ctf_private_value *bool_obj, |
00409097 | 178 | bt_ctf_bool val); |
e1e02a22 | 179 | |
e1e02a22 PP |
180 | struct bt_ctf_private_value *bt_ctf_private_value_integer_create(void); |
181 | ||
e1e02a22 PP |
182 | struct bt_ctf_private_value *bt_ctf_private_value_integer_create_init( |
183 | int64_t val); | |
184 | ||
e1e02a22 PP |
185 | void bt_ctf_private_value_integer_set( |
186 | struct bt_ctf_private_value *integer_obj, int64_t val); | |
187 | ||
e1e02a22 PP |
188 | struct bt_ctf_private_value *bt_ctf_private_value_real_create(void); |
189 | ||
e1e02a22 PP |
190 | struct bt_ctf_private_value *bt_ctf_private_value_real_create_init(double val); |
191 | ||
e1e02a22 PP |
192 | void bt_ctf_private_value_real_set( |
193 | struct bt_ctf_private_value *real_obj, double val); | |
194 | ||
e1e02a22 PP |
195 | struct bt_ctf_private_value *bt_ctf_private_value_string_create(void); |
196 | ||
e1e02a22 PP |
197 | struct bt_ctf_private_value *bt_ctf_private_value_string_create_init( |
198 | const char *val); | |
199 | ||
e1e02a22 PP |
200 | enum bt_ctf_value_status bt_ctf_private_value_string_set( |
201 | struct bt_ctf_private_value *string_obj, | |
202 | const char *val); | |
203 | ||
e1e02a22 PP |
204 | struct bt_ctf_private_value *bt_ctf_private_value_array_create(void); |
205 | ||
e1e02a22 PP |
206 | struct bt_ctf_private_value *bt_ctf_private_value_array_borrow_element_by_index( |
207 | const struct bt_ctf_private_value *array_obj, uint64_t index); | |
208 | ||
e1e02a22 PP |
209 | enum bt_ctf_value_status bt_ctf_private_value_array_append_element( |
210 | struct bt_ctf_private_value *array_obj, | |
211 | struct bt_ctf_value *element_obj); | |
212 | ||
e1e02a22 PP |
213 | enum bt_ctf_value_status bt_ctf_private_value_array_append_bool_element( |
214 | struct bt_ctf_private_value *array_obj, | |
00409097 | 215 | bt_ctf_bool val); |
e1e02a22 | 216 | |
e1e02a22 PP |
217 | enum bt_ctf_value_status bt_ctf_private_value_array_append_integer_element( |
218 | struct bt_ctf_private_value *array_obj, | |
219 | int64_t val); | |
220 | ||
e1e02a22 PP |
221 | enum bt_ctf_value_status bt_ctf_private_value_array_append_real_element( |
222 | struct bt_ctf_private_value *array_obj, | |
223 | double val); | |
224 | ||
e1e02a22 PP |
225 | enum bt_ctf_value_status bt_ctf_private_value_array_append_string_element( |
226 | struct bt_ctf_private_value *array_obj, const char *val); | |
227 | ||
e1e02a22 PP |
228 | enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_array_element( |
229 | struct bt_ctf_private_value *array_obj); | |
230 | ||
e1e02a22 PP |
231 | enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_map_element( |
232 | struct bt_ctf_private_value *array_obj); | |
233 | ||
e1e02a22 PP |
234 | enum bt_ctf_value_status bt_ctf_private_value_array_set_element_by_index( |
235 | struct bt_ctf_private_value *array_obj, uint64_t index, | |
236 | struct bt_ctf_value *element_obj); | |
237 | ||
e1e02a22 PP |
238 | struct bt_ctf_private_value *bt_ctf_private_value_map_create(void); |
239 | ||
e1e02a22 PP |
240 | struct bt_ctf_private_value *bt_ctf_private_value_map_borrow_entry_value( |
241 | const struct bt_ctf_private_value *map_obj, const char *key); | |
242 | ||
00409097 | 243 | typedef bt_ctf_bool (* bt_ctf_private_value_map_foreach_entry_cb)(const char *key, |
e1e02a22 PP |
244 | struct bt_ctf_private_value *object, void *data); |
245 | ||
e1e02a22 PP |
246 | enum bt_ctf_value_status bt_ctf_private_value_map_foreach_entry( |
247 | const struct bt_ctf_private_value *map_obj, | |
248 | bt_ctf_private_value_map_foreach_entry_cb cb, void *data); | |
249 | ||
e1e02a22 PP |
250 | enum bt_ctf_value_status bt_ctf_private_value_map_insert_entry( |
251 | struct bt_ctf_private_value *map_obj, const char *key, | |
252 | struct bt_ctf_value *element_obj); | |
253 | ||
e1e02a22 | 254 | enum bt_ctf_value_status bt_ctf_private_value_map_insert_bool_entry( |
00409097 | 255 | struct bt_ctf_private_value *map_obj, const char *key, bt_ctf_bool val); |
e1e02a22 | 256 | |
e1e02a22 PP |
257 | enum bt_ctf_value_status bt_ctf_private_value_map_insert_integer_entry( |
258 | struct bt_ctf_private_value *map_obj, const char *key, int64_t val); | |
259 | ||
e1e02a22 PP |
260 | enum bt_ctf_value_status bt_ctf_private_value_map_insert_real_entry( |
261 | struct bt_ctf_private_value *map_obj, const char *key, double val); | |
262 | ||
e1e02a22 PP |
263 | enum bt_ctf_value_status bt_ctf_private_value_map_insert_string_entry( |
264 | struct bt_ctf_private_value *map_obj, const char *key, | |
265 | const char *val); | |
266 | ||
e1e02a22 PP |
267 | enum bt_ctf_value_status bt_ctf_private_value_map_insert_empty_array_entry( |
268 | struct bt_ctf_private_value *map_obj, const char *key); | |
269 | ||
e1e02a22 PP |
270 | enum bt_ctf_value_status bt_ctf_private_value_map_insert_empty_map_entry( |
271 | struct bt_ctf_private_value *map_obj, const char *key); | |
272 | ||
ff3eac88 FD |
273 | static inline |
274 | const char *bt_ctf_value_type_string(enum bt_ctf_value_type type) | |
275 | { | |
276 | switch (type) { | |
277 | case BT_CTF_VALUE_TYPE_NULL: | |
278 | return "BT_CTF_VALUE_TYPE_NULL"; | |
279 | case BT_CTF_VALUE_TYPE_BOOL: | |
280 | return "BT_CTF_VALUE_TYPE_BOOL"; | |
281 | case BT_CTF_VALUE_TYPE_INTEGER: | |
282 | return "BT_CTF_VALUE_TYPE_INTEGER"; | |
283 | case BT_CTF_VALUE_TYPE_REAL: | |
284 | return "BT_CTF_VALUE_TYPE_REAL"; | |
285 | case BT_CTF_VALUE_TYPE_STRING: | |
286 | return "BT_CTF_VALUE_TYPE_STRING"; | |
287 | case BT_CTF_VALUE_TYPE_ARRAY: | |
288 | return "BT_CTF_VALUE_TYPE_ARRAY"; | |
289 | case BT_CTF_VALUE_TYPE_MAP: | |
290 | return "BT_CTF_VALUE_TYPE_MAP"; | |
291 | default: | |
292 | return "(unknown)"; | |
293 | } | |
294 | }; | |
295 | ||
e1e02a22 | 296 | #endif /* BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H */ |