Commit | Line | Data |
---|---|---|
2e33ac5a PP |
1 | #ifndef BABELTRACE_CTF_IR_FIELD_TYPES_H |
2 | #define BABELTRACE_CTF_IR_FIELD_TYPES_H | |
adc315b8 JG |
3 | |
4 | /* | |
2e33ac5a | 5 | * BabelTrace - CTF IR: Event field types |
adc315b8 | 6 | * |
de9dd397 | 7 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
adc315b8 JG |
8 | * |
9 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
10 | * | |
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
12 | * of this software and associated documentation files (the "Software"), to deal | |
13 | * in the Software without restriction, including without limitation the rights | |
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
15 | * copies of the Software, and to permit persons to whom the Software is | |
16 | * furnished to do so, subject to the following conditions: | |
17 | * | |
18 | * The above copyright notice and this permission notice shall be included in | |
19 | * all copies or substantial portions of the Software. | |
20 | * | |
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
27 | * SOFTWARE. | |
28 | * | |
29 | * The Common Trace Format (CTF) Specification is available at | |
30 | * http://www.efficios.com/ctf | |
31 | */ | |
32 | ||
094ff7c0 PP |
33 | /* For bt_get() */ |
34 | #include <babeltrace/ref.h> | |
35 | ||
9d408fca | 36 | /* For bt_bool */ |
c14d64fa | 37 | #include <babeltrace/types.h> |
9d408fca | 38 | |
adc315b8 | 39 | #include <stdint.h> |
c3c35de4 | 40 | #include <stddef.h> |
adc315b8 JG |
41 | |
42 | #ifdef __cplusplus | |
43 | extern "C" { | |
44 | #endif | |
45 | ||
78c8ab4f PP |
46 | /** |
47 | @defgroup ctfirfieldtypes CTF IR field types | |
48 | @ingroup ctfir | |
49 | @brief CTF IR field types. | |
50 | ||
51 | @code | |
52 | #include <babeltrace/ctf-ir/field-types.h> | |
53 | @endcode | |
54 | ||
55 | A CTF IR <strong><em>field type</em></strong> is a field type that you | |
4089d5a6 | 56 | can use to create concrete @fields. |
78c8ab4f | 57 | |
4089d5a6 | 58 | You can create a @field object from a CTF IR field type object |
50842bdc | 59 | with bt_field_create(). |
78c8ab4f PP |
60 | |
61 | In the CTF IR hierarchy, you can set the root field types of three | |
62 | objects: | |
63 | ||
64 | - \ref ctfirtraceclass | |
3dca2276 | 65 | - Trace packet header field type: bt_trace_set_packet_header_field_type(). |
78c8ab4f PP |
66 | - \ref ctfirstreamclass |
67 | - Stream packet context field type: | |
3dca2276 | 68 | bt_stream_class_set_packet_context_field_type(). |
78c8ab4f | 69 | - Stream event header field type: |
3dca2276 | 70 | bt_stream_class_set_event_header_field_type(). |
78c8ab4f | 71 | - Stream event context field type: |
3dca2276 | 72 | bt_stream_class_set_event_context_field_type(). |
78c8ab4f | 73 | - \ref ctfireventclass |
3dca2276 PP |
74 | - Event context field type: bt_event_class_set_context_field_type(). |
75 | - Event payload field type: bt_event_class_set_payload_field_type(). | |
78c8ab4f PP |
76 | |
77 | As of Babeltrace \btversion, those six previous "root" field types | |
4089d5a6 | 78 | \em must be @structft objects. |
78c8ab4f | 79 | |
4089d5a6 PP |
80 | If, at any level within a given root field type, you add a @seqft or a |
81 | @varft, you do not need to specify its associated length | |
78c8ab4f | 82 | or tag field type: the length or tag string is enough for the Babeltrace |
4089d5a6 | 83 | system to resolve the needed field type depending on where this |
78c8ab4f PP |
84 | dynamic field type is located within the whole hierarchy. It is |
85 | guaranteed that this automatic resolving is performed for all the field | |
86 | types contained in a given | |
87 | \link ctfirstreamclass CTF IR stream class\endlink (and in its | |
88 | children \link ctfireventclass CTF IR event classes\endlink) once you | |
89 | add it to a \link ctfirtraceclass CTF IR trace class\endlink with | |
50842bdc | 90 | bt_trace_add_stream_class(). Once a stream class is the child of |
78c8ab4f PP |
91 | a trace class, this automatic resolving is performed for the field |
92 | types of an event class when you add it with | |
50842bdc | 93 | bt_stream_class_add_event_class(). If the system cannot find a path |
78c8ab4f PP |
94 | to a field in the hierarchy for a dynamic field type, the adding |
95 | function fails. | |
96 | ||
97 | The standard CTF field types are: | |
98 | ||
99 | <table> | |
100 | <tr> | |
101 | <th>Type ID | |
102 | <th>CTF IR field type | |
103 | <th>CTF IR field which you can create from this field type | |
104 | </tr> | |
105 | <tr> | |
50842bdc | 106 | <td>#BT_FIELD_TYPE_ID_INTEGER |
78c8ab4f PP |
107 | <td>\ref ctfirintfieldtype |
108 | <td>\ref ctfirintfield | |
109 | </tr> | |
110 | <tr> | |
50842bdc | 111 | <td>#BT_FIELD_TYPE_ID_FLOAT |
78c8ab4f PP |
112 | <td>\ref ctfirfloatfieldtype |
113 | <td>\ref ctfirfloatfield | |
114 | </tr> | |
115 | <tr> | |
50842bdc | 116 | <td>#BT_FIELD_TYPE_ID_ENUM |
78c8ab4f PP |
117 | <td>\ref ctfirenumfieldtype |
118 | <td>\ref ctfirenumfield | |
119 | </tr> | |
120 | <tr> | |
50842bdc | 121 | <td>#BT_FIELD_TYPE_ID_STRING |
78c8ab4f PP |
122 | <td>\ref ctfirstringfieldtype |
123 | <td>\ref ctfirstringfield | |
124 | </tr> | |
125 | <tr> | |
50842bdc | 126 | <td>#BT_FIELD_TYPE_ID_STRUCT |
78c8ab4f PP |
127 | <td>\ref ctfirstructfieldtype |
128 | <td>\ref ctfirstructfield | |
129 | </tr> | |
130 | <tr> | |
50842bdc | 131 | <td>#BT_FIELD_TYPE_ID_ARRAY |
78c8ab4f PP |
132 | <td>\ref ctfirarrayfieldtype |
133 | <td>\ref ctfirarrayfield | |
134 | </tr> | |
135 | <tr> | |
50842bdc | 136 | <td>#BT_FIELD_TYPE_ID_SEQUENCE |
78c8ab4f PP |
137 | <td>\ref ctfirseqfieldtype |
138 | <td>\ref ctfirseqfield | |
139 | </tr> | |
140 | <tr> | |
50842bdc | 141 | <td>#BT_FIELD_TYPE_ID_VARIANT |
78c8ab4f PP |
142 | <td>\ref ctfirvarfieldtype |
143 | <td>\ref ctfirvarfield | |
144 | </tr> | |
145 | </table> | |
146 | ||
147 | Each field type has its own <strong>type ID</strong> (see | |
50842bdc PP |
148 | #bt_field_type_id). You get the type ID of a field type object |
149 | with bt_field_type_get_type_id(). | |
78c8ab4f | 150 | |
50842bdc | 151 | You can get a deep copy of a field type with bt_field_type_copy(). |
78c8ab4f PP |
152 | This function resets, in the field type copy, the resolved field type |
153 | of the dynamic field types. The automatic resolving can be done again | |
50842bdc PP |
154 | when you eventually call bt_event_create(), |
155 | bt_stream_class_add_event_class(), or | |
156 | bt_trace_add_stream_class(). | |
78c8ab4f | 157 | |
50842bdc | 158 | You \em must always use bt_field_type_compare() to compare two |
78c8ab4f PP |
159 | field types. Since some parts of the Babeltrace system can copy field |
160 | types behind the scenes, you \em cannot rely on a simple field type | |
161 | pointer comparison. | |
162 | ||
163 | As with any Babeltrace object, CTF IR field type objects have | |
164 | <a href="https://en.wikipedia.org/wiki/Reference_counting">reference | |
165 | counts</a>. See \ref refs to learn more about the reference counting | |
166 | management of Babeltrace objects. | |
167 | ||
168 | The following functions can \em freeze field type objects: | |
169 | ||
50842bdc PP |
170 | - bt_field_create() freezes its field type parameter. |
171 | - bt_stream_class_add_event_class(), if its | |
78c8ab4f PP |
172 | \link ctfirstreamclass CTF IR stream class\endlink parameter has a |
173 | \link ctfirtraceclass CTF IR trace class\endlink parent, freezes | |
174 | the root field types of its | |
175 | \link ctfireventclass CTF IR event class\endlink parameter. | |
50842bdc | 176 | - bt_trace_add_stream_class() freezes the root field types of the |
78c8ab4f PP |
177 | whole trace class hierarchy (trace class, children stream classes, |
178 | and their children event classes). | |
50842bdc | 179 | - bt_writer_create_stream() freezes the root field types of the |
78c8ab4f | 180 | whole CTF writer's trace class hierarchy. |
50842bdc | 181 | - bt_event_create() freezes the root field types of its event class |
78c8ab4f PP |
182 | parameter and of ther parent stream class of this event class. |
183 | ||
18fcd1c9 PP |
184 | You cannot modify a frozen field type object: it is considered |
185 | immutable, except for \link refs reference counting\endlink. | |
186 | ||
78c8ab4f | 187 | @sa ctfirfields |
bb8c17e0 | 188 | @sa \ref ctfirfieldtypesexamples "Examples" |
78c8ab4f PP |
189 | |
190 | @file | |
10a876cd | 191 | @brief CTF IR field types type and functions. |
78c8ab4f PP |
192 | @sa ctfirfieldtypes |
193 | ||
194 | @addtogroup ctfirfieldtypes | |
195 | @{ | |
196 | */ | |
197 | ||
198 | /** | |
50842bdc | 199 | @struct bt_field_type |
78c8ab4f PP |
200 | @brief A CTF IR field type. |
201 | @sa ctfirfieldtypes | |
202 | */ | |
50842bdc PP |
203 | struct bt_field_type; |
204 | struct bt_event_class; | |
205 | struct bt_event; | |
206 | struct bt_field; | |
207 | struct bt_field_path; | |
208 | struct bt_field_type_enumeration_mapping_iterator; | |
78c8ab4f PP |
209 | |
210 | /** | |
211 | @brief CTF scope. | |
212 | */ | |
50842bdc | 213 | enum bt_scope { |
78c8ab4f | 214 | /// Unknown, used for errors. |
50842bdc | 215 | BT_SCOPE_UNKNOWN = -1, |
78c8ab4f PP |
216 | |
217 | /// Trace packet header. | |
50842bdc | 218 | BT_SCOPE_TRACE_PACKET_HEADER = 1, |
78c8ab4f PP |
219 | |
220 | /// Stream packet context. | |
50842bdc | 221 | BT_SCOPE_STREAM_PACKET_CONTEXT = 2, |
78c8ab4f PP |
222 | |
223 | /// Stream event header. | |
50842bdc | 224 | BT_SCOPE_STREAM_EVENT_HEADER = 3, |
78c8ab4f PP |
225 | |
226 | /// Stream event context. | |
50842bdc | 227 | BT_SCOPE_STREAM_EVENT_CONTEXT = 4, |
78c8ab4f PP |
228 | |
229 | /// Event context. | |
50842bdc | 230 | BT_SCOPE_EVENT_CONTEXT = 5, |
78c8ab4f PP |
231 | |
232 | /// Event payload. | |
50842bdc | 233 | BT_SCOPE_EVENT_PAYLOAD = 6, |
78c8ab4f PP |
234 | |
235 | /// @cond DOCUMENT | |
50842bdc PP |
236 | BT_SCOPE_ENV = 0, |
237 | BT_SCOPE_EVENT_FIELDS = 6, | |
78c8ab4f PP |
238 | /// @endcond |
239 | }; | |
240 | ||
241 | /** | |
242 | @name Type information | |
243 | @{ | |
244 | */ | |
245 | ||
246 | /** | |
4089d5a6 | 247 | @brief Type ID of a @ft. |
78c8ab4f | 248 | */ |
50842bdc | 249 | enum bt_field_type_id { |
78c8ab4f | 250 | /// Unknown, used for errors. |
50842bdc | 251 | BT_FIELD_TYPE_ID_UNKNOWN = -1, |
78c8ab4f PP |
252 | |
253 | /// \ref ctfirintfieldtype | |
50842bdc | 254 | BT_FIELD_TYPE_ID_INTEGER = 0, |
78c8ab4f PP |
255 | |
256 | /// \ref ctfirfloatfieldtype | |
50842bdc | 257 | BT_FIELD_TYPE_ID_FLOAT = 1, |
78c8ab4f PP |
258 | |
259 | /// \ref ctfirenumfieldtype | |
50842bdc | 260 | BT_FIELD_TYPE_ID_ENUM = 2, |
78c8ab4f PP |
261 | |
262 | /// \ref ctfirstringfieldtype | |
50842bdc | 263 | BT_FIELD_TYPE_ID_STRING = 3, |
78c8ab4f PP |
264 | |
265 | /// \ref ctfirstructfieldtype | |
50842bdc | 266 | BT_FIELD_TYPE_ID_STRUCT = 4, |
78c8ab4f | 267 | |
78c8ab4f | 268 | /// \ref ctfirarrayfieldtype |
50842bdc | 269 | BT_FIELD_TYPE_ID_ARRAY = 6, |
78c8ab4f PP |
270 | |
271 | /// \ref ctfirseqfieldtype | |
50842bdc | 272 | BT_FIELD_TYPE_ID_SEQUENCE = 7, |
9a19a512 | 273 | |
78c8ab4f | 274 | /// \ref ctfirvarfieldtype |
50842bdc | 275 | BT_FIELD_TYPE_ID_VARIANT = 5, |
78c8ab4f PP |
276 | |
277 | /// Number of enumeration entries. | |
50842bdc | 278 | BT_FIELD_TYPE_ID_NR = 8, |
adc315b8 JG |
279 | }; |
280 | ||
78c8ab4f | 281 | /** |
4089d5a6 | 282 | @brief Returns the type ID of the @ft \p field_type. |
78c8ab4f PP |
283 | |
284 | @param[in] field_type Field type of which to get the type ID. | |
285 | @returns Type ID of \p field_type, | |
50842bdc | 286 | or #BT_FIELD_TYPE_ID_UNKNOWN on error. |
78c8ab4f PP |
287 | |
288 | @prenotnull{field_type} | |
289 | @postrefcountsame{field_type} | |
290 | ||
50842bdc PP |
291 | @sa #bt_field_type_id: CTF IR field type ID. |
292 | @sa bt_field_type_is_integer(): Returns whether or not a given | |
4089d5a6 | 293 | field type is a @intft. |
50842bdc | 294 | @sa bt_field_type_is_floating_point(): Returns whether or not a |
4089d5a6 | 295 | given field type is a @floatft. |
50842bdc | 296 | @sa bt_field_type_is_enumeration(): Returns whether or not a given |
4089d5a6 | 297 | field type is a @enumft. |
50842bdc | 298 | @sa bt_field_type_is_string(): Returns whether or not a given |
4089d5a6 | 299 | field type is a @stringft. |
50842bdc | 300 | @sa bt_field_type_is_structure(): Returns whether or not a given |
4089d5a6 | 301 | field type is a @structft. |
50842bdc | 302 | @sa bt_field_type_is_array(): Returns whether or not a given |
4089d5a6 | 303 | field type is a @arrayft. |
50842bdc | 304 | @sa bt_field_type_is_sequence(): Returns whether or not a given |
4089d5a6 | 305 | field type is a @seqft. |
50842bdc | 306 | @sa bt_field_type_is_variant(): Returns whether or not a given |
4089d5a6 | 307 | field type is a @varft. |
78c8ab4f | 308 | */ |
50842bdc PP |
309 | extern enum bt_field_type_id bt_field_type_get_type_id( |
310 | struct bt_field_type *field_type); | |
78c8ab4f PP |
311 | |
312 | /** | |
4089d5a6 | 313 | @brief Returns whether or not the @ft \p field_type is a @intft. |
78c8ab4f PP |
314 | |
315 | @param[in] field_type Field type to check (can be \c NULL). | |
c14d64fa PP |
316 | @returns #BT_TRUE if \p field_type is an integer field type, |
317 | or #BT_FALSE otherwise (including if \p field_type is | |
78c8ab4f PP |
318 | \c NULL). |
319 | ||
320 | @prenotnull{field_type} | |
321 | @postrefcountsame{field_type} | |
322 | ||
50842bdc | 323 | @sa bt_field_type_get_type_id(): Returns the type ID of a given |
78c8ab4f PP |
324 | field type. |
325 | */ | |
13d80369 PP |
326 | static inline |
327 | bt_bool bt_field_type_is_integer(struct bt_field_type *field_type) | |
328 | { | |
329 | return bt_field_type_get_type_id(field_type) == | |
330 | BT_FIELD_TYPE_ID_INTEGER; | |
331 | } | |
78c8ab4f PP |
332 | |
333 | /** | |
4089d5a6 | 334 | @brief Returns whether or not the @ft \p field_type is a @floatft. |
78c8ab4f PP |
335 | |
336 | @param[in] field_type Field type to check (can be \c NULL). | |
c14d64fa PP |
337 | @returns #BT_TRUE if \p field_type is a floating point |
338 | #BT_FALSE field type, | |
78c8ab4f PP |
339 | or 0 otherwise (including if \p field_type is |
340 | \c NULL). | |
341 | ||
342 | @postrefcountsame{field_type} | |
343 | ||
50842bdc | 344 | @sa bt_field_type_get_type_id(): Returns the type ID of a given |
78c8ab4f PP |
345 | field type. |
346 | */ | |
13d80369 PP |
347 | static inline |
348 | bt_bool bt_field_type_is_floating_point(struct bt_field_type *field_type) | |
349 | { | |
350 | return bt_field_type_get_type_id(field_type) == BT_FIELD_TYPE_ID_FLOAT; | |
351 | } | |
78c8ab4f PP |
352 | |
353 | /** | |
4089d5a6 | 354 | @brief Returns whether or not the @ft \p field_type is a @enumft. |
78c8ab4f PP |
355 | |
356 | @param[in] field_type Field type to check (can be \c NULL). | |
c14d64fa PP |
357 | @returns #BT_TRUE if \p field_type is an enumeration field type, |
358 | or #BT_FALSE otherwise (including if \p field_type is | |
78c8ab4f PP |
359 | \c NULL). |
360 | ||
361 | @postrefcountsame{field_type} | |
362 | ||
50842bdc | 363 | @sa bt_field_type_get_type_id(): Returns the type ID of a given |
78c8ab4f PP |
364 | field type. |
365 | */ | |
13d80369 PP |
366 | static inline |
367 | bt_bool bt_field_type_is_enumeration(struct bt_field_type *field_type) | |
368 | { | |
369 | return bt_field_type_get_type_id(field_type) == BT_FIELD_TYPE_ID_ENUM; | |
370 | } | |
78c8ab4f PP |
371 | |
372 | /** | |
4089d5a6 | 373 | @brief Returns whether or not the @ft \p field_type is a @stringft. |
78c8ab4f PP |
374 | |
375 | @param[in] field_type Field type to check (can be \c NULL). | |
c14d64fa PP |
376 | @returns #BT_TRUE if \p field_type is a string field type, |
377 | or #BT_FALSE otherwise (including if \p field_type is | |
78c8ab4f PP |
378 | \c NULL). |
379 | ||
380 | @postrefcountsame{field_type} | |
381 | ||
50842bdc | 382 | @sa bt_field_type_get_type_id(): Returns the type ID of a given |
78c8ab4f PP |
383 | field type. |
384 | */ | |
13d80369 PP |
385 | static inline |
386 | bt_bool bt_field_type_is_string(struct bt_field_type *field_type) | |
387 | { | |
388 | return bt_field_type_get_type_id(field_type) == BT_FIELD_TYPE_ID_STRING; | |
389 | } | |
78c8ab4f PP |
390 | |
391 | /** | |
4089d5a6 | 392 | @brief Returns whether or not the @ft \p field_type is a @structft. |
78c8ab4f PP |
393 | |
394 | @param[in] field_type Field type to check (can be \c NULL). | |
c14d64fa PP |
395 | @returns #BT_TRUE if \p field_type is a structure field type, |
396 | or #BT_FALSE otherwise (including if \p field_type is | |
78c8ab4f PP |
397 | \c NULL). |
398 | ||
399 | @postrefcountsame{field_type} | |
400 | ||
50842bdc | 401 | @sa bt_field_type_get_type_id(): Returns the type ID of a given |
78c8ab4f PP |
402 | field type. |
403 | */ | |
13d80369 PP |
404 | static inline |
405 | bt_bool bt_field_type_is_structure(struct bt_field_type *field_type) | |
406 | { | |
407 | return bt_field_type_get_type_id(field_type) == BT_FIELD_TYPE_ID_STRUCT; | |
408 | } | |
78c8ab4f PP |
409 | |
410 | /** | |
4089d5a6 | 411 | @brief Returns whether or not the @ft \p field_type is a @arrayft. |
78c8ab4f PP |
412 | |
413 | @param[in] field_type Field type to check (can be \c NULL). | |
c14d64fa PP |
414 | @returns #BT_TRUE if \p field_type is an array field type, |
415 | or #BT_FALSE otherwise (including if \p field_type is | |
78c8ab4f PP |
416 | \c NULL). |
417 | ||
418 | @postrefcountsame{field_type} | |
419 | ||
50842bdc | 420 | @sa bt_field_type_get_type_id(): Returns the type ID of a given |
78c8ab4f PP |
421 | field type. |
422 | */ | |
13d80369 PP |
423 | static inline |
424 | bt_bool bt_field_type_is_array(struct bt_field_type *field_type) | |
425 | { | |
426 | return bt_field_type_get_type_id(field_type) == BT_FIELD_TYPE_ID_ARRAY; | |
427 | } | |
78c8ab4f PP |
428 | |
429 | /** | |
4089d5a6 | 430 | @brief Returns whether or not the @ft \p field_type is a @seqft. |
78c8ab4f PP |
431 | |
432 | @param[in] field_type Field type to check (can be \c NULL). | |
c14d64fa PP |
433 | @returns #BT_TRUE if \p field_type is a sequence field type, |
434 | or #BT_FALSE otherwise (including if \p field_type is | |
78c8ab4f PP |
435 | \c NULL). |
436 | ||
437 | @postrefcountsame{field_type} | |
438 | ||
50842bdc | 439 | @sa bt_field_type_get_type_id(): Returns the type ID of a given |
78c8ab4f PP |
440 | field type. |
441 | */ | |
13d80369 PP |
442 | static inline |
443 | bt_bool bt_field_type_is_sequence(struct bt_field_type *field_type) | |
444 | { | |
445 | return bt_field_type_get_type_id(field_type) == | |
446 | BT_FIELD_TYPE_ID_SEQUENCE; | |
447 | } | |
78c8ab4f PP |
448 | |
449 | /** | |
4089d5a6 | 450 | @brief Returns whether or not the @ft \p field_type is a @varft. |
78c8ab4f PP |
451 | |
452 | @param[in] field_type Field type to check (can be \c NULL). | |
c14d64fa PP |
453 | @returns #BT_TRUE if \p field_type is a variant field type, |
454 | or #BT_FALSE otherwise (including if \p field_type is | |
78c8ab4f PP |
455 | \c NULL). |
456 | ||
457 | @postrefcountsame{field_type} | |
458 | ||
50842bdc | 459 | @sa bt_field_type_get_type_id(): Returns the type ID of a given |
78c8ab4f PP |
460 | field type. |
461 | */ | |
13d80369 PP |
462 | static inline |
463 | bt_bool bt_field_type_is_variant(struct bt_field_type *field_type) | |
464 | { | |
465 | return bt_field_type_get_type_id(field_type) == | |
466 | BT_FIELD_TYPE_ID_VARIANT; | |
467 | } | |
78c8ab4f PP |
468 | |
469 | /** @} */ | |
470 | ||
471 | /** | |
472 | @name Common properties types and functions | |
473 | @{ | |
474 | */ | |
475 | ||
476 | /** | |
477 | @brief <a href="https://en.wikipedia.org/wiki/Endianness">Byte order</a> | |
4089d5a6 | 478 | of a @ft. |
78c8ab4f | 479 | */ |
50842bdc | 480 | enum bt_byte_order { |
78c8ab4f | 481 | /// Unknown, used for errors. |
50842bdc | 482 | BT_BYTE_ORDER_UNKNOWN = -1, |
78c8ab4f | 483 | |
c35a1669 | 484 | /* |
46df6b28 PP |
485 | * Note that native, in the context of the CTF specification, is defined |
486 | * as "the byte order described in the trace" and does not mean that the | |
487 | * host's endianness will be used. | |
c35a1669 | 488 | */ |
78c8ab4f | 489 | /// Native (default) byte order. |
50842bdc | 490 | BT_BYTE_ORDER_NATIVE = 0, |
78c8ab4f | 491 | |
d41cff38 | 492 | /** |
2f4b93cd | 493 | Unspecified byte order; the initial native byte order of a |
d41cff38 PP |
494 | \link ctfirtraceclass CTF IR trace class\endlink. |
495 | */ | |
50842bdc | 496 | BT_BYTE_ORDER_UNSPECIFIED, |
d41cff38 | 497 | |
78c8ab4f | 498 | /// Little-endian. |
50842bdc | 499 | BT_BYTE_ORDER_LITTLE_ENDIAN, |
78c8ab4f PP |
500 | |
501 | /// Big-endian. | |
50842bdc | 502 | BT_BYTE_ORDER_BIG_ENDIAN, |
78c8ab4f PP |
503 | |
504 | /// Network byte order (big-endian). | |
50842bdc | 505 | BT_BYTE_ORDER_NETWORK, |
adc315b8 JG |
506 | }; |
507 | ||
78c8ab4f | 508 | /** |
4089d5a6 | 509 | @brief String encoding of a @ft. |
78c8ab4f | 510 | */ |
50842bdc | 511 | enum bt_string_encoding { |
78c8ab4f | 512 | /// Unknown, used for errors. |
50842bdc | 513 | BT_STRING_ENCODING_UNKNOWN = -1, |
78c8ab4f PP |
514 | |
515 | /// No encoding. | |
50842bdc | 516 | BT_STRING_ENCODING_NONE, |
78c8ab4f PP |
517 | |
518 | /// <a href="https://en.wikipedia.org/wiki/UTF-8">UTF-8</a>. | |
50842bdc | 519 | BT_STRING_ENCODING_UTF8, |
78c8ab4f PP |
520 | |
521 | /// <a href="https://en.wikipedia.org/wiki/ASCII">ASCII</a>. | |
50842bdc | 522 | BT_STRING_ENCODING_ASCII, |
87b41f95 PP |
523 | }; |
524 | ||
78c8ab4f | 525 | /** |
4089d5a6 PP |
526 | @brief Returns the alignment of the @fields described by |
527 | the @ft \p field_type. | |
78c8ab4f PP |
528 | |
529 | @param[in] field_type Field type which describes the | |
530 | fields of which to get the alignment. | |
531 | @returns Alignment of the fields described by | |
532 | \p field_type, or a negative value on error. | |
533 | ||
534 | @prenotnull{field_type} | |
535 | @postrefcountsame{field_type} | |
536 | ||
50842bdc | 537 | @sa bt_field_type_set_alignment(): Sets the alignment |
78c8ab4f PP |
538 | of the fields described by a given field type. |
539 | */ | |
50842bdc PP |
540 | extern int bt_field_type_get_alignment( |
541 | struct bt_field_type *field_type); | |
78c8ab4f PP |
542 | |
543 | /** | |
4089d5a6 PP |
544 | @brief Sets the alignment of the @fields described by the |
545 | @ft \p field_type to \p alignment. | |
78c8ab4f PP |
546 | |
547 | \p alignment \em must be greater than 0 and a power of two. | |
548 | ||
549 | @param[in] field_type Field type which describes the fields of | |
550 | which to set the alignment. | |
551 | @param[in] alignment Alignment of the fields described by | |
552 | \p field_type. | |
553 | @returns 0 on success, or a negative value on error. | |
554 | ||
555 | @prenotnull{field_type} | |
556 | @prehot{field_type} | |
557 | @pre \p alignment is greater than 0 and a power of two. | |
558 | @postrefcountsame{field_type} | |
559 | ||
50842bdc | 560 | @sa bt_field_type_get_alignment(): Returns the alignment of the |
78c8ab4f PP |
561 | fields described by a given field type. |
562 | */ | |
50842bdc | 563 | extern int bt_field_type_set_alignment(struct bt_field_type *field_type, |
78c8ab4f PP |
564 | unsigned int alignment); |
565 | ||
566 | /** | |
4089d5a6 PP |
567 | @brief Returns the byte order of the @fields described by |
568 | the @ft \p field_type. | |
78c8ab4f | 569 | |
4089d5a6 PP |
570 | You can only call this function if \p field_type is a @intft, a |
571 | @floatft, or a @enumft. | |
78c8ab4f PP |
572 | |
573 | @param[in] field_type Field type which describes the | |
574 | fields of which to get the byte order. | |
575 | @returns Byte order of the fields described by | |
50842bdc | 576 | \p field_type, or #BT_BYTE_ORDER_UNKNOWN on |
78c8ab4f PP |
577 | error. |
578 | ||
579 | @prenotnull{field_type} | |
4089d5a6 | 580 | @pre \p field_type is a @intft, a @floatft, or a @enumft. |
78c8ab4f PP |
581 | @postrefcountsame{field_type} |
582 | ||
50842bdc | 583 | @sa bt_field_type_set_byte_order(): Sets the byte order |
78c8ab4f PP |
584 | of the fields described by a given field type. |
585 | */ | |
50842bdc PP |
586 | extern enum bt_byte_order bt_field_type_get_byte_order( |
587 | struct bt_field_type *field_type); | |
78c8ab4f PP |
588 | |
589 | /** | |
4089d5a6 PP |
590 | @brief Sets the byte order of the @fields described by the |
591 | @ft \p field_type to \p byte_order. | |
78c8ab4f PP |
592 | |
593 | If \p field_type is a compound field type, this function also | |
594 | recursively sets the byte order of its children to \p byte_order. | |
595 | ||
596 | @param[in] field_type Field type which describes the fields of | |
597 | which to set the byte order. | |
598 | @param[in] byte_order Alignment of the fields described by | |
599 | \p field_type. | |
600 | @returns 0 on success, or a negative value on error. | |
601 | ||
602 | @prenotnull{field_type} | |
603 | @prehot{field_type} | |
50842bdc PP |
604 | @pre \p byte_order is #BT_BYTE_ORDER_NATIVE, |
605 | #BT_BYTE_ORDER_LITTLE_ENDIAN, #BT_BYTE_ORDER_BIG_ENDIAN, | |
606 | or #BT_BYTE_ORDER_NETWORK. | |
4089d5a6 | 607 | @postrefcountsame{field_type} |
78c8ab4f | 608 | |
50842bdc | 609 | @sa bt_field_type_get_byte_order(): Returns the byte order of the |
78c8ab4f PP |
610 | fields described by a given field type. |
611 | */ | |
50842bdc PP |
612 | extern int bt_field_type_set_byte_order( |
613 | struct bt_field_type *field_type, | |
614 | enum bt_byte_order byte_order); | |
78c8ab4f PP |
615 | |
616 | /** @} */ | |
617 | ||
618 | /** | |
619 | @name Utility functions | |
620 | @{ | |
621 | */ | |
622 | ||
623 | /** | |
4089d5a6 | 624 | @brief Returns whether or not the @ft \p field_type_a |
78c8ab4f PP |
625 | is equivalent to the field type \p field_type_b. |
626 | ||
627 | You \em must use this function to compare two field types: it is not | |
628 | safe to compare two pointer values directly, because, for internal | |
629 | reasons, some parts of the Babeltrace system can copy user field types | |
630 | and discard the original ones. | |
631 | ||
632 | @param[in] field_type_a Field type to compare to \p field_type_b. | |
633 | @param[in] field_type_b Field type to compare to \p field_type_a. | |
634 | @returns 0 if \p field_type_a is equivalent to | |
635 | \p field_type_b, 1 if they are not equivalent, | |
636 | or a negative value on error. | |
637 | ||
638 | @prenotnull{field_type_a} | |
639 | @prenotnull{field_type_b} | |
640 | @postrefcountsame{field_type_a} | |
641 | @postrefcountsame{field_type_b} | |
642 | */ | |
50842bdc PP |
643 | extern int bt_field_type_compare(struct bt_field_type *field_type_a, |
644 | struct bt_field_type *field_type_b); | |
78c8ab4f PP |
645 | |
646 | /** | |
4089d5a6 | 647 | @brief Creates a \em deep copy of the @ft \p field_type. |
78c8ab4f PP |
648 | |
649 | You can copy a frozen field type: the resulting copy is | |
650 | <em>not frozen</em>. | |
651 | ||
4089d5a6 | 652 | This function resets the tag field type of a copied @varft. The |
78c8ab4f PP |
653 | automatic field resolving which some functions of the API perform |
654 | can set it again when the returned field type is used (learn more | |
655 | in the detailed description of this module). | |
656 | ||
657 | @param[in] field_type Field type to copy. | |
658 | @returns Deep copy of \p field_type on success, | |
659 | or \c NULL on error. | |
660 | ||
661 | @prenotnull{field_type} | |
662 | @postrefcountsame{field_type} | |
663 | @postsuccessrefcountret1 | |
63168860 | 664 | @post <strong>On success</strong>, the returned field type is not frozen. |
78c8ab4f | 665 | */ |
50842bdc PP |
666 | extern struct bt_field_type *bt_field_type_copy( |
667 | struct bt_field_type *field_type); | |
78c8ab4f PP |
668 | |
669 | /** @} */ | |
670 | ||
671 | /** @} */ | |
672 | ||
673 | /** | |
674 | @defgroup ctfirintfieldtype CTF IR integer field type | |
675 | @ingroup ctfirfieldtypes | |
676 | @brief CTF IR integer field type. | |
677 | ||
678 | @code | |
679 | #include <babeltrace/ctf-ir/field-types.h> | |
680 | @endcode | |
681 | ||
682 | A CTF IR <strong><em>integer field type</em></strong> is a field type that | |
4089d5a6 | 683 | you can use to create concrete @intfield objects. |
78c8ab4f PP |
684 | |
685 | You can create an integer field type | |
50842bdc | 686 | with bt_field_type_integer_create(). |
78c8ab4f PP |
687 | |
688 | An integer field type has the following properties: | |
689 | ||
690 | <table> | |
691 | <tr> | |
692 | <th>Property | |
693 | <th>Value at creation | |
694 | <th>Getter | |
695 | <th>Setter | |
696 | </tr> | |
697 | <tr> | |
698 | <td>\b Alignment (bits) of the described integer fields | |
699 | <td>1 | |
50842bdc PP |
700 | <td>bt_field_type_get_alignment() |
701 | <td>bt_field_type_set_alignment() | |
78c8ab4f PP |
702 | </tr> |
703 | <tr> | |
704 | <td><strong>Byte order</strong> of the described integer fields | |
50842bdc PP |
705 | <td>#BT_BYTE_ORDER_NATIVE |
706 | <td>bt_field_type_get_byte_order() | |
707 | <td>bt_field_type_set_byte_order() | |
78c8ab4f PP |
708 | </tr> |
709 | <tr> | |
710 | <td><strong>Storage size</strong> (bits) of the described | |
711 | integer fields | |
712 | <td>Specified at creation | |
50842bdc PP |
713 | <td>bt_field_type_integer_get_size() |
714 | <td>bt_field_type_integer_set_size() | |
78c8ab4f PP |
715 | </tr> |
716 | <tr> | |
717 | <td><strong>Signedness</strong> of the described integer fields | |
718 | <td>Unsigned | |
50842bdc PP |
719 | <td>bt_field_type_integer_is_signed() |
720 | <td>bt_field_type_integer_set_is_signed() | |
78c8ab4f PP |
721 | </tr> |
722 | <tr> | |
723 | <td><strong>Preferred display base</strong> of the described | |
724 | integer fields | |
50842bdc PP |
725 | <td>#BT_INTEGER_BASE_DECIMAL |
726 | <td>bt_field_type_integer_get_base() | |
727 | <td>bt_field_type_integer_set_base() | |
78c8ab4f PP |
728 | </tr> |
729 | <tr> | |
730 | <td>\b Encoding of the described integer fields | |
50842bdc PP |
731 | <td>#BT_STRING_ENCODING_NONE |
732 | <td>bt_field_type_integer_get_encoding() | |
733 | <td>bt_field_type_integer_set_encoding() | |
78c8ab4f PP |
734 | </tr> |
735 | <tr> | |
736 | <td><strong>Mapped | |
737 | \link ctfirclockclass CTF IR clock class\endlink</strong> | |
738 | <td>None | |
50842bdc PP |
739 | <td>bt_field_type_integer_get_mapped_clock_class() |
740 | <td>bt_field_type_integer_set_mapped_clock_class() | |
78c8ab4f PP |
741 | </tr> |
742 | </table> | |
743 | ||
744 | @sa ctfirintfield | |
745 | @sa ctfirfieldtypes | |
bb8c17e0 | 746 | @sa \ref ctfirfieldtypesexamples_intfieldtype "Examples" |
78c8ab4f PP |
747 | |
748 | @addtogroup ctfirintfieldtype | |
749 | @{ | |
750 | */ | |
751 | ||
752 | /** | |
4089d5a6 | 753 | @brief Preferred display base (radix) of a @intft. |
78c8ab4f | 754 | */ |
50842bdc | 755 | enum bt_integer_base { |
78c8ab4f | 756 | /// Unknown, used for errors. |
50842bdc | 757 | BT_INTEGER_BASE_UNKNOWN = -1, |
78c8ab4f | 758 | |
d2bd5ad3 | 759 | /// Unspecified by the tracer. |
50842bdc | 760 | BT_INTEGER_BASE_UNSPECIFIED = 0, |
d2bd5ad3 | 761 | |
78c8ab4f | 762 | /// Binary. |
50842bdc | 763 | BT_INTEGER_BASE_BINARY = 2, |
78c8ab4f PP |
764 | |
765 | /// Octal. | |
50842bdc | 766 | BT_INTEGER_BASE_OCTAL = 8, |
78c8ab4f PP |
767 | |
768 | /// Decimal. | |
50842bdc | 769 | BT_INTEGER_BASE_DECIMAL = 10, |
78c8ab4f PP |
770 | |
771 | /// Hexadecimal. | |
50842bdc | 772 | BT_INTEGER_BASE_HEXADECIMAL = 16, |
b011f6b0 PP |
773 | }; |
774 | ||
78c8ab4f | 775 | /** |
4089d5a6 PP |
776 | @brief Creates a default @intft with \p size bits as the storage size |
777 | of the @intfields it describes. | |
78c8ab4f | 778 | |
c3c35de4 JD |
779 | You can change the storage size of the integer fields described by |
780 | the created integer field type later with | |
50842bdc | 781 | bt_field_type_integer_set_size(). |
c3c35de4 | 782 | |
78c8ab4f PP |
783 | @param[in] size Storage size (bits) of the described integer fields. |
784 | @returns Created integer field type, or \c NULL on error. | |
785 | ||
786 | @pre \p size is greater than 0 and lesser than or equal to 64. | |
787 | @postsuccessrefcountret1 | |
788 | */ | |
50842bdc | 789 | extern struct bt_field_type *bt_field_type_integer_create( |
adc315b8 JG |
790 | unsigned int size); |
791 | ||
78c8ab4f | 792 | /** |
4089d5a6 PP |
793 | @brief Returns the storage size, in bits, of the @intfields |
794 | described by the @intft \p int_field_type. | |
78c8ab4f PP |
795 | |
796 | @param[in] int_field_type Integer field type which describes the | |
797 | integer fields of which to get the | |
798 | storage size. | |
799 | @returns Storage size (bits) of the integer | |
800 | fields described by \p int_field_type, | |
801 | or a negative value on error. | |
802 | ||
803 | @prenotnull{int_field_type} | |
804 | @preisintft{int_field_type} | |
805 | @postrefcountsame{int_field_type} | |
c3c35de4 | 806 | |
50842bdc | 807 | @sa bt_field_type_integer_set_size(): Sets the storage size of the |
c3c35de4 | 808 | integer fields described by a given integer field type. |
78c8ab4f | 809 | */ |
50842bdc PP |
810 | extern int bt_field_type_integer_get_size( |
811 | struct bt_field_type *int_field_type); | |
b92ddaaa | 812 | |
c3c35de4 JD |
813 | /** |
814 | @brief Sets the storage size, in bits, of the @intfields described by | |
815 | the @intft \p int_field_type. | |
816 | ||
817 | @param[in] int_field_type Integer field type which describes the | |
818 | integer fields of which to set the | |
819 | storage size. | |
820 | @param[in] size Storage size (bits) of the integer fields | |
821 | described by \p int_field_type. | |
822 | @returns 0 on success, or a negative value on error. | |
823 | ||
824 | @prenotnull{int_field_type} | |
825 | @preisintft{int_field_type} | |
826 | @prehot{int_field_type} | |
827 | @pre \p size is greater than 0 and lesser than or equal to 64. | |
828 | @postrefcountsame{int_field_type} | |
829 | ||
50842bdc | 830 | @sa bt_field_type_integer_get_size(): Returns the storage size of |
c3c35de4 JD |
831 | the integer fields described by a given integer field type. |
832 | */ | |
50842bdc PP |
833 | extern int bt_field_type_integer_set_size( |
834 | struct bt_field_type *int_field_type, unsigned int size); | |
c3c35de4 | 835 | |
78c8ab4f | 836 | /** |
4089d5a6 PP |
837 | @brief Returns whether or not the @intfields described by the @intft |
838 | \p int_field_type are signed. | |
78c8ab4f PP |
839 | |
840 | @param[in] int_field_type Integer field type which describes the | |
841 | integer fields of which to get the | |
842 | signedness. | |
c14d64fa PP |
843 | @returns #BT_TRUE if the integer fields described by |
844 | \p int_field_type are signed, #BT_FALSE if they | |
845 | are unsigned. | |
78c8ab4f PP |
846 | |
847 | @prenotnull{int_field_type} | |
848 | @preisintft{int_field_type} | |
849 | @postrefcountsame{int_field_type} | |
850 | ||
50842bdc | 851 | @sa bt_field_type_integer_set_is_signed(): Sets the signedness of the |
78c8ab4f PP |
852 | integer fields described by a given integer field type. |
853 | */ | |
50842bdc PP |
854 | extern bt_bool bt_field_type_integer_is_signed( |
855 | struct bt_field_type *int_field_type); | |
e852c730 | 856 | |
78c8ab4f | 857 | /** |
4089d5a6 PP |
858 | @brief Sets whether or not the @intfields described by |
859 | the @intft \p int_field_type are signed. | |
78c8ab4f PP |
860 | |
861 | @param[in] int_field_type Integer field type which describes the | |
862 | integer fields of which to set the | |
863 | signedness. | |
864 | @param[in] is_signed Signedness of the integer fields | |
c14d64fa PP |
865 | described by \p int_field_type; #BT_FALSE means |
866 | \em unsigned, #BT_TRUE means \em signed. | |
78c8ab4f PP |
867 | @returns 0 on success, or a negative value on error. |
868 | ||
869 | @prenotnull{int_field_type} | |
870 | @preisintft{int_field_type} | |
871 | @prehot{int_field_type} | |
c3c35de4 | 872 | @postrefcountsame{int_field_type} |
78c8ab4f | 873 | |
50842bdc | 874 | @sa bt_field_type_integer_is_signed(): Returns the signedness of |
78c8ab4f PP |
875 | the integer fields described by a given integer field type. |
876 | */ | |
50842bdc PP |
877 | extern int bt_field_type_integer_set_is_signed( |
878 | struct bt_field_type *int_field_type, bt_bool is_signed); | |
e852c730 | 879 | |
78c8ab4f | 880 | /** |
4089d5a6 PP |
881 | @brief Returns the preferred display base (radix) of the @intfields |
882 | described by the @intft \p int_field_type. | |
78c8ab4f PP |
883 | |
884 | @param[in] int_field_type Integer field type which describes the | |
885 | integer fields of which to get the | |
886 | preferred display base. | |
887 | @returns Preferred display base of the integer | |
888 | fields described by \p int_field_type, | |
50842bdc | 889 | #BT_INTEGER_BASE_UNSPECIFIED if |
d2bd5ad3 | 890 | not specified, or |
50842bdc | 891 | #BT_INTEGER_BASE_UNKNOWN on error. |
78c8ab4f PP |
892 | |
893 | @prenotnull{int_field_type} | |
894 | @preisintft{int_field_type} | |
895 | @postrefcountsame{int_field_type} | |
896 | ||
50842bdc | 897 | @sa bt_field_type_integer_set_base(): Sets the preferred display |
78c8ab4f PP |
898 | base of the integer fields described by a given integer field |
899 | type. | |
900 | */ | |
50842bdc PP |
901 | extern enum bt_integer_base bt_field_type_integer_get_base( |
902 | struct bt_field_type *int_field_type); | |
b92ddaaa | 903 | |
78c8ab4f | 904 | /** |
4089d5a6 PP |
905 | @brief Sets the preferred display base (radix) of the @intfields |
906 | described by the @intft \p int_field_type to \p base. | |
78c8ab4f PP |
907 | |
908 | @param[in] int_field_type Integer field type which describes the | |
909 | integer fields of which to set the | |
910 | preferred display base. | |
911 | @param[in] base Preferred display base of the integer | |
912 | fields described by \p int_field_type. | |
913 | @returns 0 on success, or a negative value on error. | |
914 | ||
915 | @prenotnull{int_field_type} | |
916 | @preisintft{int_field_type} | |
917 | @prehot{int_field_type} | |
50842bdc PP |
918 | @pre \p base is #BT_INTEGER_BASE_UNSPECIFIED, |
919 | #BT_INTEGER_BASE_BINARY, #BT_INTEGER_BASE_OCTAL, | |
920 | #BT_INTEGER_BASE_DECIMAL, or #BT_INTEGER_BASE_HEXADECIMAL. | |
78c8ab4f PP |
921 | @postrefcountsame{int_field_type} |
922 | ||
50842bdc | 923 | @sa bt_field_type_integer_get_base(): Returns the preferred display |
78c8ab4f PP |
924 | base of the integer fields described by a given |
925 | integer field type. | |
926 | */ | |
50842bdc PP |
927 | extern int bt_field_type_integer_set_base( |
928 | struct bt_field_type *int_field_type, | |
929 | enum bt_integer_base base); | |
adc315b8 | 930 | |
78c8ab4f | 931 | /** |
4089d5a6 PP |
932 | @brief Returns the encoding of the @intfields described by |
933 | the @intft \p int_field_type. | |
78c8ab4f PP |
934 | |
935 | @param[in] int_field_type Integer field type which describes the | |
936 | integer fields of which to get the | |
937 | encoding. | |
938 | @returns Encoding of the integer | |
939 | fields described by \p int_field_type, | |
50842bdc | 940 | or #BT_STRING_ENCODING_UNKNOWN on |
78c8ab4f PP |
941 | error. |
942 | ||
943 | @prenotnull{int_field_type} | |
944 | @preisintft{int_field_type} | |
945 | @postrefcountsame{int_field_type} | |
946 | ||
50842bdc | 947 | @sa bt_field_type_integer_set_encoding(): Sets the encoding |
78c8ab4f PP |
948 | of the integer fields described by a given integer field type. |
949 | */ | |
50842bdc PP |
950 | extern enum bt_string_encoding bt_field_type_integer_get_encoding( |
951 | struct bt_field_type *int_field_type); | |
b92ddaaa | 952 | |
78c8ab4f | 953 | /** |
4089d5a6 PP |
954 | @brief Sets the encoding of the @intfields described by the @intft |
955 | \p int_field_type to \p encoding. | |
78c8ab4f | 956 | |
4089d5a6 PP |
957 | You can use this property, in CTF IR, to create "text" @arrayfts or |
958 | @seqfts. A text array field type is array field type with an unsigned, | |
78c8ab4f PP |
959 | 8-bit integer field type having an encoding as its element field type. |
960 | ||
961 | @param[in] int_field_type Integer field type which describes the | |
962 | integer fields of which to set the | |
963 | encoding. | |
964 | @param[in] encoding Encoding of the integer | |
965 | fields described by \p int_field_type. | |
966 | @returns 0 on success, or a negative value on error. | |
967 | ||
968 | @prenotnull{int_field_type} | |
969 | @preisintft{int_field_type} | |
970 | @prehot{int_field_type} | |
50842bdc PP |
971 | @pre \p encoding is #BT_STRING_ENCODING_NONE, |
972 | #BT_STRING_ENCODING_ASCII, or | |
973 | #BT_STRING_ENCODING_UTF8. | |
78c8ab4f PP |
974 | @postrefcountsame{int_field_type} |
975 | ||
50842bdc | 976 | @sa bt_field_type_integer_get_encoding(): Returns the encoding of |
78c8ab4f PP |
977 | the integer fields described by a given integer field type. |
978 | */ | |
50842bdc PP |
979 | extern int bt_field_type_integer_set_encoding( |
980 | struct bt_field_type *int_field_type, | |
981 | enum bt_string_encoding encoding); | |
adc315b8 | 982 | |
094ff7c0 PP |
983 | extern struct bt_clock_class *bt_field_type_integer_borrow_mapped_clock_class( |
984 | struct bt_field_type *int_field_type); | |
985 | ||
6cfb906f | 986 | /** |
4089d5a6 PP |
987 | @brief Returns the \link ctfirclockclass CTF IR clock class\endlink |
988 | mapped to the @intft \p int_field_type. | |
78c8ab4f PP |
989 | |
990 | The mapped clock class, if any, indicates the class of the clock which | |
4089d5a6 | 991 | an @intfield described by \p int_field_type should sample or update. |
78c8ab4f PP |
992 | This mapped clock class is only indicative. |
993 | ||
994 | @param[in] int_field_type Integer field type of which to get the | |
995 | mapped clock class. | |
996 | @returns Mapped clock class of \p int_field_type, | |
997 | or \c NULL if there's no mapped clock | |
998 | class or on error. | |
999 | ||
1000 | @prenotnull{int_field_type} | |
1001 | @preisintft{int_field_type} | |
1002 | @postrefcountsame{int_field_type} | |
1003 | @postsuccessrefcountretinc | |
1004 | ||
50842bdc | 1005 | @sa bt_field_type_integer_set_mapped_clock_class(): Sets the mapped |
78c8ab4f PP |
1006 | clock class of a given integer field type. |
1007 | */ | |
094ff7c0 PP |
1008 | static inline |
1009 | struct bt_clock_class *bt_field_type_integer_get_mapped_clock_class( | |
1010 | struct bt_field_type *int_field_type) | |
1011 | { | |
1012 | return bt_get(bt_field_type_integer_borrow_mapped_clock_class( | |
1013 | int_field_type)); | |
1014 | } | |
6cfb906f JG |
1015 | |
1016 | /** | |
4089d5a6 | 1017 | @brief Sets the \link ctfirclockclass CTF IR clock class\endlink mapped |
ac0c6bdd | 1018 | to the @intft \p int_field_type to \p clock_class. |
78c8ab4f PP |
1019 | |
1020 | The mapped clock class, if any, indicates the class of the clock which | |
1021 | an integer field described by \p int_field_type should sample or update. | |
1022 | This mapped clock class is only indicative. | |
1023 | ||
1024 | @param[in] int_field_type Integer field type of which to set the | |
1025 | mapped clock class. | |
1026 | @param[in] clock_class Mapped clock class of \p int_field_type. | |
1027 | @returns 0 on success, or a negative value on error. | |
1028 | ||
1029 | @prenotnull{int_field_type} | |
1030 | @prenotnull{clock_class} | |
1031 | @preisintft{int_field_type} | |
1032 | @prehot{int_field_type} | |
1033 | @postrefcountsame{int_field_type} | |
1034 | @postsuccessrefcountinc{clock_class} | |
1035 | ||
50842bdc | 1036 | @sa bt_field_type_integer_get_mapped_clock_class(): Returns the mapped |
78c8ab4f PP |
1037 | clock class of a given integer field type. |
1038 | */ | |
50842bdc PP |
1039 | extern int bt_field_type_integer_set_mapped_clock_class( |
1040 | struct bt_field_type *int_field_type, | |
1041 | struct bt_clock_class *clock_class); | |
6cfb906f | 1042 | |
78c8ab4f | 1043 | /** @} */ |
adc315b8 | 1044 | |
78c8ab4f PP |
1045 | /** |
1046 | @defgroup ctfirfloatfieldtype CTF IR floating point number field type | |
1047 | @ingroup ctfirfieldtypes | |
1048 | @brief CTF IR floating point number field type. | |
1049 | ||
1050 | @code | |
1051 | #include <babeltrace/ctf-ir/field-types.h> | |
1052 | @endcode | |
1053 | ||
1054 | A CTF IR <strong><em>floating point number field type</em></strong> is | |
4089d5a6 | 1055 | a field type that you can use to create concrete @floatfields. |
78c8ab4f PP |
1056 | |
1057 | You can create a floating point number field type | |
50842bdc | 1058 | with bt_field_type_floating_point_create(). |
78c8ab4f PP |
1059 | |
1060 | A floating point number field type has the following properties: | |
1061 | ||
1062 | <table> | |
1063 | <tr> | |
1064 | <th>Property | |
1065 | <th>Value at creation | |
1066 | <th>Getter | |
1067 | <th>Setter | |
1068 | </tr> | |
1069 | <tr> | |
1070 | <td>\b Alignment (bits) of the described floating point | |
1071 | number fields | |
1072 | <td>1 | |
50842bdc PP |
1073 | <td>bt_field_type_get_alignment() |
1074 | <td>bt_field_type_set_alignment() | |
78c8ab4f PP |
1075 | </tr> |
1076 | <tr> | |
1077 | <td><strong>Byte order</strong> of the described floating point | |
1078 | number fields | |
50842bdc PP |
1079 | <td>#BT_BYTE_ORDER_NATIVE |
1080 | <td>bt_field_type_get_byte_order() | |
1081 | <td>bt_field_type_set_byte_order() | |
78c8ab4f PP |
1082 | </tr> |
1083 | <tr> | |
1084 | <td><strong>Exponent storage size</strong> (bits) of the described | |
1085 | floating point number fields | |
1086 | <td>8 | |
50842bdc PP |
1087 | <td>bt_field_type_floating_point_get_exponent_digits() |
1088 | <td>bt_field_type_floating_point_set_exponent_digits() | |
78c8ab4f PP |
1089 | </tr> |
1090 | <tr> | |
1091 | <td><strong>Mantissa and sign storage size</strong> (bits) of the | |
1092 | described floating point number fields | |
1093 | <td>24 (23-bit mantissa, 1-bit sign) | |
50842bdc PP |
1094 | <td>bt_field_type_floating_point_get_mantissa_digits() |
1095 | <td>bt_field_type_floating_point_set_mantissa_digits() | |
78c8ab4f PP |
1096 | </tr> |
1097 | </table> | |
1098 | ||
1099 | @sa ctfirfloatfield | |
1100 | @sa ctfirfieldtypes | |
bb8c17e0 | 1101 | @sa \ref ctfirfieldtypesexamples_floatfieldtype "Examples" |
78c8ab4f PP |
1102 | |
1103 | @addtogroup ctfirfloatfieldtype | |
1104 | @{ | |
1105 | */ | |
b92ddaaa | 1106 | |
78c8ab4f | 1107 | /** |
4089d5a6 | 1108 | @brief Creates a default @floatft. |
adc315b8 | 1109 | |
78c8ab4f PP |
1110 | @returns Created floating point number field type, |
1111 | or \c NULL on error. | |
b92ddaaa | 1112 | |
78c8ab4f PP |
1113 | @postsuccessrefcountret1 |
1114 | */ | |
50842bdc | 1115 | extern struct bt_field_type *bt_field_type_floating_point_create(void); |
b92ddaaa | 1116 | |
78c8ab4f | 1117 | /** |
4089d5a6 PP |
1118 | @brief Returns the exponent storage size of the @floatfields |
1119 | described by the @floatft \p float_field_type. | |
78c8ab4f PP |
1120 | |
1121 | @param[in] float_field_type Floating point number field type which | |
1122 | describes the floating point number | |
1123 | fields of which to get the exponent | |
1124 | storage size. | |
1125 | @returns Exponent storage size of the | |
1126 | floating point number fields | |
1127 | described by \p float_field_type, | |
1128 | or a negative value on error. | |
1129 | ||
1130 | @prenotnull{float_field_type} | |
1131 | @preisfloatft{float_field_type} | |
1132 | @postrefcountsame{float_field_type} | |
1133 | ||
50842bdc | 1134 | @sa bt_field_type_floating_point_set_exponent_digits(): Sets the |
78c8ab4f PP |
1135 | exponent storage size of the floating point number fields |
1136 | described by a given floating point number field type. | |
1137 | */ | |
50842bdc PP |
1138 | extern int bt_field_type_floating_point_get_exponent_digits( |
1139 | struct bt_field_type *float_field_type); | |
b92ddaaa | 1140 | |
78c8ab4f | 1141 | /** |
4089d5a6 PP |
1142 | @brief Sets the exponent storage size of the @floatfields described by |
1143 | the @floatft \p float_field_type to \p exponent_size. | |
78c8ab4f PP |
1144 | |
1145 | As of Babeltrace \btversion, \p exponent_size can only be 8 or 11. | |
1146 | ||
1147 | @param[in] float_field_type Floating point number field type which | |
1148 | describes the floating point number | |
1149 | fields of which to set the exponent | |
1150 | storage size. | |
1151 | @param[in] exponent_size Exponent storage size of the floating | |
1152 | point number fields described by \p | |
1153 | float_field_type. | |
1154 | @returns 0 on success, or a negative value on error. | |
1155 | ||
1156 | @prenotnull{float_field_type} | |
1157 | @preisfloatft{float_field_type} | |
1158 | @prehot{float_field_type} | |
1159 | @pre \p exponent_size is 8 or 11. | |
1160 | @postrefcountsame{float_field_type} | |
1161 | ||
50842bdc | 1162 | @sa bt_field_type_floating_point_get_exponent_digits(): Returns the |
78c8ab4f PP |
1163 | exponent storage size of the floating point number fields |
1164 | described by a given floating point number field type. | |
1165 | */ | |
50842bdc PP |
1166 | extern int bt_field_type_floating_point_set_exponent_digits( |
1167 | struct bt_field_type *float_field_type, | |
78c8ab4f PP |
1168 | unsigned int exponent_size); |
1169 | ||
1170 | /** | |
4089d5a6 PP |
1171 | @brief Returns the mantissa and sign storage size of the @floatfields |
1172 | described by the @floatft \p float_field_type. | |
78c8ab4f PP |
1173 | |
1174 | On success, the returned value is the sum of the mantissa \em and | |
1175 | sign storage sizes. | |
1176 | ||
1177 | @param[in] float_field_type Floating point number field type which | |
1178 | describes the floating point number | |
1179 | fields of which to get the mantissa and | |
1180 | sign storage size. | |
1181 | @returns Mantissa and sign storage size of the | |
1182 | floating point number fields | |
1183 | described by \p float_field_type, | |
1184 | or a negative value on error. | |
1185 | ||
1186 | @prenotnull{float_field_type} | |
1187 | @preisfloatft{float_field_type} | |
1188 | @postrefcountsame{float_field_type} | |
1189 | ||
50842bdc | 1190 | @sa bt_field_type_floating_point_set_mantissa_digits(): Sets the |
78c8ab4f PP |
1191 | mantissa and size storage size of the floating point number |
1192 | fields described by a given floating point number field type. | |
1193 | */ | |
50842bdc PP |
1194 | extern int bt_field_type_floating_point_get_mantissa_digits( |
1195 | struct bt_field_type *float_field_type); | |
78c8ab4f PP |
1196 | |
1197 | /** | |
4089d5a6 PP |
1198 | @brief Sets the mantissa and sign storage size of the @floatfields |
1199 | described by the @floatft \p float_field_type to \p | |
1200 | mantissa_sign_size. | |
78c8ab4f PP |
1201 | |
1202 | As of Babeltrace \btversion, \p mantissa_sign_size can only be 24 or 53. | |
1203 | ||
1204 | @param[in] float_field_type Floating point number field type which | |
1205 | describes the floating point number | |
1206 | fields of which to set the mantissa and | |
1207 | sign storage size. | |
1208 | @param[in] mantissa_sign_size Mantissa and sign storage size of the | |
1209 | floating point number fields described | |
1210 | by \p float_field_type. | |
1211 | @returns 0 on success, or a negative value on error. | |
1212 | ||
1213 | @prenotnull{float_field_type} | |
1214 | @preisfloatft{float_field_type} | |
1215 | @prehot{float_field_type} | |
1216 | @pre \p mantissa_sign_size is 24 or 53. | |
1217 | @postrefcountsame{float_field_type} | |
1218 | ||
50842bdc | 1219 | @sa bt_field_type_floating_point_get_mantissa_digits(): Returns the |
78c8ab4f PP |
1220 | mantissa and sign storage size of the floating point number |
1221 | fields described by a given floating point number field type. | |
1222 | */ | |
50842bdc PP |
1223 | extern int bt_field_type_floating_point_set_mantissa_digits( |
1224 | struct bt_field_type *float_field_type, | |
78c8ab4f PP |
1225 | unsigned int mantissa_sign_size); |
1226 | ||
1227 | /** @} */ | |
b92ddaaa | 1228 | |
78c8ab4f PP |
1229 | /** |
1230 | @defgroup ctfirenumfieldtype CTF IR enumeration field type | |
1231 | @ingroup ctfirfieldtypes | |
1232 | @brief CTF IR enumeration field type. | |
1233 | ||
1234 | @code | |
1235 | #include <babeltrace/ctf-ir/field-types.h> | |
1236 | @endcode | |
1237 | ||
1238 | A CTF IR <strong><em>enumeration field type</em></strong> is | |
4089d5a6 | 1239 | a field type that you can use to create concrete @enumfields. |
78c8ab4f | 1240 | |
4089d5a6 | 1241 | You can create an enumeration field type with |
50842bdc | 1242 | bt_field_type_enumeration_create(). This function needs a @intft |
4089d5a6 PP |
1243 | which represents the storage field type of the created enumeration field |
1244 | type. In other words, an enumeration field type wraps an integer field | |
1245 | type and adds label-value mappings to it. | |
78c8ab4f PP |
1246 | |
1247 | An enumeration mapping has: | |
1248 | ||
1249 | - A <strong>name</strong>. | |
1250 | - A <strong>range of values</strong> given by a beginning and an ending | |
1251 | value, both included in the range. | |
1252 | ||
1253 | You can add a mapping to an enumeration field type with | |
3dca2276 PP |
1254 | bt_field_type_enumeration_signed_add_mapping() or |
1255 | bt_field_type_enumeration_unsigned_add_mapping(), depending on the | |
4089d5a6 | 1256 | signedness of the wrapped @intft. |
78c8ab4f | 1257 | |
5c3f3b7e PP |
1258 | You can find mappings by name or by value with the following find |
1259 | operations: | |
1260 | ||
50842bdc | 1261 | - bt_field_type_enumeration_find_mappings_by_name(): Finds the |
5c3f3b7e | 1262 | mappings with a given name. |
3dca2276 | 1263 | - bt_field_type_enumeration_unsigned_find_mappings_by_value(): |
5c3f3b7e PP |
1264 | Finds the mappings which contain a given unsigned value in their |
1265 | range. | |
3dca2276 | 1266 | - bt_field_type_enumeration_signed_find_mappings_by_value(): |
5c3f3b7e PP |
1267 | Finds the mappings which contain a given signed value in their range. |
1268 | ||
1269 | Those functions return a @enumftiter on the result set of the find | |
1270 | operation. | |
1271 | ||
96e8f959 MD |
1272 | Many mappings can share the same name, and the ranges of a given |
1273 | enumeration field type are allowed to overlap. For example, | |
78c8ab4f PP |
1274 | this is a valid set of mappings: |
1275 | ||
1276 | @verbatim | |
1277 | APPLE -> [ 3, 19] | |
1278 | BANANA -> [-15, 1] | |
1279 | CHERRY -> [ 25, 34] | |
1280 | APPLE -> [ 55, 55] | |
1281 | @endverbatim | |
1282 | ||
96e8f959 | 1283 | The following set of mappings is also valid: |
78c8ab4f PP |
1284 | |
1285 | @verbatim | |
1286 | APPLE -> [ 3, 19] | |
1287 | BANANA -> [-15, 1] | |
1288 | CHERRY -> [ 25, 34] | |
1289 | APPLE -> [ 30, 55] | |
1290 | @endverbatim | |
1291 | ||
1292 | Here, the range of the second \c APPLE mapping overlaps the range of | |
1293 | the \c CHERRY mapping. | |
1294 | ||
5c3f3b7e | 1295 | @sa ctfirenumftmappingiter |
78c8ab4f PP |
1296 | @sa ctfirenumfield |
1297 | @sa ctfirfieldtypes | |
1298 | ||
1299 | @addtogroup ctfirenumfieldtype | |
1300 | @{ | |
1301 | */ | |
1302 | ||
1303 | /** | |
4089d5a6 | 1304 | @brief Creates a default @enumft wrapping the @intft \p int_field_type. |
78c8ab4f PP |
1305 | |
1306 | @param[in] int_field_type Integer field type wrapped by the | |
1307 | created enumeration field type. | |
1308 | @returns Created enumeration field type, | |
1309 | or \c NULL on error. | |
1310 | ||
1311 | @prenotnull{int_field_type} | |
1312 | @preisintft{int_field_type} | |
1313 | @postsuccessrefcountinc{int_field_type} | |
1314 | @postsuccessrefcountret1 | |
1315 | */ | |
50842bdc PP |
1316 | extern struct bt_field_type *bt_field_type_enumeration_create( |
1317 | struct bt_field_type *int_field_type); | |
78c8ab4f | 1318 | |
094ff7c0 PP |
1319 | extern |
1320 | struct bt_field_type *bt_field_type_enumeration_borrow_container_field_type( | |
1321 | struct bt_field_type *enum_field_type); | |
1322 | ||
78c8ab4f | 1323 | /** |
4089d5a6 | 1324 | @brief Returns the @intft wrapped by the @enumft \p enum_field_type. |
78c8ab4f PP |
1325 | |
1326 | @param[in] enum_field_type Enumeration field type of which to get | |
1327 | the wrapped integer field type. | |
1328 | @returns Integer field type wrapped by | |
1329 | \p enum_field_type, or \c NULL on | |
1330 | error. | |
1331 | ||
1332 | @prenotnull{enum_field_type} | |
1333 | @preisenumft{enum_field_type} | |
1334 | @postrefcountsame{enum_field_type} | |
1335 | @postsuccessrefcountretinc | |
1336 | */ | |
094ff7c0 | 1337 | static inline |
3dca2276 | 1338 | struct bt_field_type *bt_field_type_enumeration_get_container_field_type( |
094ff7c0 PP |
1339 | struct bt_field_type *enum_field_type) |
1340 | { | |
1341 | return bt_get(bt_field_type_enumeration_borrow_container_field_type( | |
1342 | enum_field_type)); | |
1343 | } | |
78c8ab4f PP |
1344 | |
1345 | /** | |
4089d5a6 PP |
1346 | @brief Returns the number of mappings contained in the |
1347 | @enumft \p enum_field_type. | |
78c8ab4f PP |
1348 | |
1349 | @param[in] enum_field_type Enumeration field type of which to get | |
1350 | the number of contained mappings. | |
1351 | @returns Number of mappings contained in | |
1352 | \p enum_field_type, or a negative | |
1353 | value on error. | |
1354 | ||
1355 | @prenotnull{enum_field_type} | |
1356 | @preisenumft{enum_field_type} | |
1357 | @postrefcountsame{enum_field_type} | |
1358 | */ | |
50842bdc PP |
1359 | extern int64_t bt_field_type_enumeration_get_mapping_count( |
1360 | struct bt_field_type *enum_field_type); | |
78c8ab4f PP |
1361 | |
1362 | /** | |
4089d5a6 | 1363 | @brief Returns the signed mapping of the @enumft |
78c8ab4f PP |
1364 | \p enum_field_type at index \p index. |
1365 | ||
4089d5a6 | 1366 | The @intft wrapped by \p enum_field_type, as returned by |
3dca2276 | 1367 | bt_field_type_enumeration_get_container_field_type(), must be \b signed |
4089d5a6 | 1368 | to use this function. |
78c8ab4f PP |
1369 | |
1370 | On success, \p enum_field_type remains the sole owner of \p *name. | |
1371 | ||
1372 | @param[in] enum_field_type Enumeration field type of which to get | |
1373 | the mapping at index \p index. | |
8dc7eb94 | 1374 | @param[in] index Index of the mapping to get from |
78c8ab4f PP |
1375 | \p enum_field_type. |
1376 | @param[out] name Returned name of the mapping at index | |
1377 | \p index. | |
1378 | @param[out] range_begin Returned beginning of the range | |
1379 | (included) of the mapping at index \p | |
1380 | index. | |
1381 | @param[out] range_end Returned end of the range (included) of | |
1382 | the mapping at index \p index. | |
1383 | @returns 0 on success, or a negative value on error. | |
1384 | ||
1385 | @prenotnull{enum_field_type} | |
1386 | @prenotnull{name} | |
1387 | @prenotnull{range_begin} | |
1388 | @prenotnull{range_end} | |
1389 | @preisenumft{enum_field_type} | |
4089d5a6 | 1390 | @pre The wrapped @intft of \p enum_field_type is signed. |
78c8ab4f PP |
1391 | @pre \p index is lesser than the number of mappings contained in the |
1392 | enumeration field type \p enum_field_type (see | |
50842bdc | 1393 | bt_field_type_enumeration_get_mapping_count()). |
78c8ab4f PP |
1394 | @postrefcountsame{enum_field_type} |
1395 | ||
3dca2276 | 1396 | @sa bt_field_type_enumeration_unsigned_get_mapping_by_index(): Returns the |
cfb61c11 | 1397 | unsigned mapping contained by a given enumeration field type |
78c8ab4f PP |
1398 | at a given index. |
1399 | */ | |
3dca2276 | 1400 | extern int bt_field_type_enumeration_signed_get_mapping_by_index( |
50842bdc | 1401 | struct bt_field_type *enum_field_type, uint64_t index, |
78c8ab4f PP |
1402 | const char **name, int64_t *range_begin, int64_t *range_end); |
1403 | ||
1404 | /** | |
4089d5a6 PP |
1405 | @brief Returns the unsigned mapping of the @enumft |
1406 | \p enum_field_type at index \p index. | |
78c8ab4f | 1407 | |
4089d5a6 | 1408 | The @intft wrapped by \p enum_field_type, as returned by |
3dca2276 | 1409 | bt_field_type_enumeration_get_container_field_type(), must be |
78c8ab4f PP |
1410 | \b unsigned to use this function. |
1411 | ||
1412 | On success, \p enum_field_type remains the sole owner of \p *name. | |
1413 | ||
1414 | @param[in] enum_field_type Enumeration field type of which to get | |
1415 | the mapping at index \p index. | |
8dc7eb94 | 1416 | @param[in] index Index of the mapping to get from |
78c8ab4f PP |
1417 | \p enum_field_type. |
1418 | @param[out] name Returned name of the mapping at index | |
1419 | \p index. | |
1420 | @param[out] range_begin Returned beginning of the range | |
1421 | (included) of the mapping at index \p | |
1422 | index. | |
1423 | @param[out] range_end Returned end of the range (included) of | |
1424 | the mapping at index \p index. | |
1425 | @returns 0 on success, or a negative value on error. | |
1426 | ||
1427 | @prenotnull{enum_field_type} | |
1428 | @prenotnull{name} | |
1429 | @prenotnull{range_begin} | |
1430 | @prenotnull{range_end} | |
1431 | @preisenumft{enum_field_type} | |
4089d5a6 | 1432 | @pre The wrapped @intft of \p enum_field_type is unsigned. |
78c8ab4f PP |
1433 | @pre \p index is lesser than the number of mappings contained in the |
1434 | enumeration field type \p enum_field_type (see | |
50842bdc | 1435 | bt_field_type_enumeration_get_mapping_count()). |
78c8ab4f PP |
1436 | @postrefcountsame{enum_field_type} |
1437 | ||
3dca2276 | 1438 | @sa bt_field_type_enumeration_signed_get_mapping_by_index(): Returns the |
cfb61c11 | 1439 | signed mapping contained by a given enumeration field type |
78c8ab4f PP |
1440 | at a given index. |
1441 | */ | |
3dca2276 | 1442 | extern int bt_field_type_enumeration_unsigned_get_mapping_by_index( |
50842bdc | 1443 | struct bt_field_type *enum_field_type, uint64_t index, |
78c8ab4f PP |
1444 | const char **name, uint64_t *range_begin, |
1445 | uint64_t *range_end); | |
1446 | ||
8dc7eb94 | 1447 | /** |
5c3f3b7e PP |
1448 | @brief Finds the mappings of the @enumft \p enum_field_type which |
1449 | are named \p name. | |
8dc7eb94 | 1450 | |
5c3f3b7e PP |
1451 | This function returns an iterator on the result set of this find |
1452 | operation. See \ref ctfirenumftmappingiter for more details. | |
1453 | ||
1454 | @param[in] enum_field_type Enumeration field type of which to find | |
1455 | the mappings named \p name. | |
1456 | @param[in] name Name of the mappings to find in | |
1457 | \p enum_field_type. | |
1458 | @returns @enumftiter on the set of mappings named | |
1459 | \p name in \p enum_field_type, or | |
1460 | \c NULL if no mappings were found or | |
1461 | on error. | |
8dc7eb94 JG |
1462 | |
1463 | @prenotnull{enum_field_type} | |
1464 | @prenotnull{name} | |
1465 | @preisenumft{enum_field_type} | |
1466 | @postrefcountsame{enum_field_type} | |
1467 | @postsuccessrefcountret1 | |
5c3f3b7e PP |
1468 | @post <strong>On success</strong>, the returned @enumftiter can iterate |
1469 | on at least one mapping. | |
1470 | ||
3dca2276 | 1471 | @sa bt_field_type_enumeration_signed_find_mappings_by_value(): Finds |
5c3f3b7e PP |
1472 | the mappings of a given enumeration field type which contain |
1473 | a given signed value in their range. | |
3dca2276 | 1474 | @sa bt_field_type_enumeration_unsigned_find_mappings_by_value(): Finds |
5c3f3b7e PP |
1475 | the mappings of a given enumeration field type which contain |
1476 | a given unsigned value in their range. | |
8dc7eb94 | 1477 | */ |
50842bdc PP |
1478 | extern struct bt_field_type_enumeration_mapping_iterator * |
1479 | bt_field_type_enumeration_find_mappings_by_name( | |
1480 | struct bt_field_type *enum_field_type, | |
8dc7eb94 JG |
1481 | const char *name); |
1482 | ||
1483 | /** | |
5c3f3b7e PP |
1484 | @brief Finds the mappings of the @enumft \p enum_field_type which |
1485 | contain the signed value \p value in their range. | |
8dc7eb94 | 1486 | |
5c3f3b7e PP |
1487 | This function returns an iterator on the result set of this find |
1488 | operation. See \ref ctfirenumftmappingiter for more details. | |
1489 | ||
1490 | @param[in] enum_field_type Enumeration field type of which to find | |
1491 | the mappings which contain \p value. | |
1492 | @param[in] value Value to find in the ranges of the | |
1493 | mappings of \p enum_field_type. | |
1494 | @returns @enumftiter on the set of mappings of | |
1495 | \p enum_field_type which contain | |
1496 | \p value in their range, or \c NULL if | |
1497 | no mappings were found or on error. | |
8dc7eb94 JG |
1498 | |
1499 | @prenotnull{enum_field_type} | |
8dc7eb94 JG |
1500 | @preisenumft{enum_field_type} |
1501 | @postrefcountsame{enum_field_type} | |
1502 | @postsuccessrefcountret1 | |
5c3f3b7e PP |
1503 | @post <strong>On success</strong>, the returned @enumftiter can iterate |
1504 | on at least one mapping. | |
1505 | ||
50842bdc | 1506 | @sa bt_field_type_enumeration_find_mappings_by_name(): Finds the |
5c3f3b7e PP |
1507 | mappings of a given enumeration field type which have a given |
1508 | name. | |
3dca2276 | 1509 | @sa bt_field_type_enumeration_unsigned_find_mappings_by_value(): Finds |
5c3f3b7e PP |
1510 | the mappings of a given enumeration field type which contain |
1511 | a given unsigned value in their range. | |
8dc7eb94 | 1512 | */ |
50842bdc | 1513 | extern struct bt_field_type_enumeration_mapping_iterator * |
3dca2276 | 1514 | bt_field_type_enumeration_signed_find_mappings_by_value( |
50842bdc | 1515 | struct bt_field_type *enum_field_type, |
8dc7eb94 JG |
1516 | int64_t value); |
1517 | ||
1518 | /** | |
5c3f3b7e PP |
1519 | @brief Finds the mappings of the @enumft \p enum_field_type which |
1520 | contain the unsigned value \p value in their range. | |
1521 | ||
1522 | This function returns an iterator on the result set of this find | |
1523 | operation. See \ref ctfirenumftmappingiter for more details. | |
1524 | ||
1525 | @param[in] enum_field_type Enumeration field type of which to find | |
1526 | the mappings which contain \p value. | |
1527 | @param[in] value Value to find in the ranges of the | |
1528 | mappings of \p enum_field_type. | |
1529 | @returns @enumftiter on the set of mappings of | |
1530 | \p enum_field_type which contain | |
1531 | \p value in their range, or \c NULL | |
1532 | if no mappings were found or | |
1533 | on error. | |
8dc7eb94 JG |
1534 | |
1535 | @prenotnull{enum_field_type} | |
8dc7eb94 JG |
1536 | @preisenumft{enum_field_type} |
1537 | @postrefcountsame{enum_field_type} | |
1538 | @postsuccessrefcountret1 | |
5c3f3b7e PP |
1539 | @post <strong>On success</strong>, the returned @enumftiter can iterate |
1540 | on at least one mapping. | |
1541 | ||
50842bdc | 1542 | @sa bt_field_type_enumeration_find_mappings_by_name(): Finds the |
5c3f3b7e PP |
1543 | mappings of a given enumeration field type which have a given |
1544 | name. | |
3dca2276 | 1545 | @sa bt_field_type_enumeration_signed_find_mappings_by_value(): Finds |
5c3f3b7e PP |
1546 | the mappings of a given enumeration field type which contain |
1547 | a given unsigned value in their range. | |
8dc7eb94 | 1548 | */ |
50842bdc | 1549 | extern struct bt_field_type_enumeration_mapping_iterator * |
3dca2276 | 1550 | bt_field_type_enumeration_unsigned_find_mappings_by_value( |
50842bdc | 1551 | struct bt_field_type *enum_field_type, |
8dc7eb94 JG |
1552 | uint64_t value); |
1553 | ||
78c8ab4f | 1554 | /** |
4089d5a6 PP |
1555 | @brief Adds a mapping to the @enumft \p enum_field_type which maps the |
1556 | name \p name to the signed range \p range_begin (included) to | |
1557 | \p range_end (included). | |
78c8ab4f PP |
1558 | |
1559 | Make \p range_begin and \p range_end the same value to add a mapping | |
1560 | to a single value. | |
1561 | ||
4089d5a6 | 1562 | The @intft wrapped by \p enum_field_type, as returned by |
3dca2276 | 1563 | bt_field_type_enumeration_get_container_field_type(), must be |
78c8ab4f PP |
1564 | \b signed to use this function. |
1565 | ||
96e8f959 | 1566 | A mapping in \p enum_field_type can exist with the name \p name. |
78c8ab4f PP |
1567 | |
1568 | @param[in] enum_field_type Enumeration field type to which to add | |
1569 | a mapping. | |
1570 | @param[in] name Name of the mapping to add (copied | |
1571 | on success). | |
1572 | @param[in] range_begin Beginning of the range of the mapping | |
1573 | (included). | |
1574 | @param[in] range_end End of the range of the mapping | |
1575 | (included). | |
1576 | @returns 0 on success, or a negative value on error. | |
1577 | ||
1578 | @prenotnull{enum_field_type} | |
1579 | @prenotnull{name} | |
1acbbff5 | 1580 | @prehot{enum_field_type} |
78c8ab4f | 1581 | @preisenumft{enum_field_type} |
4089d5a6 | 1582 | @pre The wrapped @intft of \p enum_field_type is signed. |
78c8ab4f PP |
1583 | @pre \p range_end is greater than or equal to \p range_begin. |
1584 | @postrefcountsame{enum_field_type} | |
1585 | ||
3dca2276 | 1586 | @sa bt_field_type_enumeration_unsigned_add_mapping(): Adds an |
78c8ab4f PP |
1587 | unsigned mapping to a given enumeration field type. |
1588 | */ | |
3dca2276 | 1589 | extern int bt_field_type_enumeration_signed_add_mapping( |
50842bdc | 1590 | struct bt_field_type *enum_field_type, const char *name, |
78c8ab4f | 1591 | int64_t range_begin, int64_t range_end); |
adc315b8 | 1592 | |
78c8ab4f | 1593 | /** |
4089d5a6 PP |
1594 | @brief Adds a mapping to the @enumft \p enum_field_type which maps |
1595 | the name \p name to the unsigned | |
78c8ab4f PP |
1596 | range \p range_begin (included) to \p range_end (included). |
1597 | ||
1598 | Make \p range_begin and \p range_end the same value to add a mapping | |
1599 | to a single value. | |
1600 | ||
4089d5a6 | 1601 | The @intft wrapped by \p enum_field_type, as returned by |
3dca2276 | 1602 | bt_field_type_enumeration_get_container_field_type(), must be |
78c8ab4f PP |
1603 | \b unsigned to use this function. |
1604 | ||
96e8f959 | 1605 | A mapping in \p enum_field_type can exist with the name \p name. |
78c8ab4f PP |
1606 | |
1607 | @param[in] enum_field_type Enumeration field type to which to add | |
1608 | a mapping. | |
1609 | @param[in] name Name of the mapping to add (copied | |
1610 | on success). | |
1611 | @param[in] range_begin Beginning of the range of the mapping | |
1612 | (included). | |
1613 | @param[in] range_end End of the range of the mapping | |
1614 | (included). | |
1615 | @returns 0 on success, or a negative value on error. | |
1616 | ||
1617 | @prenotnull{enum_field_type} | |
1618 | @prenotnull{name} | |
1acbbff5 | 1619 | @prehot{enum_field_type} |
78c8ab4f | 1620 | @preisenumft{enum_field_type} |
4089d5a6 | 1621 | @pre The wrapped @intft of \p enum_field_type is unsigned. |
78c8ab4f PP |
1622 | @pre \p range_end is greater than or equal to \p range_begin. |
1623 | @postrefcountsame{enum_field_type} | |
1624 | ||
3dca2276 | 1625 | @sa bt_field_type_enumeration_signed_add_mapping(): Adds a signed |
78c8ab4f PP |
1626 | mapping to a given enumeration field type. |
1627 | */ | |
3dca2276 | 1628 | extern int bt_field_type_enumeration_unsigned_add_mapping( |
50842bdc | 1629 | struct bt_field_type *enum_field_type, const char *name, |
78c8ab4f | 1630 | uint64_t range_begin, uint64_t range_end); |
b92ddaaa | 1631 | |
78c8ab4f | 1632 | /** @} */ |
adc315b8 | 1633 | |
cfb61c11 | 1634 | /** |
5c3f3b7e PP |
1635 | @defgroup ctfirenumftmappingiter CTF IR enumeration field type mapping iterator |
1636 | @ingroup ctfirenumfieldtype | |
1637 | @brief CTF IR enumeration field type mapping iterator. | |
cfb61c11 JG |
1638 | |
1639 | @code | |
1640 | #include <babeltrace/ctf-ir/field-types.h> | |
1641 | @endcode | |
1642 | ||
5c3f3b7e PP |
1643 | A CTF IR <strong><em>enumeration field type mapping |
1644 | iterator</em></strong> is an iterator on @enumft mappings. | |
1645 | ||
1646 | You can get an enumeration mapping iterator from one of the following | |
1647 | functions: | |
1648 | ||
1649 | - Find operations of an @enumft object: | |
50842bdc | 1650 | - bt_field_type_enumeration_find_mappings_by_name(): Finds the |
5c3f3b7e | 1651 | mappings with a given name. |
3dca2276 | 1652 | - bt_field_type_enumeration_unsigned_find_mappings_by_value(): |
5c3f3b7e PP |
1653 | Finds the mappings which contain a given unsigned value in their |
1654 | range. | |
3dca2276 | 1655 | - bt_field_type_enumeration_signed_find_mappings_by_value(): |
5c3f3b7e | 1656 | Finds the mappings which contain a given signed value in their range. |
50842bdc | 1657 | - bt_field_enumeration_get_mappings(): Finds the mappings in the |
5c3f3b7e PP |
1658 | @enumft of an @enumfield containing its current integral value in |
1659 | their range. | |
1660 | ||
1661 | Those functions guarantee that the returned iterator can iterate on | |
1662 | at least one mapping. Otherwise, they return \c NULL. | |
1663 | ||
1664 | You can get the name and the range of a mapping iterator's current | |
1665 | mapping with | |
3dca2276 | 1666 | bt_field_type_enumeration_mapping_iterator_signed_get() |
5c3f3b7e | 1667 | or |
3dca2276 | 1668 | bt_field_type_enumeration_mapping_iterator_unsigned_get(), |
5c3f3b7e PP |
1669 | depending on the signedness of the @intft wrapped by the |
1670 | @enumft. If you only need the name of the current mapping, you can | |
1671 | use any of the two functions and set the \p range_begin and \p range_end | |
1672 | parameters to \c NULL. | |
1673 | ||
1674 | You can advance an enumeration field type mapping iterator to the next | |
1675 | mapping with | |
50842bdc | 1676 | bt_field_type_enumeration_mapping_iterator_next(). This |
5c3f3b7e PP |
1677 | function returns a negative value when you reach the end of the |
1678 | result set. | |
1679 | ||
1680 | As with any Babeltrace object, CTF IR enumeration field type mapping | |
1681 | iterator objects have <a | |
1682 | href="https://en.wikipedia.org/wiki/Reference_counting">reference | |
1683 | counts</a>. See \ref refs to learn more about the reference counting | |
1684 | management of Babeltrace objects. | |
cfb61c11 JG |
1685 | |
1686 | @sa ctfirenumfieldtype | |
cfb61c11 | 1687 | |
5c3f3b7e | 1688 | @addtogroup ctfirenumftmappingiter |
cfb61c11 JG |
1689 | @{ |
1690 | */ | |
1691 | ||
1692 | /** | |
50842bdc | 1693 | @struct bt_field_type_enumeration_mapping_iterator |
5c3f3b7e PP |
1694 | @brief A CTF IR enumeration field type mapping iterator. |
1695 | @sa ctfirenumftmappingiter | |
cfb61c11 | 1696 | */ |
cfb61c11 JG |
1697 | |
1698 | /** | |
5c3f3b7e PP |
1699 | @brief Returns the name and the range of the current (signed) mapping |
1700 | of the @enumftiter \p iter. | |
cfb61c11 | 1701 | |
5c3f3b7e PP |
1702 | If one of \p range_begin or \p range_end is not \c NULL, the @intft |
1703 | wrapped by the @enumft from which \p iter was obtained, as returned by | |
3dca2276 | 1704 | bt_field_type_enumeration_get_container_field_type(), must be |
5c3f3b7e PP |
1705 | \b signed to use this function. Otherwise, if you only need to get the |
1706 | name of the current mapping, set \p range_begin and \p range_end to | |
1707 | \c NULL. | |
1708 | ||
1709 | On success, if \p name is not \c NULL, \p *name remains valid as long | |
1710 | as \p iter exists and | |
50842bdc | 1711 | bt_field_type_enumeration_mapping_iterator_next() is |
5c3f3b7e PP |
1712 | \em not called on \p iter. |
1713 | ||
1714 | @param[in] iter Enumeration field type mapping iterator | |
1715 | of which to get the range of the current | |
1716 | mapping. | |
1717 | @param[out] name Returned name of the current mapping of | |
1718 | \p iter (can be \c NULL to ignore). | |
cfb61c11 | 1719 | @param[out] range_begin Returned beginning of the range |
5c3f3b7e PP |
1720 | (included) of the current mapping of |
1721 | \p iter (can be \c NULL to ignore). | |
1722 | @param[out] range_end Returned end of the range | |
1723 | (included) of the current mapping of | |
1724 | \p iter (can be \c NULL to ignore). | |
cfb61c11 JG |
1725 | @returns 0 on success, or a negative value on error. |
1726 | ||
1727 | @prenotnull{iter} | |
cfb61c11 JG |
1728 | @postrefcountsame{iter} |
1729 | ||
3dca2276 | 1730 | @sa bt_field_type_enumeration_mapping_iterator_unsigned_get(): |
5c3f3b7e PP |
1731 | Returns the name and the unsigned range of the current mapping |
1732 | of a given enumeration field type mapping iterator. | |
cfb61c11 | 1733 | */ |
3dca2276 | 1734 | extern int bt_field_type_enumeration_mapping_iterator_signed_get( |
50842bdc | 1735 | struct bt_field_type_enumeration_mapping_iterator *iter, |
5c3f3b7e | 1736 | const char **name, int64_t *range_begin, int64_t *range_end); |
cfb61c11 JG |
1737 | |
1738 | /** | |
5c3f3b7e PP |
1739 | @brief Returns the name and the range of the current (unsigned) mapping |
1740 | of the @enumftiter \p iter. | |
cfb61c11 | 1741 | |
5c3f3b7e PP |
1742 | If one of \p range_begin or \p range_end is not \c NULL, the @intft |
1743 | wrapped by the @enumft from which \p iter was obtained, as returned by | |
3dca2276 | 1744 | bt_field_type_enumeration_get_container_field_type(), must be |
5c3f3b7e PP |
1745 | \b unsigned to use this function. Otherwise, if you only need to get the |
1746 | name of the current mapping, set \p range_begin and \p range_end to | |
1747 | \c NULL. | |
1748 | ||
1749 | On success, if \p name is not \c NULL, \p *name remains valid as long | |
1750 | as \p iter exists and | |
50842bdc | 1751 | bt_field_type_enumeration_mapping_iterator_next() is |
5c3f3b7e PP |
1752 | \em not called on \p iter. |
1753 | ||
1754 | @param[in] iter Enumeration field type mapping iterator | |
1755 | of which to get the range of the current | |
1756 | mapping. | |
1757 | @param[out] name Returned name of the current mapping of | |
1758 | \p iter (can be \c NULL to ignore). | |
cfb61c11 | 1759 | @param[out] range_begin Returned beginning of the range |
5c3f3b7e PP |
1760 | (included) of the current mapping of |
1761 | \p iter (can be \c NULL to ignore). | |
1762 | @param[out] range_end Returned end of the range | |
1763 | (included) of the current mapping of | |
1764 | \p iter (can be \c NULL to ignore). | |
cfb61c11 JG |
1765 | @returns 0 on success, or a negative value on error. |
1766 | ||
1767 | @prenotnull{iter} | |
cfb61c11 JG |
1768 | @postrefcountsame{iter} |
1769 | ||
5c3f3b7e | 1770 | @sa |
3dca2276 | 1771 | bt_field_type_enumeration_mapping_iterator_signed_get(): |
5c3f3b7e PP |
1772 | Returns the name and the signed range of the current mapping of |
1773 | a given enumeration field type mapping iterator. | |
cfb61c11 | 1774 | */ |
3dca2276 | 1775 | extern int bt_field_type_enumeration_mapping_iterator_unsigned_get( |
50842bdc | 1776 | struct bt_field_type_enumeration_mapping_iterator *iter, |
5c3f3b7e | 1777 | const char **name, uint64_t *range_begin, uint64_t *range_end); |
cfb61c11 JG |
1778 | |
1779 | /** | |
5c3f3b7e | 1780 | @brief Advances the @enumftiter \p iter to the next mapping. |
cfb61c11 | 1781 | |
5c3f3b7e PP |
1782 | @param[in] iter Enumeration field type mapping iterator to |
1783 | advance. | |
1784 | @returns 0 on success, or a negative value on error or | |
1785 | when you reach the end of the set. | |
cfb61c11 JG |
1786 | |
1787 | @prenotnull{iter} | |
1788 | @postrefcountsame{iter} | |
1789 | */ | |
50842bdc PP |
1790 | extern int bt_field_type_enumeration_mapping_iterator_next( |
1791 | struct bt_field_type_enumeration_mapping_iterator *iter); | |
cfb61c11 JG |
1792 | |
1793 | /** @} */ | |
1794 | ||
78c8ab4f PP |
1795 | /** |
1796 | @defgroup ctfirstringfieldtype CTF IR string field type | |
1797 | @ingroup ctfirfieldtypes | |
1798 | @brief CTF IR string field type. | |
b92ddaaa | 1799 | |
78c8ab4f PP |
1800 | @code |
1801 | #include <babeltrace/ctf-ir/field-types.h> | |
1802 | @endcode | |
adc315b8 | 1803 | |
78c8ab4f | 1804 | A CTF IR <strong><em>string field type</em></strong> is a field type that |
4089d5a6 | 1805 | you can use to create concrete @stringfields. |
adc315b8 | 1806 | |
78c8ab4f | 1807 | You can create a string field type |
50842bdc | 1808 | with bt_field_type_string_create(). |
adc315b8 | 1809 | |
78c8ab4f | 1810 | A string field type has only one property: the \b encoding of its |
4089d5a6 | 1811 | described @stringfields. By default, the encoding of the string fields |
50842bdc | 1812 | described by a string field type is #BT_STRING_ENCODING_UTF8. You |
78c8ab4f | 1813 | can set the encoding of the string fields described by a string field |
50842bdc | 1814 | type with bt_field_type_string_set_encoding(). |
78c8ab4f PP |
1815 | |
1816 | @sa ctfirstringfield | |
1817 | @sa ctfirfieldtypes | |
1818 | ||
1819 | @addtogroup ctfirstringfieldtype | |
1820 | @{ | |
1821 | */ | |
1822 | ||
1823 | /** | |
4089d5a6 | 1824 | @brief Creates a default @stringft. |
78c8ab4f PP |
1825 | |
1826 | @returns Created string field type, or \c NULL on error. | |
1827 | ||
1828 | @postsuccessrefcountret1 | |
1829 | */ | |
50842bdc | 1830 | extern struct bt_field_type *bt_field_type_string_create(void); |
78c8ab4f PP |
1831 | |
1832 | /** | |
4089d5a6 PP |
1833 | @brief Returns the encoding of the @stringfields described by |
1834 | the @stringft \p string_field_type. | |
78c8ab4f PP |
1835 | |
1836 | @param[in] string_field_type String field type which describes the | |
1837 | string fields of which to get the | |
1838 | encoding. | |
1839 | @returns Encoding of the string | |
1840 | fields described by \p string_field_type, | |
50842bdc | 1841 | or #BT_STRING_ENCODING_UNKNOWN on |
78c8ab4f PP |
1842 | error. |
1843 | ||
1844 | @prenotnull{string_field_type} | |
1845 | @preisstringft{string_field_type} | |
1846 | @postrefcountsame{string_field_type} | |
1847 | ||
50842bdc | 1848 | @sa bt_field_type_string_set_encoding(): Sets the encoding |
78c8ab4f PP |
1849 | of the string fields described by a given string field type. |
1850 | */ | |
50842bdc PP |
1851 | extern enum bt_string_encoding bt_field_type_string_get_encoding( |
1852 | struct bt_field_type *string_field_type); | |
78c8ab4f PP |
1853 | |
1854 | /** | |
4089d5a6 PP |
1855 | @brief Sets the encoding of the @stringfields described by the |
1856 | @stringft \p string_field_type to \p encoding. | |
78c8ab4f PP |
1857 | |
1858 | @param[in] string_field_type String field type which describes the | |
1859 | string fields of which to set the | |
1860 | encoding. | |
1861 | @param[in] encoding Encoding of the string fields described | |
1862 | by \p string_field_type. | |
1863 | @returns 0 on success, or a negative value on error. | |
1864 | ||
1865 | @prenotnull{string_field_type} | |
1866 | @preisstringft{string_field_type} | |
1867 | @prehot{string_field_type} | |
50842bdc PP |
1868 | @pre \p encoding is #BT_STRING_ENCODING_ASCII or |
1869 | #BT_STRING_ENCODING_UTF8. | |
78c8ab4f PP |
1870 | @postrefcountsame{string_field_type} |
1871 | ||
50842bdc | 1872 | @sa bt_field_type_string_get_encoding(): Returns the encoding of |
78c8ab4f PP |
1873 | the string fields described by a given string field type. |
1874 | */ | |
50842bdc PP |
1875 | extern int bt_field_type_string_set_encoding( |
1876 | struct bt_field_type *string_field_type, | |
1877 | enum bt_string_encoding encoding); | |
78c8ab4f PP |
1878 | |
1879 | /** @} */ | |
1880 | ||
1881 | /** | |
1882 | @defgroup ctfirstructfieldtype CTF IR structure field type | |
1883 | @ingroup ctfirfieldtypes | |
1884 | @brief CTF IR structure field type. | |
1885 | ||
1886 | @code | |
1887 | #include <babeltrace/ctf-ir/field-types.h> | |
1888 | @endcode | |
1889 | ||
1890 | A CTF IR <strong><em>structure field type</em></strong> is | |
4089d5a6 | 1891 | a field type that you can use to create concrete @structfields. |
78c8ab4f PP |
1892 | |
1893 | You can create a structure field type | |
50842bdc | 1894 | with bt_field_type_structure_create(). This function creates |
78c8ab4f PP |
1895 | an empty structure field type, with no fields. |
1896 | ||
1897 | You can add a field to a structure field type with | |
50842bdc | 1898 | bt_field_type_structure_add_field(). Two fields in a structure |
78c8ab4f PP |
1899 | field type cannot have the same name. |
1900 | ||
1901 | You can set the \em minimum alignment of the structure fields described | |
1902 | by a structure field type with the common | |
50842bdc | 1903 | bt_field_type_set_alignment() function. The \em effective alignment |
78c8ab4f PP |
1904 | of the structure fields described by a structure field type, as per |
1905 | <a href="http://diamon.org/ctf/">CTF</a>, is the \em maximum value amongst | |
1906 | the effective alignments of all its fields. Note that the effective | |
4089d5a6 | 1907 | alignment of @varfields is always 1. |
78c8ab4f PP |
1908 | |
1909 | You can set the byte order of <em>all the contained fields</em>, | |
1910 | recursively, of a structure field type with the common | |
50842bdc | 1911 | bt_field_type_set_byte_order() function. |
78c8ab4f PP |
1912 | |
1913 | @sa ctfirstructfield | |
1914 | @sa ctfirfieldtypes | |
1915 | ||
1916 | @addtogroup ctfirstructfieldtype | |
1917 | @{ | |
1918 | */ | |
1919 | ||
1920 | /** | |
4089d5a6 | 1921 | @brief Creates a default, empty @structft. |
78c8ab4f PP |
1922 | |
1923 | @returns Created structure field type, | |
1924 | or \c NULL on error. | |
1925 | ||
1926 | @postsuccessrefcountret1 | |
1927 | */ | |
50842bdc | 1928 | extern struct bt_field_type *bt_field_type_structure_create(void); |
78c8ab4f PP |
1929 | |
1930 | /** | |
4089d5a6 PP |
1931 | @brief Returns the number of fields contained in the |
1932 | @structft \p struct_field_type. | |
78c8ab4f PP |
1933 | |
1934 | @param[in] struct_field_type Structure field type of which to get | |
1935 | the number of contained fields. | |
1936 | @returns Number of fields contained in | |
1937 | \p struct_field_type, or a negative | |
1938 | value on error. | |
1939 | ||
1940 | @prenotnull{struct_field_type} | |
1941 | @preisstructft{struct_field_type} | |
1942 | @postrefcountsame{struct_field_type} | |
1943 | */ | |
50842bdc PP |
1944 | extern int64_t bt_field_type_structure_get_field_count( |
1945 | struct bt_field_type *struct_field_type); | |
b92ddaaa | 1946 | |
094ff7c0 PP |
1947 | extern int bt_field_type_structure_borrow_field_by_index( |
1948 | struct bt_field_type *struct_field_type, | |
1949 | const char **field_name, struct bt_field_type **field_type, | |
1950 | uint64_t index); | |
1951 | ||
78c8ab4f | 1952 | /** |
4089d5a6 PP |
1953 | @brief Returns the field of the @structft \p struct_field_type |
1954 | at index \p index. | |
78c8ab4f PP |
1955 | |
1956 | On success, the field's type is placed in \p *field_type if | |
1957 | \p field_type is not \c NULL. The field's name is placed in | |
1958 | \p *field_name if \p field_name is not \c NULL. | |
1959 | \p struct_field_type remains the sole owner of \p *field_name. | |
1960 | ||
1961 | @param[in] struct_field_type Structure field type of which to get | |
1962 | the field at index \p index. | |
1963 | @param[out] field_name Returned name of the field at index | |
1964 | \p index (can be \c NULL). | |
1965 | @param[out] field_type Returned field type of the field | |
1966 | at index \p index (can be \c NULL). | |
1967 | @param[in] index Index of the field to get from | |
1968 | \p struct_field_type. | |
1969 | @returns 0 on success, or a negative value on error. | |
1970 | ||
1971 | @prenotnull{struct_field_type} | |
1972 | @preisstructft{struct_field_type} | |
1973 | @pre \p index is lesser than the number of fields contained in the | |
1974 | structure field type \p struct_field_type (see | |
50842bdc | 1975 | bt_field_type_structure_get_field_count()). |
78c8ab4f PP |
1976 | @postrefcountsame{struct_field_type} |
1977 | @post <strong>On success</strong>, the returned field's type is placed | |
1978 | in \p *field_type and its reference count is incremented. | |
1979 | ||
50842bdc | 1980 | @sa bt_field_type_structure_get_field_type_by_name(): Finds a |
78c8ab4f PP |
1981 | structure field type's field by name. |
1982 | */ | |
094ff7c0 PP |
1983 | static inline |
1984 | int bt_field_type_structure_get_field_by_index( | |
50842bdc PP |
1985 | struct bt_field_type *struct_field_type, |
1986 | const char **field_name, struct bt_field_type **field_type, | |
094ff7c0 PP |
1987 | uint64_t index) |
1988 | { | |
1989 | int ret = bt_field_type_structure_borrow_field_by_index( | |
1990 | struct_field_type, field_name, field_type, index); | |
1991 | ||
1992 | if (ret == 0 && field_type) { | |
1993 | bt_get(*field_type); | |
1994 | } | |
1995 | ||
1996 | return ret; | |
1997 | } | |
1998 | ||
1999 | extern | |
2000 | struct bt_field_type *bt_field_type_structure_borrow_field_type_by_name( | |
2001 | struct bt_field_type *struct_field_type, | |
2002 | const char *field_name); | |
9ac68eb1 | 2003 | |
78c8ab4f PP |
2004 | /** |
2005 | @brief Returns the type of the field named \p field_name found in | |
4089d5a6 | 2006 | the @structft \p struct_field_type. |
78c8ab4f PP |
2007 | |
2008 | @param[in] struct_field_type Structure field type of which to get | |
2009 | a field's type. | |
2010 | @param[in] field_name Name of the field to find. | |
2011 | @returns Type of the field named \p field_name in | |
2012 | \p struct_field_type, or | |
2013 | \c NULL on error. | |
2014 | ||
2015 | @prenotnull{struct_field_type} | |
2016 | @prenotnull{field_name} | |
2017 | @preisstructft{struct_field_type} | |
2018 | @postrefcountsame{struct_field_type} | |
2019 | @postsuccessrefcountretinc | |
2020 | ||
50842bdc | 2021 | @sa bt_field_type_structure_get_field_by_index(): Finds a |
78c8ab4f PP |
2022 | structure field type's field by index. |
2023 | */ | |
094ff7c0 | 2024 | static inline |
50842bdc PP |
2025 | struct bt_field_type *bt_field_type_structure_get_field_type_by_name( |
2026 | struct bt_field_type *struct_field_type, | |
094ff7c0 PP |
2027 | const char *field_name) |
2028 | { | |
2029 | return bt_get(bt_field_type_structure_borrow_field_type_by_name( | |
2030 | struct_field_type, field_name)); | |
2031 | } | |
b92ddaaa | 2032 | |
78c8ab4f | 2033 | /** |
4089d5a6 PP |
2034 | @brief Adds a field named \p field_name with the @ft |
2035 | \p field_type to the @structft \p struct_field_type. | |
78c8ab4f PP |
2036 | |
2037 | On success, \p field_type becomes the child of \p struct_field_type. | |
2038 | ||
2039 | This function adds the new field after the current last field of | |
2040 | \p struct_field_type (append mode). | |
2041 | ||
2042 | You \em cannot add a field named \p field_name if there's already a | |
2043 | field named \p field_name in \p struct_field_type. | |
2044 | ||
2045 | @param[in] struct_field_type Structure field type to which to add | |
2046 | a new field. | |
2047 | @param[in] field_type Field type of the field to add to | |
2048 | \p struct_field_type. | |
2049 | @param[in] field_name Name of the field to add to | |
2050 | \p struct_field_type | |
2051 | (copied on success). | |
2052 | @returns 0 on success, or a negative value on error. | |
2053 | ||
2054 | @prenotnull{struct_field_type} | |
2055 | @prenotnull{field_type} | |
2056 | @prenotnull{field_name} | |
2057 | @preisstructft{struct_field_type} | |
2058 | @pre \p field_type is not and does not contain \p struct_field_type, | |
2059 | recursively, as a field's type. | |
2060 | @prehot{struct_field_type} | |
2061 | @postrefcountsame{struct_field_type} | |
2062 | @postsuccessrefcountinc{field_type} | |
2063 | */ | |
50842bdc PP |
2064 | extern int bt_field_type_structure_add_field( |
2065 | struct bt_field_type *struct_field_type, | |
2066 | struct bt_field_type *field_type, | |
78c8ab4f | 2067 | const char *field_name); |
b92ddaaa | 2068 | |
78c8ab4f | 2069 | /** @} */ |
b92ddaaa | 2070 | |
78c8ab4f PP |
2071 | /** |
2072 | @defgroup ctfirarrayfieldtype CTF IR array field type | |
2073 | @ingroup ctfirfieldtypes | |
2074 | @brief CTF IR array field type. | |
adc315b8 | 2075 | |
78c8ab4f PP |
2076 | @code |
2077 | #include <babeltrace/ctf-ir/field-types.h> | |
2078 | @endcode | |
d9b1ab6d | 2079 | |
78c8ab4f | 2080 | A CTF IR <strong><em>array field type</em></strong> is a field type that |
4089d5a6 | 2081 | you can use to create concrete @arrayfields. |
adc315b8 | 2082 | |
78c8ab4f | 2083 | You can create an array field type |
50842bdc | 2084 | with bt_field_type_array_create(). This function needs |
4089d5a6 PP |
2085 | the @ft of the fields contained by the array fields described by the |
2086 | array field type to create. | |
b92ddaaa | 2087 | |
78c8ab4f PP |
2088 | @sa ctfirarrayfield |
2089 | @sa ctfirfieldtypes | |
b92ddaaa | 2090 | |
78c8ab4f PP |
2091 | @addtogroup ctfirarrayfieldtype |
2092 | @{ | |
2093 | */ | |
b92ddaaa | 2094 | |
78c8ab4f | 2095 | /** |
4089d5a6 | 2096 | @brief Creates a default @arrayft with |
78c8ab4f | 2097 | \p element_field_type as the field type of the fields contained |
4089d5a6 | 2098 | in its described @arrayfields of length \p length. |
78c8ab4f PP |
2099 | |
2100 | @param[in] element_field_type Field type of the fields contained in | |
2101 | the array fields described by the | |
2102 | created array field type. | |
2103 | @param[in] length Length of the array fields described by | |
2104 | the created array field type. | |
2105 | @returns Created array field type, or | |
2106 | \c NULL on error. | |
2107 | ||
2108 | @prenotnull{element_field_type} | |
2109 | @postsuccessrefcountinc{element_field_type} | |
2110 | @postsuccessrefcountret1 | |
2111 | */ | |
50842bdc PP |
2112 | extern struct bt_field_type *bt_field_type_array_create( |
2113 | struct bt_field_type *element_field_type, | |
78c8ab4f | 2114 | unsigned int length); |
b92ddaaa | 2115 | |
094ff7c0 PP |
2116 | extern struct bt_field_type *bt_field_type_array_borrow_element_field_type( |
2117 | struct bt_field_type *array_field_type); | |
2118 | ||
78c8ab4f | 2119 | /** |
4089d5a6 PP |
2120 | @brief Returns the @ft of the @fields contained in |
2121 | the @arrayfields described by the @arrayft \p array_field_type. | |
78c8ab4f PP |
2122 | |
2123 | @param[in] array_field_type Array field type of which to get | |
2124 | the type of the fields contained in its | |
2125 | described array fields. | |
2126 | @returns Type of the fields contained in the | |
2127 | array fields described by | |
2128 | \p array_field_type, or \c NULL | |
2129 | on error. | |
2130 | ||
2131 | @prenotnull{array_field_type} | |
2132 | @preisarrayft{array_field_type} | |
2133 | @postrefcountsame{array_field_type} | |
2134 | @postsuccessrefcountretinc | |
2135 | */ | |
094ff7c0 PP |
2136 | static inline |
2137 | struct bt_field_type *bt_field_type_array_get_element_field_type( | |
2138 | struct bt_field_type *array_field_type) | |
2139 | { | |
2140 | return bt_get(bt_field_type_array_borrow_element_field_type( | |
2141 | array_field_type)); | |
2142 | } | |
b92ddaaa | 2143 | |
78c8ab4f | 2144 | /** |
4089d5a6 PP |
2145 | @brief Returns the number of @fields contained in the |
2146 | @arrayfields described by the @arrayft \p array_field_type. | |
78c8ab4f PP |
2147 | |
2148 | @param[in] array_field_type Array field type of which to get | |
2149 | the number of fields contained in its | |
2150 | described array fields. | |
2151 | @returns Number of fields contained in the | |
2152 | array fields described by | |
2153 | \p array_field_type, or a negative value | |
2154 | on error. | |
2155 | ||
2156 | @prenotnull{array_field_type} | |
2157 | @preisarrayft{array_field_type} | |
2158 | @postrefcountsame{array_field_type} | |
2159 | */ | |
50842bdc PP |
2160 | extern int64_t bt_field_type_array_get_length( |
2161 | struct bt_field_type *array_field_type); | |
adc315b8 | 2162 | |
78c8ab4f | 2163 | /** @} */ |
adc315b8 | 2164 | |
78c8ab4f PP |
2165 | /** |
2166 | @defgroup ctfirseqfieldtype CTF IR sequence field type | |
2167 | @ingroup ctfirfieldtypes | |
2168 | @brief CTF IR sequence field type. | |
b92ddaaa | 2169 | |
78c8ab4f PP |
2170 | @code |
2171 | #include <babeltrace/ctf-ir/field-types.h> | |
2172 | @endcode | |
b92ddaaa | 2173 | |
78c8ab4f | 2174 | A CTF IR <strong><em>sequence field type</em></strong> is |
4089d5a6 | 2175 | a field type that you can use to create concrete @seqfields. |
adc315b8 | 2176 | |
78c8ab4f | 2177 | You can create a sequence field type with |
50842bdc | 2178 | bt_field_type_sequence_create(). This function needs the @ft |
78c8ab4f PP |
2179 | of the fields contained by the sequence fields described by the created |
2180 | sequence field type. This function also needs the length name of the | |
2181 | sequence field type to create. The length name is used to automatically | |
2182 | resolve the length's field type. See \ref ctfirfieldtypes to learn more | |
2183 | about the automatic resolving. | |
b92ddaaa | 2184 | |
78c8ab4f PP |
2185 | @sa ctfirseqfield |
2186 | @sa ctfirfieldtypes | |
adc315b8 | 2187 | |
78c8ab4f PP |
2188 | @addtogroup ctfirseqfieldtype |
2189 | @{ | |
2190 | */ | |
b92ddaaa | 2191 | |
78c8ab4f | 2192 | /** |
4089d5a6 PP |
2193 | @brief Creates a default @seqft with \p element_field_type as the |
2194 | @ft of the @fields contained in its described @seqfields | |
2195 | with the length name \p length_name. | |
78c8ab4f PP |
2196 | |
2197 | \p length_name can be an absolute or relative reference. See | |
2198 | <a href="http://diamon.org/ctf/">CTF</a> for more details. | |
2199 | ||
2200 | @param[in] element_field_type Field type of the fields contained in | |
2201 | the sequence fields described by the | |
2202 | created sequence field type. | |
2203 | @param[in] length_name Length name (copied on success). | |
2204 | @returns Created array field type, or | |
2205 | \c NULL on error. | |
2206 | ||
2207 | @prenotnull{element_field_type} | |
2208 | @prenotnull{length_name} | |
2209 | @postsuccessrefcountinc{element_field_type} | |
2210 | @postsuccessrefcountret1 | |
2211 | */ | |
50842bdc PP |
2212 | extern struct bt_field_type *bt_field_type_sequence_create( |
2213 | struct bt_field_type *element_field_type, | |
78c8ab4f | 2214 | const char *length_name); |
adc315b8 | 2215 | |
094ff7c0 PP |
2216 | extern struct bt_field_type *bt_field_type_sequence_borrow_element_field_type( |
2217 | struct bt_field_type *sequence_field_type); | |
2218 | ||
78c8ab4f | 2219 | /** |
4089d5a6 PP |
2220 | @brief Returns the @ft of the @fields contained in the @seqft |
2221 | described by the @seqft \p sequence_field_type. | |
78c8ab4f PP |
2222 | |
2223 | @param[in] sequence_field_type Sequence field type of which to get | |
2224 | the type of the fields contained in its | |
2225 | described sequence fields. | |
2226 | @returns Type of the fields contained in the | |
2227 | sequence fields described by | |
2228 | \p sequence_field_type, or \c NULL | |
2229 | on error. | |
2230 | ||
2231 | @prenotnull{sequence_field_type} | |
2232 | @preisseqft{sequence_field_type} | |
2233 | @postrefcountsame{sequence_field_type} | |
2234 | @postsuccessrefcountretinc | |
2235 | */ | |
094ff7c0 PP |
2236 | static inline |
2237 | struct bt_field_type *bt_field_type_sequence_get_element_field_type( | |
2238 | struct bt_field_type *sequence_field_type) | |
2239 | { | |
2240 | return bt_get(bt_field_type_sequence_borrow_element_field_type( | |
2241 | sequence_field_type)); | |
2242 | } | |
b92ddaaa | 2243 | |
78c8ab4f | 2244 | /** |
4089d5a6 | 2245 | @brief Returns the length name of the @seqft \p sequence_field_type. |
adc315b8 | 2246 | |
78c8ab4f PP |
2247 | On success, \p sequence_field_type remains the sole owner of |
2248 | the returned string. | |
b011f6b0 | 2249 | |
78c8ab4f PP |
2250 | @param[in] sequence_field_type Sequence field type of which to get the |
2251 | length name. | |
2252 | @returns Length name of \p sequence_field_type, | |
2253 | or \c NULL on error. | |
2254 | ||
2255 | @prenotnull{sequence_field_type} | |
2256 | @preisseqft{sequence_field_type} | |
2257 | ||
50842bdc | 2258 | @sa bt_field_type_sequence_get_length_field_path(): Returns the |
78c8ab4f PP |
2259 | length's CTF IR field path of a given sequence field type. |
2260 | */ | |
50842bdc PP |
2261 | extern const char *bt_field_type_sequence_get_length_field_name( |
2262 | struct bt_field_type *sequence_field_type); | |
78c8ab4f | 2263 | |
094ff7c0 PP |
2264 | extern struct bt_field_path *bt_field_type_sequence_borrow_length_field_path( |
2265 | struct bt_field_type *sequence_field_type); | |
2266 | ||
78c8ab4f | 2267 | /** |
4089d5a6 PP |
2268 | @brief Returns the length's CTF IR field path of the @seqft |
2269 | \p sequence_field_type. | |
78c8ab4f PP |
2270 | |
2271 | The length's field path of a sequence field type is set when automatic | |
2272 | resolving is performed (see \ref ctfirfieldtypes). | |
2273 | ||
2274 | @param[in] sequence_field_type Sequence field type of which to get the | |
2275 | length's field path. | |
2276 | @returns Length's field path of | |
2277 | \p sequence_field_type, or | |
2278 | \c NULL if the length's field path is | |
2279 | not set yet is not set or on error. | |
2280 | ||
2281 | @prenotnull{sequence_field_type} | |
2282 | @preisseqft{sequence_field_type} | |
2283 | @postsuccessrefcountretinc | |
2284 | ||
50842bdc | 2285 | @sa bt_field_type_sequence_get_length_field_name(): Returns the |
78c8ab4f PP |
2286 | length's name of a given sequence field type. |
2287 | */ | |
094ff7c0 PP |
2288 | static inline |
2289 | struct bt_field_path *bt_field_type_sequence_get_length_field_path( | |
2290 | struct bt_field_type *sequence_field_type) | |
2291 | { | |
2292 | return bt_get(bt_field_type_sequence_borrow_length_field_path( | |
2293 | sequence_field_type)); | |
2294 | } | |
b011f6b0 | 2295 | |
78c8ab4f | 2296 | /** @} */ |
265e809c | 2297 | |
78c8ab4f PP |
2298 | /** |
2299 | @defgroup ctfirvarfieldtype CTF IR variant field type | |
2300 | @ingroup ctfirfieldtypes | |
2301 | @brief CTF IR variant field type. | |
2302 | ||
2303 | @code | |
2304 | #include <babeltrace/ctf-ir/field-types.h> | |
2305 | @endcode | |
2306 | ||
2307 | A CTF IR <strong><em>variant field type</em></strong> is | |
4089d5a6 PP |
2308 | a field type that you can use to create concrete @varfields. |
2309 | ||
2310 | You can create a variant field type with | |
50842bdc | 2311 | bt_field_type_variant_create(). This function expects you to pass |
4089d5a6 PP |
2312 | both the tag's @enumft and the tag name of the variant field type to |
2313 | create. The tag's field type is optional, as the Babeltrace system can | |
2314 | automatically resolve it using the tag name. You can leave the tag name | |
2315 | to \c NULL initially, and set it later with | |
50842bdc | 2316 | bt_field_type_variant_set_tag_name(). The tag name must be set when |
4089d5a6 PP |
2317 | the variant field type is frozen. See \ref ctfirfieldtypes to learn more |
2318 | about the automatic resolving and the conditions under which a field | |
2319 | type can be frozen. | |
78c8ab4f PP |
2320 | |
2321 | You can add a field to a variant field type with | |
50842bdc | 2322 | bt_field_type_variant_add_field(). All the field names of a |
4089d5a6 | 2323 | variant field type \em must exist as mapping names in its tag's @enumft. |
78c8ab4f | 2324 | |
4089d5a6 | 2325 | The effective alignment of the @varfields described by a |
78c8ab4f | 2326 | variant field type is always 1, but the individual fields of a |
4089d5a6 | 2327 | @varfield can have custom alignments. |
78c8ab4f PP |
2328 | |
2329 | You can set the byte order of <em>all the contained fields</em>, | |
2330 | recursively, of a variant field type with the common | |
50842bdc | 2331 | bt_field_type_set_byte_order() function. |
78c8ab4f PP |
2332 | |
2333 | @sa ctfirvarfield | |
2334 | @sa ctfirfieldtypes | |
2335 | ||
2336 | @addtogroup ctfirvarfieldtype | |
2337 | @{ | |
2338 | */ | |
06629ab3 | 2339 | |
78c8ab4f | 2340 | /** |
4089d5a6 | 2341 | @brief Creates a default, empty @varft with the tag's @enumft |
78c8ab4f PP |
2342 | \p tag_field_type and the tag name \p tag_name. |
2343 | ||
2344 | \p tag_field_type can be \c NULL; the tag's field type can be | |
2345 | automatically resolved from the variant field type's tag name (see | |
2346 | \ref ctfirfieldtypes). If \p tag_name is \c NULL, it \em must be set | |
50842bdc | 2347 | with bt_field_type_variant_set_tag_name() \em before the variant |
78c8ab4f PP |
2348 | field type is frozen. |
2349 | ||
2350 | \p tag_name can be an absolute or relative reference. See | |
2351 | <a href="http://diamon.org/ctf/">CTF</a> for more details. | |
2352 | ||
2353 | @param[in] tag_field_type Tag's enumeration field type | |
2354 | (can be \c NULL). | |
2355 | @param[in] tag_name Tag name (copied on success, | |
2356 | can be \c NULL). | |
2357 | @returns Created variant field type, or | |
2358 | \c NULL on error. | |
2359 | ||
2360 | @pre \p tag_field_type is an enumeration field type or \c NULL. | |
2361 | @post <strong>On success, if \p tag_field_type is not \c NULL</strong>, | |
2362 | its reference count is incremented. | |
2363 | @postsuccessrefcountret1 | |
2364 | */ | |
50842bdc PP |
2365 | extern struct bt_field_type *bt_field_type_variant_create( |
2366 | struct bt_field_type *tag_field_type, | |
78c8ab4f | 2367 | const char *tag_name); |
b92ddaaa | 2368 | |
094ff7c0 PP |
2369 | extern struct bt_field_type *bt_field_type_variant_borrow_tag_field_type( |
2370 | struct bt_field_type *variant_field_type); | |
2371 | ||
78c8ab4f | 2372 | /** |
4089d5a6 | 2373 | @brief Returns the tag's @enumft of the @varft \p variant_field_type. |
78c8ab4f PP |
2374 | |
2375 | @param[in] variant_field_type Variant field type of which to get | |
2376 | the tag's enumeration field type. | |
2377 | @returns Tag's enumeration field type of | |
2378 | \p variant_field_type, or \c NULL if the | |
2379 | tag's field type is not set or on | |
2380 | error. | |
2381 | ||
2382 | @prenotnull{variant_field_type} | |
2383 | @preisvarft{variant_field_type} | |
2384 | @postrefcountsame{variant_field_type} | |
2385 | @postsuccessrefcountretinc | |
2386 | */ | |
094ff7c0 PP |
2387 | static inline |
2388 | struct bt_field_type *bt_field_type_variant_get_tag_field_type( | |
2389 | struct bt_field_type *variant_field_type) | |
2390 | { | |
2391 | return bt_get(bt_field_type_variant_borrow_tag_field_type( | |
2392 | variant_field_type)); | |
2393 | } | |
56db8d7a | 2394 | |
78c8ab4f | 2395 | /** |
4089d5a6 | 2396 | @brief Returns the tag name of the @varft \p variant_field_type. |
78c8ab4f PP |
2397 | |
2398 | On success, \p variant_field_type remains the sole owner of | |
2399 | the returned string. | |
2400 | ||
2401 | @param[in] variant_field_type Variant field type of which to get the | |
2402 | tag name. | |
2403 | @returns Tag name of \p variant_field_type, or | |
2404 | \c NULL if the tag name is not set or | |
2405 | on error. | |
2406 | ||
2407 | @prenotnull{variant_field_type} | |
2408 | @preisvarft{variant_field_type} | |
2409 | ||
50842bdc | 2410 | @sa bt_field_type_variant_set_tag_name(): Sets the tag name of |
78c8ab4f | 2411 | a given variant field type. |
50842bdc | 2412 | @sa bt_field_type_variant_get_tag_field_path(): Returns the tag's |
78c8ab4f PP |
2413 | CTF IR field path of a given variant field type. |
2414 | */ | |
50842bdc PP |
2415 | extern const char *bt_field_type_variant_get_tag_name( |
2416 | struct bt_field_type *variant_field_type); | |
56db8d7a | 2417 | |
78c8ab4f | 2418 | /** |
4089d5a6 | 2419 | @brief Sets the tag name of the @varft \p variant_field_type. |
78c8ab4f PP |
2420 | |
2421 | \p tag_name can be an absolute or relative reference. See | |
2422 | <a href="http://diamon.org/ctf/">CTF</a> for more details. | |
2423 | ||
2424 | @param[in] variant_field_type Variant field type of which to set | |
2425 | the tag name. | |
2426 | @param[in] tag_name Tag name of \p variant_field_type | |
2427 | (copied on success). | |
2428 | @returns 0 on success, or a negative value on error. | |
2429 | ||
2430 | @prenotnull{variant_field_type} | |
2431 | @prenotnull{name} | |
2432 | @prehot{variant_field_type} | |
2433 | @postrefcountsame{variant_field_type} | |
2434 | ||
50842bdc | 2435 | @sa bt_field_type_variant_get_tag_name(): Returns the tag name of |
78c8ab4f PP |
2436 | a given variant field type. |
2437 | */ | |
50842bdc PP |
2438 | extern int bt_field_type_variant_set_tag_name( |
2439 | struct bt_field_type *variant_field_type, | |
78c8ab4f | 2440 | const char *tag_name); |
56db8d7a | 2441 | |
094ff7c0 PP |
2442 | extern struct bt_field_path *bt_field_type_variant_borrow_tag_field_path( |
2443 | struct bt_field_type *variant_field_type); | |
2444 | ||
78c8ab4f | 2445 | /** |
4089d5a6 PP |
2446 | @brief Returns the tag's CTF IR field path of the @varft |
2447 | \p variant_field_type. | |
78c8ab4f PP |
2448 | |
2449 | The tag's field path of a variant field type is set when automatic | |
2450 | resolving is performed (see \ref ctfirfieldtypes). | |
2451 | ||
2452 | @param[in] variant_field_type Variant field type of which to get the | |
2453 | tag's field path. | |
2454 | @returns Tag's field path of | |
2455 | \p variant_field_type, or | |
2456 | \c NULL if the tag's field path is not | |
2457 | set yet is not set or on error. | |
2458 | ||
2459 | @prenotnull{variant_field_type} | |
2460 | @preisvarft{variant_field_type} | |
2461 | @postsuccessrefcountretinc | |
2462 | ||
50842bdc | 2463 | @sa bt_field_type_variant_get_tag_name(): Returns the tag's |
78c8ab4f PP |
2464 | name of a given variant field type. |
2465 | */ | |
094ff7c0 PP |
2466 | static inline |
2467 | struct bt_field_path *bt_field_type_variant_get_tag_field_path( | |
2468 | struct bt_field_type *variant_field_type) | |
2469 | { | |
2470 | return bt_get(bt_field_type_variant_borrow_tag_field_path( | |
2471 | variant_field_type)); | |
2472 | } | |
56db8d7a | 2473 | |
78c8ab4f | 2474 | /** |
4089d5a6 PP |
2475 | @brief Returns the number of fields (choices) contained in the @varft |
2476 | \p variant_field_type. | |
78c8ab4f PP |
2477 | |
2478 | @param[in] variant_field_type Variant field type of which to get | |
2479 | the number of contained fields. | |
2480 | @returns Number of fields contained in | |
2481 | \p variant_field_type, or a negative | |
2482 | value on error. | |
2483 | ||
2484 | @prenotnull{variant_field_type} | |
2485 | @preisvarft{variant_field_type} | |
2486 | @postrefcountsame{variant_field_type} | |
2487 | */ | |
50842bdc PP |
2488 | extern int64_t bt_field_type_variant_get_field_count( |
2489 | struct bt_field_type *variant_field_type); | |
56db8d7a | 2490 | |
094ff7c0 PP |
2491 | extern int bt_field_type_variant_borrow_field_by_index( |
2492 | struct bt_field_type *variant_field_type, | |
2493 | const char **field_name, | |
2494 | struct bt_field_type **field_type, uint64_t index); | |
2495 | ||
78c8ab4f | 2496 | /** |
4089d5a6 PP |
2497 | @brief Returns the field (choice) of the @varft \p variant_field_type |
2498 | at index \p index. | |
78c8ab4f PP |
2499 | |
2500 | On success, the field's type is placed in \p *field_type if | |
2501 | \p field_type is not \c NULL. The field's name is placed in | |
2502 | \p *field_name if \p field_name is not \c NULL. | |
2503 | \p variant_field_type remains the sole owner of \p *field_name. | |
2504 | ||
2505 | @param[in] variant_field_type Variant field type of which to get | |
2506 | the field at index \p index. | |
2507 | @param[out] field_name Returned name of the field at index | |
2508 | \p index (can be \c NULL). | |
2509 | @param[out] field_type Returned field type of the field | |
2510 | at index \p index (can be \c NULL). | |
2511 | @param[in] index Index of the field to get from | |
2512 | \p variant_field_type. | |
2513 | @returns 0 on success, or a negative value on error. | |
2514 | ||
2515 | @prenotnull{variant_field_type} | |
2516 | @preisvarft{variant_field_type} | |
2517 | @pre \p index is lesser than the number of fields contained in the | |
2518 | variant field type \p variant_field_type (see | |
50842bdc | 2519 | bt_field_type_variant_get_field_count()). |
78c8ab4f PP |
2520 | @postrefcountsame{variant_field_type} |
2521 | @post <strong>On success</strong>, the returned field's type is placed | |
2522 | in \p *field_type and its reference count is incremented. | |
2523 | ||
50842bdc | 2524 | @sa bt_field_type_variant_get_field_type_by_name(): Finds a variant |
78c8ab4f | 2525 | field type's field by name. |
50842bdc | 2526 | @sa bt_field_type_variant_get_field_type_from_tag(): Finds a variant |
78c8ab4f PP |
2527 | field type's field by current tag value. |
2528 | */ | |
094ff7c0 PP |
2529 | static inline |
2530 | int bt_field_type_variant_get_field_by_index( | |
50842bdc | 2531 | struct bt_field_type *variant_field_type, |
78c8ab4f | 2532 | const char **field_name, |
094ff7c0 PP |
2533 | struct bt_field_type **field_type, uint64_t index) |
2534 | { | |
2535 | int ret = bt_field_type_variant_borrow_field_by_index( | |
2536 | variant_field_type, field_name, field_type, index); | |
2537 | ||
2538 | if (ret == 0 && field_type) { | |
2539 | bt_get(*field_type); | |
2540 | } | |
2541 | ||
2542 | return ret; | |
2543 | } | |
2544 | ||
2545 | extern | |
2546 | struct bt_field_type *bt_field_type_variant_borrow_field_type_by_name( | |
2547 | struct bt_field_type *variant_field_type, | |
2548 | const char *field_name); | |
56db8d7a | 2549 | |
78c8ab4f PP |
2550 | /** |
2551 | @brief Returns the type of the field (choice) named \p field_name | |
4089d5a6 | 2552 | found in the @varft \p variant_field_type. |
78c8ab4f PP |
2553 | |
2554 | @param[in] variant_field_type Variant field type of which to get | |
2555 | a field's type. | |
2556 | @param[in] field_name Name of the field to find. | |
2557 | @returns Type of the field named \p field_name in | |
2558 | \p variant_field_type, or | |
2559 | \c NULL on error. | |
2560 | ||
2561 | @prenotnull{variant_field_type} | |
2562 | @prenotnull{field_name} | |
2563 | @preisvarft{variant_field_type} | |
2564 | @postrefcountsame{variant_field_type} | |
2565 | @postsuccessrefcountretinc | |
2566 | ||
50842bdc | 2567 | @sa bt_field_type_variant_get_field_by_index(): Finds a variant field type's |
78c8ab4f | 2568 | field by index. |
50842bdc | 2569 | @sa bt_field_type_variant_get_field_type_from_tag(): Finds a variant |
78c8ab4f PP |
2570 | field type's field by current tag value. |
2571 | */ | |
094ff7c0 | 2572 | static inline |
50842bdc PP |
2573 | struct bt_field_type *bt_field_type_variant_get_field_type_by_name( |
2574 | struct bt_field_type *variant_field_type, | |
094ff7c0 PP |
2575 | const char *field_name) |
2576 | { | |
2577 | return bt_get(bt_field_type_variant_borrow_field_type_by_name( | |
2578 | variant_field_type, field_name)); | |
2579 | } | |
2580 | ||
2581 | extern | |
2582 | struct bt_field_type *bt_field_type_variant_borrow_field_type_from_tag( | |
2583 | struct bt_field_type *variant_field_type, | |
2584 | struct bt_field *tag_field); | |
56db8d7a | 2585 | |
78c8ab4f PP |
2586 | /** |
2587 | @brief Returns the type of the field (choice) selected by the value of | |
4089d5a6 | 2588 | the @enumfield \p tag_field in the @varft \p variant_field_type. |
78c8ab4f PP |
2589 | |
2590 | \p tag_field is the current tag value. | |
2591 | ||
50842bdc | 2592 | The field type of \p tag_field, as returned by bt_field_get_type(), |
78c8ab4f | 2593 | \em must be equivalent to the field type returned by |
3dca2276 | 2594 | bt_field_type_variant_get_tag_field_type() for \p variant_field_type. |
78c8ab4f PP |
2595 | |
2596 | @param[in] variant_field_type Variant field type of which to get | |
2597 | a field's type. | |
2598 | @param[in] tag_field Current tag value (variant field type's | |
2599 | selector). | |
2600 | @returns Type of the field selected by | |
2601 | \p tag_field in \p variant_field_type, | |
2602 | or \c NULL on error. | |
2603 | ||
2604 | @prenotnull{variant_field_type} | |
2605 | @prenotnull{tag_field} | |
2606 | @preisvarft{variant_field_type} | |
2607 | @preisenumfield{tag_field} | |
2608 | @postrefcountsame{variant_field_type} | |
2609 | @postrefcountsame{tag_field} | |
2610 | @postsuccessrefcountretinc | |
2611 | ||
50842bdc | 2612 | @sa bt_field_type_variant_get_field_by_index(): Finds a variant field type's |
78c8ab4f | 2613 | field by index. |
50842bdc | 2614 | @sa bt_field_type_variant_get_field_type_by_name(): Finds a variant |
78c8ab4f PP |
2615 | field type's field by name. |
2616 | */ | |
094ff7c0 | 2617 | static inline |
50842bdc PP |
2618 | struct bt_field_type *bt_field_type_variant_get_field_type_from_tag( |
2619 | struct bt_field_type *variant_field_type, | |
094ff7c0 PP |
2620 | struct bt_field *tag_field) |
2621 | { | |
2622 | return bt_get(bt_field_type_variant_borrow_field_type_from_tag( | |
2623 | variant_field_type, tag_field)); | |
2624 | } | |
78c8ab4f PP |
2625 | |
2626 | /** | |
4089d5a6 PP |
2627 | @brief Adds a field (a choice) named \p field_name with the @ft |
2628 | \p field_type to the @varft \p variant_field_type. | |
78c8ab4f PP |
2629 | |
2630 | On success, \p field_type becomes the child of \p variant_field_type. | |
2631 | ||
2632 | You \em cannot add a field named \p field_name if there's already a | |
2633 | field named \p field_name in \p variant_field_type. | |
2634 | ||
2635 | \p field_name \em must name an existing mapping in the tag's | |
2636 | enumeration field type of \p variant_field_type. | |
2637 | ||
2638 | @param[in] variant_field_type Variant field type to which to add | |
2639 | a new field. | |
2640 | @param[in] field_type Field type of the field to add to | |
2641 | \p variant_field_type. | |
2642 | @param[in] field_name Name of the field to add to | |
2643 | \p variant_field_type | |
2644 | (copied on success). | |
2645 | @returns 0 on success, or a negative value on error. | |
2646 | ||
2647 | @prenotnull{variant_field_type} | |
2648 | @prenotnull{field_type} | |
2649 | @prenotnull{field_name} | |
2650 | @preisvarft{variant_field_type} | |
2651 | @pre \p field_type is not and does not contain \p variant_field_type, | |
2652 | recursively, as a field's type. | |
2653 | @prehot{variant_field_type} | |
2654 | @postrefcountsame{variant_field_type} | |
2655 | @postsuccessrefcountinc{field_type} | |
2656 | */ | |
50842bdc PP |
2657 | extern int bt_field_type_variant_add_field( |
2658 | struct bt_field_type *variant_field_type, | |
2659 | struct bt_field_type *field_type, | |
78c8ab4f PP |
2660 | const char *field_name); |
2661 | ||
2662 | /** @} */ | |
56db8d7a | 2663 | |
adc315b8 JG |
2664 | #ifdef __cplusplus |
2665 | } | |
2666 | #endif | |
2667 | ||
2e33ac5a | 2668 | #endif /* BABELTRACE_CTF_IR_FIELD_TYPES_H */ |