Remove legacy `include/babeltrace2/{ctf-ir,ctf}` directories
[babeltrace.git] / src / ctf-writer / values.h
CommitLineData
e1e02a22
PP
1#ifndef BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H
2#define BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H
3
4/*
5 * Copyright (c) 2015-2017 EfficiOS Inc. and Linux Foundation
6 * Copyright (c) 2015-2017 Philippe Proulx <pproulx@efficios.com>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26
00409097 27#include <babeltrace2/ctf-writer/types.h>
91d81473
MJ
28
29#include "common/macros.h"
e1e02a22
PP
30
31struct bt_ctf_value;
32struct bt_ctf_private_value;
33
34/**
35@brief Status codes.
36*/
37enum bt_ctf_value_status {
38 /// Operation canceled.
39 BT_CTF_VALUE_STATUS_CANCELED = 125,
40
41 /// Cannot allocate memory.
42 BT_CTF_VALUE_STATUS_NOMEM = -12,
43
44 /// Okay, no error.
45 BT_CTF_VALUE_STATUS_OK = 0,
46};
47
48BT_HIDDEN
49enum bt_ctf_value_status _bt_ctf_value_freeze(struct bt_ctf_value *object);
50
51#ifdef BT_DEV_MODE
52# define bt_ctf_value_freeze _bt_ctf_value_freeze
53#else
54# define bt_ctf_value_freeze(_value)
55#endif /* BT_DEV_MODE */
56
b78363ea 57extern struct bt_ctf_value *const bt_ctf_value_null;
e1e02a22
PP
58
59enum bt_ctf_value_type {
60 /// Null value object.
61 BT_CTF_VALUE_TYPE_NULL = 0,
62
00409097 63 /// Boolean value object (holds #BT_CTF_TRUE or #BT_CTF_FALSE).
e1e02a22
PP
64 BT_CTF_VALUE_TYPE_BOOL = 1,
65
66 /// Integer value object (holds a signed 64-bit integer raw value).
67 BT_CTF_VALUE_TYPE_INTEGER = 2,
68
69 /// Floating point number value object (holds a \c double raw value).
70 BT_CTF_VALUE_TYPE_REAL = 3,
71
72 /// String value object.
73 BT_CTF_VALUE_TYPE_STRING = 4,
74
75 /// Array value object.
76 BT_CTF_VALUE_TYPE_ARRAY = 5,
77
78 /// Map value object.
79 BT_CTF_VALUE_TYPE_MAP = 6,
80};
81
82BT_HIDDEN
83enum bt_ctf_value_type bt_ctf_value_get_type(const struct bt_ctf_value *object);
84
85static inline
00409097 86bt_ctf_bool bt_ctf_value_is_null(const struct bt_ctf_value *object)
e1e02a22
PP
87{
88 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_NULL;
89}
90
91static inline
00409097 92bt_ctf_bool bt_ctf_value_is_bool(const struct bt_ctf_value *object)
e1e02a22
PP
93{
94 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_BOOL;
95}
96
97static inline
00409097 98bt_ctf_bool bt_ctf_value_is_integer(const struct bt_ctf_value *object)
e1e02a22
PP
99{
100 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_INTEGER;
101}
102
103static inline
00409097 104bt_ctf_bool bt_ctf_value_is_real(const struct bt_ctf_value *object)
e1e02a22
PP
105{
106 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_REAL;
107}
108
109static inline
00409097 110bt_ctf_bool bt_ctf_value_is_string(const struct bt_ctf_value *object)
e1e02a22
PP
111{
112 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_STRING;
113}
114
115static inline
00409097 116bt_ctf_bool bt_ctf_value_is_array(const struct bt_ctf_value *object)
e1e02a22
PP
117{
118 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_ARRAY;
119}
120
121static inline
00409097 122bt_ctf_bool bt_ctf_value_is_map(const struct bt_ctf_value *object)
e1e02a22
PP
123{
124 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_MAP;
125}
126
127BT_HIDDEN
128enum bt_ctf_value_status bt_ctf_value_copy(struct bt_ctf_private_value **copy,
129 const struct bt_ctf_value *object);
130
131BT_HIDDEN
00409097 132bt_ctf_bool bt_ctf_value_compare(const struct bt_ctf_value *object_a,
e1e02a22
PP
133 const struct bt_ctf_value *object_b);
134
135BT_HIDDEN
00409097 136bt_ctf_bool bt_ctf_value_bool_get(const struct bt_ctf_value *bool_obj);
e1e02a22
PP
137
138BT_HIDDEN
139int64_t bt_ctf_value_integer_get(const struct bt_ctf_value *integer_obj);
140
141BT_HIDDEN
142double bt_ctf_value_real_get(const struct bt_ctf_value *real_obj);
143
144BT_HIDDEN
145const char *bt_ctf_value_string_get(const struct bt_ctf_value *string_obj);
146
147BT_HIDDEN
148uint64_t bt_ctf_value_array_get_size(const struct bt_ctf_value *array_obj);
149
150static inline
00409097 151bt_ctf_bool bt_ctf_value_array_is_empty(const struct bt_ctf_value *array_obj)
e1e02a22
PP
152{
153 return bt_ctf_value_array_get_size(array_obj) == 0;
154}
155
156BT_HIDDEN
157struct bt_ctf_value *bt_ctf_value_array_borrow_element_by_index(
158 const struct bt_ctf_value *array_obj, uint64_t index);
159
160BT_HIDDEN
161uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value *map_obj);
162
163static inline
00409097 164bt_ctf_bool bt_ctf_value_map_is_empty(const struct bt_ctf_value *map_obj)
e1e02a22
PP
165{
166 return bt_ctf_value_map_get_size(map_obj) == 0;
167}
168
169BT_HIDDEN
170struct bt_ctf_value *bt_ctf_value_map_borrow_entry_value(
171 const struct bt_ctf_value *map_obj, const char *key);
172
00409097 173typedef bt_ctf_bool (* bt_ctf_value_map_foreach_entry_cb)(const char *key,
e1e02a22
PP
174 struct bt_ctf_value *object, void *data);
175
176BT_HIDDEN
177enum bt_ctf_value_status bt_ctf_value_map_foreach_entry(
178 const struct bt_ctf_value *map_obj,
179 bt_ctf_value_map_foreach_entry_cb cb, void *data);
180
181BT_HIDDEN
00409097 182bt_ctf_bool bt_ctf_value_map_has_entry(const struct bt_ctf_value *map_obj,
e1e02a22
PP
183 const char *key);
184
185BT_HIDDEN
186enum bt_ctf_value_status bt_ctf_value_map_extend(
187 struct bt_ctf_private_value **extended_map_obj,
188 const struct bt_ctf_value *base_map_obj,
189 const struct bt_ctf_value *extension_map_obj);
190
191
192struct bt_ctf_value;
193struct bt_ctf_private_value;
194
b78363ea 195extern struct bt_ctf_private_value *const bt_ctf_private_value_null;
e1e02a22
PP
196
197static inline
198struct bt_ctf_value *bt_ctf_private_value_as_value(
199 struct bt_ctf_private_value *priv_value)
200{
201 return (void *) priv_value;
202}
203
204BT_HIDDEN
205struct bt_ctf_private_value *bt_ctf_private_value_bool_create(void);
206
207BT_HIDDEN
00409097 208struct bt_ctf_private_value *bt_ctf_private_value_bool_create_init(bt_ctf_bool val);
e1e02a22
PP
209
210BT_HIDDEN
211void bt_ctf_private_value_bool_set(struct bt_ctf_private_value *bool_obj,
00409097 212 bt_ctf_bool val);
e1e02a22
PP
213
214BT_HIDDEN
215struct bt_ctf_private_value *bt_ctf_private_value_integer_create(void);
216
217BT_HIDDEN
218struct bt_ctf_private_value *bt_ctf_private_value_integer_create_init(
219 int64_t val);
220
221BT_HIDDEN
222void bt_ctf_private_value_integer_set(
223 struct bt_ctf_private_value *integer_obj, int64_t val);
224
225BT_HIDDEN
226struct bt_ctf_private_value *bt_ctf_private_value_real_create(void);
227
228BT_HIDDEN
229struct bt_ctf_private_value *bt_ctf_private_value_real_create_init(double val);
230
231BT_HIDDEN
232void bt_ctf_private_value_real_set(
233 struct bt_ctf_private_value *real_obj, double val);
234
235BT_HIDDEN
236struct bt_ctf_private_value *bt_ctf_private_value_string_create(void);
237
238BT_HIDDEN
239struct bt_ctf_private_value *bt_ctf_private_value_string_create_init(
240 const char *val);
241
242BT_HIDDEN
243enum bt_ctf_value_status bt_ctf_private_value_string_set(
244 struct bt_ctf_private_value *string_obj,
245 const char *val);
246
247BT_HIDDEN
248struct bt_ctf_private_value *bt_ctf_private_value_array_create(void);
249
250BT_HIDDEN
251struct bt_ctf_private_value *bt_ctf_private_value_array_borrow_element_by_index(
252 const struct bt_ctf_private_value *array_obj, uint64_t index);
253
254BT_HIDDEN
255enum bt_ctf_value_status bt_ctf_private_value_array_append_element(
256 struct bt_ctf_private_value *array_obj,
257 struct bt_ctf_value *element_obj);
258
259BT_HIDDEN
260enum bt_ctf_value_status bt_ctf_private_value_array_append_bool_element(
261 struct bt_ctf_private_value *array_obj,
00409097 262 bt_ctf_bool val);
e1e02a22
PP
263
264BT_HIDDEN
265enum bt_ctf_value_status bt_ctf_private_value_array_append_integer_element(
266 struct bt_ctf_private_value *array_obj,
267 int64_t val);
268
269BT_HIDDEN
270enum bt_ctf_value_status bt_ctf_private_value_array_append_real_element(
271 struct bt_ctf_private_value *array_obj,
272 double val);
273
274BT_HIDDEN
275enum bt_ctf_value_status bt_ctf_private_value_array_append_string_element(
276 struct bt_ctf_private_value *array_obj, const char *val);
277
278BT_HIDDEN
279enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_array_element(
280 struct bt_ctf_private_value *array_obj);
281
282BT_HIDDEN
283enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_map_element(
284 struct bt_ctf_private_value *array_obj);
285
286BT_HIDDEN
287enum bt_ctf_value_status bt_ctf_private_value_array_set_element_by_index(
288 struct bt_ctf_private_value *array_obj, uint64_t index,
289 struct bt_ctf_value *element_obj);
290
291BT_HIDDEN
292struct bt_ctf_private_value *bt_ctf_private_value_map_create(void);
293
294BT_HIDDEN
295struct bt_ctf_private_value *bt_ctf_private_value_map_borrow_entry_value(
296 const struct bt_ctf_private_value *map_obj, const char *key);
297
00409097 298typedef bt_ctf_bool (* bt_ctf_private_value_map_foreach_entry_cb)(const char *key,
e1e02a22
PP
299 struct bt_ctf_private_value *object, void *data);
300
301BT_HIDDEN
302enum bt_ctf_value_status bt_ctf_private_value_map_foreach_entry(
303 const struct bt_ctf_private_value *map_obj,
304 bt_ctf_private_value_map_foreach_entry_cb cb, void *data);
305
306BT_HIDDEN
307enum bt_ctf_value_status bt_ctf_private_value_map_insert_entry(
308 struct bt_ctf_private_value *map_obj, const char *key,
309 struct bt_ctf_value *element_obj);
310
311BT_HIDDEN
312enum bt_ctf_value_status bt_ctf_private_value_map_insert_bool_entry(
00409097 313 struct bt_ctf_private_value *map_obj, const char *key, bt_ctf_bool val);
e1e02a22
PP
314
315BT_HIDDEN
316enum bt_ctf_value_status bt_ctf_private_value_map_insert_integer_entry(
317 struct bt_ctf_private_value *map_obj, const char *key, int64_t val);
318
319BT_HIDDEN
320enum bt_ctf_value_status bt_ctf_private_value_map_insert_real_entry(
321 struct bt_ctf_private_value *map_obj, const char *key, double val);
322
323BT_HIDDEN
324enum bt_ctf_value_status bt_ctf_private_value_map_insert_string_entry(
325 struct bt_ctf_private_value *map_obj, const char *key,
326 const char *val);
327
328BT_HIDDEN
329enum bt_ctf_value_status bt_ctf_private_value_map_insert_empty_array_entry(
330 struct bt_ctf_private_value *map_obj, const char *key);
331
332BT_HIDDEN
333enum bt_ctf_value_status bt_ctf_private_value_map_insert_empty_map_entry(
334 struct bt_ctf_private_value *map_obj, const char *key);
335
ff3eac88
FD
336static inline
337const char *bt_ctf_value_type_string(enum bt_ctf_value_type type)
338{
339 switch (type) {
340 case BT_CTF_VALUE_TYPE_NULL:
341 return "BT_CTF_VALUE_TYPE_NULL";
342 case BT_CTF_VALUE_TYPE_BOOL:
343 return "BT_CTF_VALUE_TYPE_BOOL";
344 case BT_CTF_VALUE_TYPE_INTEGER:
345 return "BT_CTF_VALUE_TYPE_INTEGER";
346 case BT_CTF_VALUE_TYPE_REAL:
347 return "BT_CTF_VALUE_TYPE_REAL";
348 case BT_CTF_VALUE_TYPE_STRING:
349 return "BT_CTF_VALUE_TYPE_STRING";
350 case BT_CTF_VALUE_TYPE_ARRAY:
351 return "BT_CTF_VALUE_TYPE_ARRAY";
352 case BT_CTF_VALUE_TYPE_MAP:
353 return "BT_CTF_VALUE_TYPE_MAP";
354 default:
355 return "(unknown)";
356 }
357};
358
e1e02a22 359#endif /* BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H */
This page took 0.054371 seconds and 4 git commands to generate.