Move to kernel style SPDX license identifiers
[babeltrace.git] / src / ctf-writer / values.h
... / ...
CommitLineData
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
15struct bt_ctf_value;
16struct bt_ctf_private_value;
17
18/**
19@brief Status codes.
20*/
21enum 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
32BT_HIDDEN
33enum 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
41extern struct bt_ctf_value *const bt_ctf_value_null;
42
43enum 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
66BT_HIDDEN
67enum bt_ctf_value_type bt_ctf_value_get_type(const struct bt_ctf_value *object);
68
69static inline
70bt_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
75static inline
76bt_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
81static inline
82bt_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
87static inline
88bt_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
93static inline
94bt_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
99static inline
100bt_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
105static inline
106bt_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
111BT_HIDDEN
112enum bt_ctf_value_status bt_ctf_value_copy(struct bt_ctf_private_value **copy,
113 const struct bt_ctf_value *object);
114
115BT_HIDDEN
116bt_ctf_bool bt_ctf_value_compare(const struct bt_ctf_value *object_a,
117 const struct bt_ctf_value *object_b);
118
119BT_HIDDEN
120bt_ctf_bool bt_ctf_value_bool_get(const struct bt_ctf_value *bool_obj);
121
122BT_HIDDEN
123int64_t bt_ctf_value_integer_get(const struct bt_ctf_value *integer_obj);
124
125BT_HIDDEN
126double bt_ctf_value_real_get(const struct bt_ctf_value *real_obj);
127
128BT_HIDDEN
129const char *bt_ctf_value_string_get(const struct bt_ctf_value *string_obj);
130
131BT_HIDDEN
132uint64_t bt_ctf_value_array_get_length(const struct bt_ctf_value *array_obj);
133
134static inline
135bt_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
140BT_HIDDEN
141struct bt_ctf_value *bt_ctf_value_array_borrow_element_by_index(
142 const struct bt_ctf_value *array_obj, uint64_t index);
143
144BT_HIDDEN
145uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value *map_obj);
146
147static inline
148bt_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
153BT_HIDDEN
154struct bt_ctf_value *bt_ctf_value_map_borrow_entry_value(
155 const struct bt_ctf_value *map_obj, const char *key);
156
157typedef bt_ctf_bool (* bt_ctf_value_map_foreach_entry_cb)(const char *key,
158 struct bt_ctf_value *object, void *data);
159
160BT_HIDDEN
161enum 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
165BT_HIDDEN
166bt_ctf_bool bt_ctf_value_map_has_entry(const struct bt_ctf_value *map_obj,
167 const char *key);
168
169BT_HIDDEN
170enum 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
176struct bt_ctf_value;
177struct bt_ctf_private_value;
178
179extern struct bt_ctf_private_value *const bt_ctf_private_value_null;
180
181static inline
182struct 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
188BT_HIDDEN
189struct bt_ctf_private_value *bt_ctf_private_value_bool_create(void);
190
191BT_HIDDEN
192struct bt_ctf_private_value *bt_ctf_private_value_bool_create_init(bt_ctf_bool val);
193
194BT_HIDDEN
195void bt_ctf_private_value_bool_set(struct bt_ctf_private_value *bool_obj,
196 bt_ctf_bool val);
197
198BT_HIDDEN
199struct bt_ctf_private_value *bt_ctf_private_value_integer_create(void);
200
201BT_HIDDEN
202struct bt_ctf_private_value *bt_ctf_private_value_integer_create_init(
203 int64_t val);
204
205BT_HIDDEN
206void bt_ctf_private_value_integer_set(
207 struct bt_ctf_private_value *integer_obj, int64_t val);
208
209BT_HIDDEN
210struct bt_ctf_private_value *bt_ctf_private_value_real_create(void);
211
212BT_HIDDEN
213struct bt_ctf_private_value *bt_ctf_private_value_real_create_init(double val);
214
215BT_HIDDEN
216void bt_ctf_private_value_real_set(
217 struct bt_ctf_private_value *real_obj, double val);
218
219BT_HIDDEN
220struct bt_ctf_private_value *bt_ctf_private_value_string_create(void);
221
222BT_HIDDEN
223struct bt_ctf_private_value *bt_ctf_private_value_string_create_init(
224 const char *val);
225
226BT_HIDDEN
227enum bt_ctf_value_status bt_ctf_private_value_string_set(
228 struct bt_ctf_private_value *string_obj,
229 const char *val);
230
231BT_HIDDEN
232struct bt_ctf_private_value *bt_ctf_private_value_array_create(void);
233
234BT_HIDDEN
235struct 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
238BT_HIDDEN
239enum 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
243BT_HIDDEN
244enum 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
248BT_HIDDEN
249enum 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
253BT_HIDDEN
254enum bt_ctf_value_status bt_ctf_private_value_array_append_real_element(
255 struct bt_ctf_private_value *array_obj,
256 double val);
257
258BT_HIDDEN
259enum bt_ctf_value_status bt_ctf_private_value_array_append_string_element(
260 struct bt_ctf_private_value *array_obj, const char *val);
261
262BT_HIDDEN
263enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_array_element(
264 struct bt_ctf_private_value *array_obj);
265
266BT_HIDDEN
267enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_map_element(
268 struct bt_ctf_private_value *array_obj);
269
270BT_HIDDEN
271enum 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
275BT_HIDDEN
276struct bt_ctf_private_value *bt_ctf_private_value_map_create(void);
277
278BT_HIDDEN
279struct 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
282typedef bt_ctf_bool (* bt_ctf_private_value_map_foreach_entry_cb)(const char *key,
283 struct bt_ctf_private_value *object, void *data);
284
285BT_HIDDEN
286enum 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
290BT_HIDDEN
291enum 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
295BT_HIDDEN
296enum 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
299BT_HIDDEN
300enum 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
303BT_HIDDEN
304enum 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
307BT_HIDDEN
308enum 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
312BT_HIDDEN
313enum 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
316BT_HIDDEN
317enum 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
320static inline
321const 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.023098 seconds and 4 git commands to generate.