test-field.sh: make sure bt_run_in_py_env() and bt_cli() succeed
[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
32enum 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
40extern struct bt_ctf_value *const bt_ctf_value_null;
41
42enum bt_ctf_value_type {
43 /// Null value object.
44 BT_CTF_VALUE_TYPE_NULL = 0,
45
46 /// Boolean value object (holds #BT_CTF_TRUE or #BT_CTF_FALSE).
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
65enum bt_ctf_value_type bt_ctf_value_get_type(const struct bt_ctf_value *object);
66
67static inline
68bt_ctf_bool bt_ctf_value_is_null(const struct bt_ctf_value *object)
69{
70 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_NULL;
71}
72
73static inline
74bt_ctf_bool bt_ctf_value_is_bool(const struct bt_ctf_value *object)
75{
76 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_BOOL;
77}
78
79static inline
80bt_ctf_bool bt_ctf_value_is_integer(const struct bt_ctf_value *object)
81{
82 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_INTEGER;
83}
84
85static inline
86bt_ctf_bool bt_ctf_value_is_real(const struct bt_ctf_value *object)
87{
88 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_REAL;
89}
90
91static inline
92bt_ctf_bool bt_ctf_value_is_string(const struct bt_ctf_value *object)
93{
94 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_STRING;
95}
96
97static inline
98bt_ctf_bool bt_ctf_value_is_array(const struct bt_ctf_value *object)
99{
100 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_ARRAY;
101}
102
103static inline
104bt_ctf_bool bt_ctf_value_is_map(const struct bt_ctf_value *object)
105{
106 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_MAP;
107}
108
109enum bt_ctf_value_status bt_ctf_value_copy(struct bt_ctf_private_value **copy,
110 const struct bt_ctf_value *object);
111
112bt_ctf_bool bt_ctf_value_compare(const struct bt_ctf_value *object_a,
113 const struct bt_ctf_value *object_b);
114
115bt_ctf_bool bt_ctf_value_bool_get(const struct bt_ctf_value *bool_obj);
116
117int64_t bt_ctf_value_integer_get(const struct bt_ctf_value *integer_obj);
118
119double bt_ctf_value_real_get(const struct bt_ctf_value *real_obj);
120
121const char *bt_ctf_value_string_get(const struct bt_ctf_value *string_obj);
122
123uint64_t bt_ctf_value_array_get_length(const struct bt_ctf_value *array_obj);
124
125static inline
126bt_ctf_bool bt_ctf_value_array_is_empty(const struct bt_ctf_value *array_obj)
127{
128 return bt_ctf_value_array_get_length(array_obj) == 0;
129}
130
131struct bt_ctf_value *bt_ctf_value_array_borrow_element_by_index(
132 const struct bt_ctf_value *array_obj, uint64_t index);
133
134uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value *map_obj);
135
136static inline
137bt_ctf_bool bt_ctf_value_map_is_empty(const struct bt_ctf_value *map_obj)
138{
139 return bt_ctf_value_map_get_size(map_obj) == 0;
140}
141
142struct bt_ctf_value *bt_ctf_value_map_borrow_entry_value(
143 const struct bt_ctf_value *map_obj, const char *key);
144
145typedef bt_ctf_bool (* bt_ctf_value_map_foreach_entry_cb)(const char *key,
146 struct bt_ctf_value *object, void *data);
147
148enum 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
152bt_ctf_bool bt_ctf_value_map_has_entry(const struct bt_ctf_value *map_obj,
153 const char *key);
154
155enum 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
161struct bt_ctf_value;
162struct bt_ctf_private_value;
163
164extern struct bt_ctf_private_value *const bt_ctf_private_value_null;
165
166static inline
167struct 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
173struct bt_ctf_private_value *bt_ctf_private_value_bool_create(void);
174
175struct bt_ctf_private_value *bt_ctf_private_value_bool_create_init(bt_ctf_bool val);
176
177void bt_ctf_private_value_bool_set(struct bt_ctf_private_value *bool_obj,
178 bt_ctf_bool val);
179
180struct bt_ctf_private_value *bt_ctf_private_value_integer_create(void);
181
182struct bt_ctf_private_value *bt_ctf_private_value_integer_create_init(
183 int64_t val);
184
185void bt_ctf_private_value_integer_set(
186 struct bt_ctf_private_value *integer_obj, int64_t val);
187
188struct bt_ctf_private_value *bt_ctf_private_value_real_create(void);
189
190struct bt_ctf_private_value *bt_ctf_private_value_real_create_init(double val);
191
192void bt_ctf_private_value_real_set(
193 struct bt_ctf_private_value *real_obj, double val);
194
195struct bt_ctf_private_value *bt_ctf_private_value_string_create(void);
196
197struct bt_ctf_private_value *bt_ctf_private_value_string_create_init(
198 const char *val);
199
200enum bt_ctf_value_status bt_ctf_private_value_string_set(
201 struct bt_ctf_private_value *string_obj,
202 const char *val);
203
204struct bt_ctf_private_value *bt_ctf_private_value_array_create(void);
205
206struct 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
209enum 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
213enum bt_ctf_value_status bt_ctf_private_value_array_append_bool_element(
214 struct bt_ctf_private_value *array_obj,
215 bt_ctf_bool val);
216
217enum 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
221enum bt_ctf_value_status bt_ctf_private_value_array_append_real_element(
222 struct bt_ctf_private_value *array_obj,
223 double val);
224
225enum bt_ctf_value_status bt_ctf_private_value_array_append_string_element(
226 struct bt_ctf_private_value *array_obj, const char *val);
227
228enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_array_element(
229 struct bt_ctf_private_value *array_obj);
230
231enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_map_element(
232 struct bt_ctf_private_value *array_obj);
233
234enum 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
238struct bt_ctf_private_value *bt_ctf_private_value_map_create(void);
239
240struct 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
243typedef bt_ctf_bool (* bt_ctf_private_value_map_foreach_entry_cb)(const char *key,
244 struct bt_ctf_private_value *object, void *data);
245
246enum 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
250enum 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
254enum bt_ctf_value_status bt_ctf_private_value_map_insert_bool_entry(
255 struct bt_ctf_private_value *map_obj, const char *key, bt_ctf_bool val);
256
257enum 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
260enum 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
263enum 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
267enum 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
270enum 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
273static inline
274const 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
296#endif /* BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H */
This page took 0.026009 seconds and 5 git commands to generate.