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 | ||
32 | BT_HIDDEN | |
33 | enum bt_ctf_value_status _bt_ctf_value_freeze(struct bt_ctf_value *object); | |
34 | ||
35 | #ifdef BT_DEV_MODE | |
36 | # define bt_ctf_value_freeze _bt_ctf_value_freeze | |
37 | #else | |
38 | # define bt_ctf_value_freeze(_value) | |
39 | #endif /* BT_DEV_MODE */ | |
40 | ||
b78363ea | 41 | extern struct bt_ctf_value *const bt_ctf_value_null; |
e1e02a22 PP |
42 | |
43 | enum bt_ctf_value_type { | |
44 | /// Null value object. | |
45 | BT_CTF_VALUE_TYPE_NULL = 0, | |
46 | ||
00409097 | 47 | /// Boolean value object (holds #BT_CTF_TRUE or #BT_CTF_FALSE). |
e1e02a22 PP |
48 | BT_CTF_VALUE_TYPE_BOOL = 1, |
49 | ||
50 | /// Integer value object (holds a signed 64-bit integer raw value). | |
51 | BT_CTF_VALUE_TYPE_INTEGER = 2, | |
52 | ||
53 | /// Floating point number value object (holds a \c double raw value). | |
54 | BT_CTF_VALUE_TYPE_REAL = 3, | |
55 | ||
56 | /// String value object. | |
57 | BT_CTF_VALUE_TYPE_STRING = 4, | |
58 | ||
59 | /// Array value object. | |
60 | BT_CTF_VALUE_TYPE_ARRAY = 5, | |
61 | ||
62 | /// Map value object. | |
63 | BT_CTF_VALUE_TYPE_MAP = 6, | |
64 | }; | |
65 | ||
66 | BT_HIDDEN | |
67 | enum bt_ctf_value_type bt_ctf_value_get_type(const struct bt_ctf_value *object); | |
68 | ||
69 | static inline | |
00409097 | 70 | bt_ctf_bool bt_ctf_value_is_null(const struct bt_ctf_value *object) |
e1e02a22 PP |
71 | { |
72 | return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_NULL; | |
73 | } | |
74 | ||
75 | static inline | |
00409097 | 76 | bt_ctf_bool bt_ctf_value_is_bool(const struct bt_ctf_value *object) |
e1e02a22 PP |
77 | { |
78 | return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_BOOL; | |
79 | } | |
80 | ||
81 | static inline | |
00409097 | 82 | bt_ctf_bool bt_ctf_value_is_integer(const struct bt_ctf_value *object) |
e1e02a22 PP |
83 | { |
84 | return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_INTEGER; | |
85 | } | |
86 | ||
87 | static inline | |
00409097 | 88 | bt_ctf_bool bt_ctf_value_is_real(const struct bt_ctf_value *object) |
e1e02a22 PP |
89 | { |
90 | return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_REAL; | |
91 | } | |
92 | ||
93 | static inline | |
00409097 | 94 | bt_ctf_bool bt_ctf_value_is_string(const struct bt_ctf_value *object) |
e1e02a22 PP |
95 | { |
96 | return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_STRING; | |
97 | } | |
98 | ||
99 | static inline | |
00409097 | 100 | bt_ctf_bool bt_ctf_value_is_array(const struct bt_ctf_value *object) |
e1e02a22 PP |
101 | { |
102 | return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_ARRAY; | |
103 | } | |
104 | ||
105 | static inline | |
00409097 | 106 | bt_ctf_bool bt_ctf_value_is_map(const struct bt_ctf_value *object) |
e1e02a22 PP |
107 | { |
108 | return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_MAP; | |
109 | } | |
110 | ||
111 | BT_HIDDEN | |
112 | enum bt_ctf_value_status bt_ctf_value_copy(struct bt_ctf_private_value **copy, | |
113 | const struct bt_ctf_value *object); | |
114 | ||
115 | BT_HIDDEN | |
00409097 | 116 | bt_ctf_bool bt_ctf_value_compare(const struct bt_ctf_value *object_a, |
e1e02a22 PP |
117 | const struct bt_ctf_value *object_b); |
118 | ||
119 | BT_HIDDEN | |
00409097 | 120 | bt_ctf_bool bt_ctf_value_bool_get(const struct bt_ctf_value *bool_obj); |
e1e02a22 PP |
121 | |
122 | BT_HIDDEN | |
123 | int64_t bt_ctf_value_integer_get(const struct bt_ctf_value *integer_obj); | |
124 | ||
125 | BT_HIDDEN | |
126 | double bt_ctf_value_real_get(const struct bt_ctf_value *real_obj); | |
127 | ||
128 | BT_HIDDEN | |
129 | const char *bt_ctf_value_string_get(const struct bt_ctf_value *string_obj); | |
130 | ||
131 | BT_HIDDEN | |
393729a6 | 132 | uint64_t bt_ctf_value_array_get_length(const struct bt_ctf_value *array_obj); |
e1e02a22 PP |
133 | |
134 | static inline | |
00409097 | 135 | bt_ctf_bool bt_ctf_value_array_is_empty(const struct bt_ctf_value *array_obj) |
e1e02a22 | 136 | { |
393729a6 | 137 | return bt_ctf_value_array_get_length(array_obj) == 0; |
e1e02a22 PP |
138 | } |
139 | ||
140 | BT_HIDDEN | |
141 | struct bt_ctf_value *bt_ctf_value_array_borrow_element_by_index( | |
142 | const struct bt_ctf_value *array_obj, uint64_t index); | |
143 | ||
144 | BT_HIDDEN | |
145 | uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value *map_obj); | |
146 | ||
147 | static inline | |
00409097 | 148 | bt_ctf_bool bt_ctf_value_map_is_empty(const struct bt_ctf_value *map_obj) |
e1e02a22 PP |
149 | { |
150 | return bt_ctf_value_map_get_size(map_obj) == 0; | |
151 | } | |
152 | ||
153 | BT_HIDDEN | |
154 | struct bt_ctf_value *bt_ctf_value_map_borrow_entry_value( | |
155 | const struct bt_ctf_value *map_obj, const char *key); | |
156 | ||
00409097 | 157 | typedef bt_ctf_bool (* bt_ctf_value_map_foreach_entry_cb)(const char *key, |
e1e02a22 PP |
158 | struct bt_ctf_value *object, void *data); |
159 | ||
160 | BT_HIDDEN | |
161 | enum bt_ctf_value_status bt_ctf_value_map_foreach_entry( | |
162 | const struct bt_ctf_value *map_obj, | |
163 | bt_ctf_value_map_foreach_entry_cb cb, void *data); | |
164 | ||
165 | BT_HIDDEN | |
00409097 | 166 | bt_ctf_bool bt_ctf_value_map_has_entry(const struct bt_ctf_value *map_obj, |
e1e02a22 PP |
167 | const char *key); |
168 | ||
169 | BT_HIDDEN | |
170 | enum bt_ctf_value_status bt_ctf_value_map_extend( | |
171 | struct bt_ctf_private_value **extended_map_obj, | |
172 | const struct bt_ctf_value *base_map_obj, | |
173 | const struct bt_ctf_value *extension_map_obj); | |
174 | ||
175 | ||
176 | struct bt_ctf_value; | |
177 | struct bt_ctf_private_value; | |
178 | ||
b78363ea | 179 | extern struct bt_ctf_private_value *const bt_ctf_private_value_null; |
e1e02a22 PP |
180 | |
181 | static inline | |
182 | struct bt_ctf_value *bt_ctf_private_value_as_value( | |
183 | struct bt_ctf_private_value *priv_value) | |
184 | { | |
185 | return (void *) priv_value; | |
186 | } | |
187 | ||
188 | BT_HIDDEN | |
189 | struct bt_ctf_private_value *bt_ctf_private_value_bool_create(void); | |
190 | ||
191 | BT_HIDDEN | |
00409097 | 192 | struct bt_ctf_private_value *bt_ctf_private_value_bool_create_init(bt_ctf_bool val); |
e1e02a22 PP |
193 | |
194 | BT_HIDDEN | |
195 | void bt_ctf_private_value_bool_set(struct bt_ctf_private_value *bool_obj, | |
00409097 | 196 | bt_ctf_bool val); |
e1e02a22 PP |
197 | |
198 | BT_HIDDEN | |
199 | struct bt_ctf_private_value *bt_ctf_private_value_integer_create(void); | |
200 | ||
201 | BT_HIDDEN | |
202 | struct bt_ctf_private_value *bt_ctf_private_value_integer_create_init( | |
203 | int64_t val); | |
204 | ||
205 | BT_HIDDEN | |
206 | void bt_ctf_private_value_integer_set( | |
207 | struct bt_ctf_private_value *integer_obj, int64_t val); | |
208 | ||
209 | BT_HIDDEN | |
210 | struct bt_ctf_private_value *bt_ctf_private_value_real_create(void); | |
211 | ||
212 | BT_HIDDEN | |
213 | struct bt_ctf_private_value *bt_ctf_private_value_real_create_init(double val); | |
214 | ||
215 | BT_HIDDEN | |
216 | void bt_ctf_private_value_real_set( | |
217 | struct bt_ctf_private_value *real_obj, double val); | |
218 | ||
219 | BT_HIDDEN | |
220 | struct bt_ctf_private_value *bt_ctf_private_value_string_create(void); | |
221 | ||
222 | BT_HIDDEN | |
223 | struct bt_ctf_private_value *bt_ctf_private_value_string_create_init( | |
224 | const char *val); | |
225 | ||
226 | BT_HIDDEN | |
227 | enum bt_ctf_value_status bt_ctf_private_value_string_set( | |
228 | struct bt_ctf_private_value *string_obj, | |
229 | const char *val); | |
230 | ||
231 | BT_HIDDEN | |
232 | struct bt_ctf_private_value *bt_ctf_private_value_array_create(void); | |
233 | ||
234 | BT_HIDDEN | |
235 | struct bt_ctf_private_value *bt_ctf_private_value_array_borrow_element_by_index( | |
236 | const struct bt_ctf_private_value *array_obj, uint64_t index); | |
237 | ||
238 | BT_HIDDEN | |
239 | enum bt_ctf_value_status bt_ctf_private_value_array_append_element( | |
240 | struct bt_ctf_private_value *array_obj, | |
241 | struct bt_ctf_value *element_obj); | |
242 | ||
243 | BT_HIDDEN | |
244 | enum bt_ctf_value_status bt_ctf_private_value_array_append_bool_element( | |
245 | struct bt_ctf_private_value *array_obj, | |
00409097 | 246 | bt_ctf_bool val); |
e1e02a22 PP |
247 | |
248 | BT_HIDDEN | |
249 | enum bt_ctf_value_status bt_ctf_private_value_array_append_integer_element( | |
250 | struct bt_ctf_private_value *array_obj, | |
251 | int64_t val); | |
252 | ||
253 | BT_HIDDEN | |
254 | enum bt_ctf_value_status bt_ctf_private_value_array_append_real_element( | |
255 | struct bt_ctf_private_value *array_obj, | |
256 | double val); | |
257 | ||
258 | BT_HIDDEN | |
259 | enum bt_ctf_value_status bt_ctf_private_value_array_append_string_element( | |
260 | struct bt_ctf_private_value *array_obj, const char *val); | |
261 | ||
262 | BT_HIDDEN | |
263 | enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_array_element( | |
264 | struct bt_ctf_private_value *array_obj); | |
265 | ||
266 | BT_HIDDEN | |
267 | enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_map_element( | |
268 | struct bt_ctf_private_value *array_obj); | |
269 | ||
270 | BT_HIDDEN | |
271 | enum bt_ctf_value_status bt_ctf_private_value_array_set_element_by_index( | |
272 | struct bt_ctf_private_value *array_obj, uint64_t index, | |
273 | struct bt_ctf_value *element_obj); | |
274 | ||
275 | BT_HIDDEN | |
276 | struct bt_ctf_private_value *bt_ctf_private_value_map_create(void); | |
277 | ||
278 | BT_HIDDEN | |
279 | struct bt_ctf_private_value *bt_ctf_private_value_map_borrow_entry_value( | |
280 | const struct bt_ctf_private_value *map_obj, const char *key); | |
281 | ||
00409097 | 282 | typedef bt_ctf_bool (* bt_ctf_private_value_map_foreach_entry_cb)(const char *key, |
e1e02a22 PP |
283 | struct bt_ctf_private_value *object, void *data); |
284 | ||
285 | BT_HIDDEN | |
286 | enum bt_ctf_value_status bt_ctf_private_value_map_foreach_entry( | |
287 | const struct bt_ctf_private_value *map_obj, | |
288 | bt_ctf_private_value_map_foreach_entry_cb cb, void *data); | |
289 | ||
290 | BT_HIDDEN | |
291 | enum bt_ctf_value_status bt_ctf_private_value_map_insert_entry( | |
292 | struct bt_ctf_private_value *map_obj, const char *key, | |
293 | struct bt_ctf_value *element_obj); | |
294 | ||
295 | BT_HIDDEN | |
296 | enum bt_ctf_value_status bt_ctf_private_value_map_insert_bool_entry( | |
00409097 | 297 | struct bt_ctf_private_value *map_obj, const char *key, bt_ctf_bool val); |
e1e02a22 PP |
298 | |
299 | BT_HIDDEN | |
300 | enum bt_ctf_value_status bt_ctf_private_value_map_insert_integer_entry( | |
301 | struct bt_ctf_private_value *map_obj, const char *key, int64_t val); | |
302 | ||
303 | BT_HIDDEN | |
304 | enum bt_ctf_value_status bt_ctf_private_value_map_insert_real_entry( | |
305 | struct bt_ctf_private_value *map_obj, const char *key, double val); | |
306 | ||
307 | BT_HIDDEN | |
308 | enum bt_ctf_value_status bt_ctf_private_value_map_insert_string_entry( | |
309 | struct bt_ctf_private_value *map_obj, const char *key, | |
310 | const char *val); | |
311 | ||
312 | BT_HIDDEN | |
313 | enum bt_ctf_value_status bt_ctf_private_value_map_insert_empty_array_entry( | |
314 | struct bt_ctf_private_value *map_obj, const char *key); | |
315 | ||
316 | BT_HIDDEN | |
317 | enum bt_ctf_value_status bt_ctf_private_value_map_insert_empty_map_entry( | |
318 | struct bt_ctf_private_value *map_obj, const char *key); | |
319 | ||
ff3eac88 FD |
320 | static inline |
321 | const char *bt_ctf_value_type_string(enum bt_ctf_value_type type) | |
322 | { | |
323 | switch (type) { | |
324 | case BT_CTF_VALUE_TYPE_NULL: | |
325 | return "BT_CTF_VALUE_TYPE_NULL"; | |
326 | case BT_CTF_VALUE_TYPE_BOOL: | |
327 | return "BT_CTF_VALUE_TYPE_BOOL"; | |
328 | case BT_CTF_VALUE_TYPE_INTEGER: | |
329 | return "BT_CTF_VALUE_TYPE_INTEGER"; | |
330 | case BT_CTF_VALUE_TYPE_REAL: | |
331 | return "BT_CTF_VALUE_TYPE_REAL"; | |
332 | case BT_CTF_VALUE_TYPE_STRING: | |
333 | return "BT_CTF_VALUE_TYPE_STRING"; | |
334 | case BT_CTF_VALUE_TYPE_ARRAY: | |
335 | return "BT_CTF_VALUE_TYPE_ARRAY"; | |
336 | case BT_CTF_VALUE_TYPE_MAP: | |
337 | return "BT_CTF_VALUE_TYPE_MAP"; | |
338 | default: | |
339 | return "(unknown)"; | |
340 | } | |
341 | }; | |
342 | ||
e1e02a22 | 343 | #endif /* BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H */ |