Move to kernel style SPDX license identifiers
[babeltrace.git] / src / ctf-writer / values.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (c) 2015-2017 EfficiOS Inc. and Linux Foundation
5 * Copyright (c) 2015-2017 Philippe Proulx <pproulx@efficios.com>
6 */
7
8 #ifndef BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H
9 #define BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H
10
11 #include <babeltrace2-ctf-writer/types.h>
12
13 #include "common/macros.h"
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
41 extern struct bt_ctf_value *const bt_ctf_value_null;
42
43 enum bt_ctf_value_type {
44 /// Null value object.
45 BT_CTF_VALUE_TYPE_NULL = 0,
46
47 /// Boolean value object (holds #BT_CTF_TRUE or #BT_CTF_FALSE).
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
70 bt_ctf_bool bt_ctf_value_is_null(const struct bt_ctf_value *object)
71 {
72 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_NULL;
73 }
74
75 static inline
76 bt_ctf_bool bt_ctf_value_is_bool(const struct bt_ctf_value *object)
77 {
78 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_BOOL;
79 }
80
81 static inline
82 bt_ctf_bool bt_ctf_value_is_integer(const struct bt_ctf_value *object)
83 {
84 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_INTEGER;
85 }
86
87 static inline
88 bt_ctf_bool bt_ctf_value_is_real(const struct bt_ctf_value *object)
89 {
90 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_REAL;
91 }
92
93 static inline
94 bt_ctf_bool bt_ctf_value_is_string(const struct bt_ctf_value *object)
95 {
96 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_STRING;
97 }
98
99 static inline
100 bt_ctf_bool bt_ctf_value_is_array(const struct bt_ctf_value *object)
101 {
102 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_ARRAY;
103 }
104
105 static inline
106 bt_ctf_bool bt_ctf_value_is_map(const struct bt_ctf_value *object)
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
116 bt_ctf_bool bt_ctf_value_compare(const struct bt_ctf_value *object_a,
117 const struct bt_ctf_value *object_b);
118
119 BT_HIDDEN
120 bt_ctf_bool bt_ctf_value_bool_get(const struct bt_ctf_value *bool_obj);
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
132 uint64_t bt_ctf_value_array_get_length(const struct bt_ctf_value *array_obj);
133
134 static inline
135 bt_ctf_bool bt_ctf_value_array_is_empty(const struct bt_ctf_value *array_obj)
136 {
137 return bt_ctf_value_array_get_length(array_obj) == 0;
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
148 bt_ctf_bool bt_ctf_value_map_is_empty(const struct bt_ctf_value *map_obj)
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
157 typedef bt_ctf_bool (* bt_ctf_value_map_foreach_entry_cb)(const char *key,
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
166 bt_ctf_bool bt_ctf_value_map_has_entry(const struct bt_ctf_value *map_obj,
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
179 extern struct bt_ctf_private_value *const bt_ctf_private_value_null;
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
192 struct bt_ctf_private_value *bt_ctf_private_value_bool_create_init(bt_ctf_bool val);
193
194 BT_HIDDEN
195 void bt_ctf_private_value_bool_set(struct bt_ctf_private_value *bool_obj,
196 bt_ctf_bool val);
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,
246 bt_ctf_bool val);
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
282 typedef bt_ctf_bool (* bt_ctf_private_value_map_foreach_entry_cb)(const char *key,
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(
297 struct bt_ctf_private_value *map_obj, const char *key, bt_ctf_bool val);
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
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
343 #endif /* BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H */
This page took 0.035233 seconds and 4 git commands to generate.