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