Commit | Line | Data |
---|---|---|
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 | |
29 | struct bt_ctf_value; | |
30 | struct bt_ctf_private_value; | |
31 | ||
32 | /** | |
33 | @brief Status codes. | |
34 | */ | |
35 | enum 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 | ||
46 | BT_HIDDEN | |
47 | enum 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 | 55 | extern struct bt_ctf_value *const bt_ctf_value_null; |
e1e02a22 PP |
56 | |
57 | enum 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 | ||
80 | BT_HIDDEN | |
81 | enum bt_ctf_value_type bt_ctf_value_get_type(const struct bt_ctf_value *object); | |
82 | ||
83 | static inline | |
84 | bt_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 | ||
89 | static inline | |
90 | bt_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 | ||
95 | static inline | |
96 | bt_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 | ||
101 | static inline | |
102 | bt_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 | ||
107 | static inline | |
108 | bt_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 | ||
113 | static inline | |
114 | bt_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 | ||
119 | static inline | |
120 | bt_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 | ||
125 | BT_HIDDEN | |
126 | enum bt_ctf_value_status bt_ctf_value_copy(struct bt_ctf_private_value **copy, | |
127 | const struct bt_ctf_value *object); | |
128 | ||
129 | BT_HIDDEN | |
130 | bt_bool bt_ctf_value_compare(const struct bt_ctf_value *object_a, | |
131 | const struct bt_ctf_value *object_b); | |
132 | ||
133 | BT_HIDDEN | |
134 | bt_bool bt_ctf_value_bool_get(const struct bt_ctf_value *bool_obj); | |
135 | ||
136 | BT_HIDDEN | |
137 | int64_t bt_ctf_value_integer_get(const struct bt_ctf_value *integer_obj); | |
138 | ||
139 | BT_HIDDEN | |
140 | double bt_ctf_value_real_get(const struct bt_ctf_value *real_obj); | |
141 | ||
142 | BT_HIDDEN | |
143 | const char *bt_ctf_value_string_get(const struct bt_ctf_value *string_obj); | |
144 | ||
145 | BT_HIDDEN | |
146 | uint64_t bt_ctf_value_array_get_size(const struct bt_ctf_value *array_obj); | |
147 | ||
148 | static inline | |
149 | bt_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 | ||
154 | BT_HIDDEN | |
155 | struct bt_ctf_value *bt_ctf_value_array_borrow_element_by_index( | |
156 | const struct bt_ctf_value *array_obj, uint64_t index); | |
157 | ||
158 | BT_HIDDEN | |
159 | uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value *map_obj); | |
160 | ||
161 | static inline | |
162 | bt_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 | ||
167 | BT_HIDDEN | |
168 | struct bt_ctf_value *bt_ctf_value_map_borrow_entry_value( | |
169 | const struct bt_ctf_value *map_obj, const char *key); | |
170 | ||
171 | typedef bt_bool (* bt_ctf_value_map_foreach_entry_cb)(const char *key, | |
172 | struct bt_ctf_value *object, void *data); | |
173 | ||
174 | BT_HIDDEN | |
175 | enum 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 | ||
179 | BT_HIDDEN | |
180 | bt_bool bt_ctf_value_map_has_entry(const struct bt_ctf_value *map_obj, | |
181 | const char *key); | |
182 | ||
183 | BT_HIDDEN | |
184 | enum 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 | ||
190 | struct bt_ctf_value; | |
191 | struct bt_ctf_private_value; | |
192 | ||
b78363ea | 193 | extern struct bt_ctf_private_value *const bt_ctf_private_value_null; |
e1e02a22 PP |
194 | |
195 | static inline | |
196 | struct 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 | ||
202 | BT_HIDDEN | |
203 | struct bt_ctf_private_value *bt_ctf_private_value_bool_create(void); | |
204 | ||
205 | BT_HIDDEN | |
206 | struct bt_ctf_private_value *bt_ctf_private_value_bool_create_init(bt_bool val); | |
207 | ||
208 | BT_HIDDEN | |
209 | void bt_ctf_private_value_bool_set(struct bt_ctf_private_value *bool_obj, | |
210 | bt_bool val); | |
211 | ||
212 | BT_HIDDEN | |
213 | struct bt_ctf_private_value *bt_ctf_private_value_integer_create(void); | |
214 | ||
215 | BT_HIDDEN | |
216 | struct bt_ctf_private_value *bt_ctf_private_value_integer_create_init( | |
217 | int64_t val); | |
218 | ||
219 | BT_HIDDEN | |
220 | void bt_ctf_private_value_integer_set( | |
221 | struct bt_ctf_private_value *integer_obj, int64_t val); | |
222 | ||
223 | BT_HIDDEN | |
224 | struct bt_ctf_private_value *bt_ctf_private_value_real_create(void); | |
225 | ||
226 | BT_HIDDEN | |
227 | struct bt_ctf_private_value *bt_ctf_private_value_real_create_init(double val); | |
228 | ||
229 | BT_HIDDEN | |
230 | void bt_ctf_private_value_real_set( | |
231 | struct bt_ctf_private_value *real_obj, double val); | |
232 | ||
233 | BT_HIDDEN | |
234 | struct bt_ctf_private_value *bt_ctf_private_value_string_create(void); | |
235 | ||
236 | BT_HIDDEN | |
237 | struct bt_ctf_private_value *bt_ctf_private_value_string_create_init( | |
238 | const char *val); | |
239 | ||
240 | BT_HIDDEN | |
241 | enum bt_ctf_value_status bt_ctf_private_value_string_set( | |
242 | struct bt_ctf_private_value *string_obj, | |
243 | const char *val); | |
244 | ||
245 | BT_HIDDEN | |
246 | struct bt_ctf_private_value *bt_ctf_private_value_array_create(void); | |
247 | ||
248 | BT_HIDDEN | |
249 | struct 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 | ||
252 | BT_HIDDEN | |
253 | enum 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 | ||
257 | BT_HIDDEN | |
258 | enum 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 | ||
262 | BT_HIDDEN | |
263 | enum 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 | ||
267 | BT_HIDDEN | |
268 | enum bt_ctf_value_status bt_ctf_private_value_array_append_real_element( | |
269 | struct bt_ctf_private_value *array_obj, | |
270 | double val); | |
271 | ||
272 | BT_HIDDEN | |
273 | enum bt_ctf_value_status bt_ctf_private_value_array_append_string_element( | |
274 | struct bt_ctf_private_value *array_obj, const char *val); | |
275 | ||
276 | BT_HIDDEN | |
277 | enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_array_element( | |
278 | struct bt_ctf_private_value *array_obj); | |
279 | ||
280 | BT_HIDDEN | |
281 | enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_map_element( | |
282 | struct bt_ctf_private_value *array_obj); | |
283 | ||
284 | BT_HIDDEN | |
285 | enum 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 | ||
289 | BT_HIDDEN | |
290 | struct bt_ctf_private_value *bt_ctf_private_value_map_create(void); | |
291 | ||
292 | BT_HIDDEN | |
293 | struct 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 | ||
296 | typedef bt_bool (* bt_ctf_private_value_map_foreach_entry_cb)(const char *key, | |
297 | struct bt_ctf_private_value *object, void *data); | |
298 | ||
299 | BT_HIDDEN | |
300 | enum 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 | ||
304 | BT_HIDDEN | |
305 | enum 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 | ||
309 | BT_HIDDEN | |
310 | enum 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 | ||
313 | BT_HIDDEN | |
314 | enum 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 | ||
317 | BT_HIDDEN | |
318 | enum 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 | ||
321 | BT_HIDDEN | |
322 | enum 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 | ||
326 | BT_HIDDEN | |
327 | enum 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 | ||
330 | BT_HIDDEN | |
331 | enum 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 |
334 | static inline |
335 | const 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 */ |