Cleanup: remove private babeltrace.h
[babeltrace.git] / src / ctf-writer / values.h
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
27 #include <babeltrace2/types.h>
28
29 #include "common/macros.h"
30
31 struct bt_ctf_value;
32 struct bt_ctf_private_value;
33
34 /**
35 @brief Status codes.
36 */
37 enum 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
48 BT_HIDDEN
49 enum 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
57 extern struct bt_ctf_value *const bt_ctf_value_null;
58
59 enum bt_ctf_value_type {
60 /// Null value object.
61 BT_CTF_VALUE_TYPE_NULL = 0,
62
63 /// Boolean value object (holds #BT_TRUE or #BT_FALSE).
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
82 BT_HIDDEN
83 enum bt_ctf_value_type bt_ctf_value_get_type(const struct bt_ctf_value *object);
84
85 static inline
86 bt_bool bt_ctf_value_is_null(const struct bt_ctf_value *object)
87 {
88 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_NULL;
89 }
90
91 static inline
92 bt_bool bt_ctf_value_is_bool(const struct bt_ctf_value *object)
93 {
94 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_BOOL;
95 }
96
97 static inline
98 bt_bool bt_ctf_value_is_integer(const struct bt_ctf_value *object)
99 {
100 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_INTEGER;
101 }
102
103 static inline
104 bt_bool bt_ctf_value_is_real(const struct bt_ctf_value *object)
105 {
106 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_REAL;
107 }
108
109 static inline
110 bt_bool bt_ctf_value_is_string(const struct bt_ctf_value *object)
111 {
112 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_STRING;
113 }
114
115 static inline
116 bt_bool bt_ctf_value_is_array(const struct bt_ctf_value *object)
117 {
118 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_ARRAY;
119 }
120
121 static inline
122 bt_bool bt_ctf_value_is_map(const struct bt_ctf_value *object)
123 {
124 return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_MAP;
125 }
126
127 BT_HIDDEN
128 enum bt_ctf_value_status bt_ctf_value_copy(struct bt_ctf_private_value **copy,
129 const struct bt_ctf_value *object);
130
131 BT_HIDDEN
132 bt_bool bt_ctf_value_compare(const struct bt_ctf_value *object_a,
133 const struct bt_ctf_value *object_b);
134
135 BT_HIDDEN
136 bt_bool bt_ctf_value_bool_get(const struct bt_ctf_value *bool_obj);
137
138 BT_HIDDEN
139 int64_t bt_ctf_value_integer_get(const struct bt_ctf_value *integer_obj);
140
141 BT_HIDDEN
142 double bt_ctf_value_real_get(const struct bt_ctf_value *real_obj);
143
144 BT_HIDDEN
145 const char *bt_ctf_value_string_get(const struct bt_ctf_value *string_obj);
146
147 BT_HIDDEN
148 uint64_t bt_ctf_value_array_get_size(const struct bt_ctf_value *array_obj);
149
150 static inline
151 bt_bool bt_ctf_value_array_is_empty(const struct bt_ctf_value *array_obj)
152 {
153 return bt_ctf_value_array_get_size(array_obj) == 0;
154 }
155
156 BT_HIDDEN
157 struct bt_ctf_value *bt_ctf_value_array_borrow_element_by_index(
158 const struct bt_ctf_value *array_obj, uint64_t index);
159
160 BT_HIDDEN
161 uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value *map_obj);
162
163 static inline
164 bt_bool bt_ctf_value_map_is_empty(const struct bt_ctf_value *map_obj)
165 {
166 return bt_ctf_value_map_get_size(map_obj) == 0;
167 }
168
169 BT_HIDDEN
170 struct bt_ctf_value *bt_ctf_value_map_borrow_entry_value(
171 const struct bt_ctf_value *map_obj, const char *key);
172
173 typedef bt_bool (* bt_ctf_value_map_foreach_entry_cb)(const char *key,
174 struct bt_ctf_value *object, void *data);
175
176 BT_HIDDEN
177 enum 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
181 BT_HIDDEN
182 bt_bool bt_ctf_value_map_has_entry(const struct bt_ctf_value *map_obj,
183 const char *key);
184
185 BT_HIDDEN
186 enum 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
192 struct bt_ctf_value;
193 struct bt_ctf_private_value;
194
195 extern struct bt_ctf_private_value *const bt_ctf_private_value_null;
196
197 static inline
198 struct 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
204 BT_HIDDEN
205 struct bt_ctf_private_value *bt_ctf_private_value_bool_create(void);
206
207 BT_HIDDEN
208 struct bt_ctf_private_value *bt_ctf_private_value_bool_create_init(bt_bool val);
209
210 BT_HIDDEN
211 void bt_ctf_private_value_bool_set(struct bt_ctf_private_value *bool_obj,
212 bt_bool val);
213
214 BT_HIDDEN
215 struct bt_ctf_private_value *bt_ctf_private_value_integer_create(void);
216
217 BT_HIDDEN
218 struct bt_ctf_private_value *bt_ctf_private_value_integer_create_init(
219 int64_t val);
220
221 BT_HIDDEN
222 void bt_ctf_private_value_integer_set(
223 struct bt_ctf_private_value *integer_obj, int64_t val);
224
225 BT_HIDDEN
226 struct bt_ctf_private_value *bt_ctf_private_value_real_create(void);
227
228 BT_HIDDEN
229 struct bt_ctf_private_value *bt_ctf_private_value_real_create_init(double val);
230
231 BT_HIDDEN
232 void bt_ctf_private_value_real_set(
233 struct bt_ctf_private_value *real_obj, double val);
234
235 BT_HIDDEN
236 struct bt_ctf_private_value *bt_ctf_private_value_string_create(void);
237
238 BT_HIDDEN
239 struct bt_ctf_private_value *bt_ctf_private_value_string_create_init(
240 const char *val);
241
242 BT_HIDDEN
243 enum bt_ctf_value_status bt_ctf_private_value_string_set(
244 struct bt_ctf_private_value *string_obj,
245 const char *val);
246
247 BT_HIDDEN
248 struct bt_ctf_private_value *bt_ctf_private_value_array_create(void);
249
250 BT_HIDDEN
251 struct 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
254 BT_HIDDEN
255 enum 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
259 BT_HIDDEN
260 enum bt_ctf_value_status bt_ctf_private_value_array_append_bool_element(
261 struct bt_ctf_private_value *array_obj,
262 bt_bool val);
263
264 BT_HIDDEN
265 enum 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
269 BT_HIDDEN
270 enum bt_ctf_value_status bt_ctf_private_value_array_append_real_element(
271 struct bt_ctf_private_value *array_obj,
272 double val);
273
274 BT_HIDDEN
275 enum bt_ctf_value_status bt_ctf_private_value_array_append_string_element(
276 struct bt_ctf_private_value *array_obj, const char *val);
277
278 BT_HIDDEN
279 enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_array_element(
280 struct bt_ctf_private_value *array_obj);
281
282 BT_HIDDEN
283 enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_map_element(
284 struct bt_ctf_private_value *array_obj);
285
286 BT_HIDDEN
287 enum 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
291 BT_HIDDEN
292 struct bt_ctf_private_value *bt_ctf_private_value_map_create(void);
293
294 BT_HIDDEN
295 struct 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
298 typedef bt_bool (* bt_ctf_private_value_map_foreach_entry_cb)(const char *key,
299 struct bt_ctf_private_value *object, void *data);
300
301 BT_HIDDEN
302 enum 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
306 BT_HIDDEN
307 enum 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
311 BT_HIDDEN
312 enum bt_ctf_value_status bt_ctf_private_value_map_insert_bool_entry(
313 struct bt_ctf_private_value *map_obj, const char *key, bt_bool val);
314
315 BT_HIDDEN
316 enum 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
319 BT_HIDDEN
320 enum 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
323 BT_HIDDEN
324 enum 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
328 BT_HIDDEN
329 enum 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
332 BT_HIDDEN
333 enum 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
336 static inline
337 const 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
359 #endif /* BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H */
This page took 0.036064 seconds and 4 git commands to generate.