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