Docs: add documentation for bt_ctf_field_type_enumeration_find_mappings*
[babeltrace.git] / include / babeltrace / ctf-ir / field-types.h
1 #ifndef BABELTRACE_CTF_IR_FIELD_TYPES_H
2 #define BABELTRACE_CTF_IR_FIELD_TYPES_H
3
4 /*
5 * BabelTrace - CTF IR: Event field types
6 *
7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
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
33 #include <stdint.h>
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 /**
40 @defgroup ctfirfieldtypes CTF IR field types
41 @ingroup ctfir
42 @brief CTF IR field types.
43
44 @code
45 #include <babeltrace/ctf-ir/field-types.h>
46 @endcode
47
48 A CTF IR <strong><em>field type</em></strong> is a field type that you
49 can use to create concrete @fields.
50
51 You can create a @field object from a CTF IR field type object
52 with bt_ctf_field_create().
53
54 In the CTF IR hierarchy, you can set the root field types of three
55 objects:
56
57 - \ref ctfirtraceclass
58 - Trace packet header field type: bt_ctf_trace_set_packet_header_type().
59 - \ref ctfirstreamclass
60 - Stream packet context field type:
61 bt_ctf_stream_class_set_packet_context_type().
62 - Stream event header field type:
63 bt_ctf_stream_class_set_event_header_type().
64 - Stream event context field type:
65 bt_ctf_stream_class_set_event_context_type().
66 - \ref ctfireventclass
67 - Event context field type: bt_ctf_event_class_set_context_type().
68 - Event payload field type: bt_ctf_event_class_set_payload_type().
69
70 As of Babeltrace \btversion, those six previous "root" field types
71 \em must be @structft objects.
72
73 If, at any level within a given root field type, you add a @seqft or a
74 @varft, you do not need to specify its associated length
75 or tag field type: the length or tag string is enough for the Babeltrace
76 system to resolve the needed field type depending on where this
77 dynamic field type is located within the whole hierarchy. It is
78 guaranteed that this automatic resolving is performed for all the field
79 types contained in a given
80 \link ctfirstreamclass CTF IR stream class\endlink (and in its
81 children \link ctfireventclass CTF IR event classes\endlink) once you
82 add it to a \link ctfirtraceclass CTF IR trace class\endlink with
83 bt_ctf_trace_add_stream_class(). Once a stream class is the child of
84 a trace class, this automatic resolving is performed for the field
85 types of an event class when you add it with
86 bt_ctf_stream_class_add_event_class(). If the system cannot find a path
87 to a field in the hierarchy for a dynamic field type, the adding
88 function fails.
89
90 The standard CTF field types are:
91
92 <table>
93 <tr>
94 <th>Type ID
95 <th>CTF IR field type
96 <th>CTF IR field which you can create from this field type
97 </tr>
98 <tr>
99 <td>#BT_CTF_TYPE_ID_INTEGER
100 <td>\ref ctfirintfieldtype
101 <td>\ref ctfirintfield
102 </tr>
103 <tr>
104 <td>#BT_CTF_TYPE_ID_FLOAT
105 <td>\ref ctfirfloatfieldtype
106 <td>\ref ctfirfloatfield
107 </tr>
108 <tr>
109 <td>#BT_CTF_TYPE_ID_ENUM
110 <td>\ref ctfirenumfieldtype
111 <td>\ref ctfirenumfield
112 </tr>
113 <tr>
114 <td>#BT_CTF_TYPE_ID_STRING
115 <td>\ref ctfirstringfieldtype
116 <td>\ref ctfirstringfield
117 </tr>
118 <tr>
119 <td>#BT_CTF_TYPE_ID_STRUCT
120 <td>\ref ctfirstructfieldtype
121 <td>\ref ctfirstructfield
122 </tr>
123 <tr>
124 <td>#BT_CTF_TYPE_ID_ARRAY
125 <td>\ref ctfirarrayfieldtype
126 <td>\ref ctfirarrayfield
127 </tr>
128 <tr>
129 <td>#BT_CTF_TYPE_ID_SEQUENCE
130 <td>\ref ctfirseqfieldtype
131 <td>\ref ctfirseqfield
132 </tr>
133 <tr>
134 <td>#BT_CTF_TYPE_ID_VARIANT
135 <td>\ref ctfirvarfieldtype
136 <td>\ref ctfirvarfield
137 </tr>
138 </table>
139
140 Each field type has its own <strong>type ID</strong> (see
141 #bt_ctf_type_id). You get the type ID of a field type object
142 with bt_ctf_field_type_get_type_id().
143
144 You can get a deep copy of a field type with bt_ctf_field_type_copy().
145 This function resets, in the field type copy, the resolved field type
146 of the dynamic field types. The automatic resolving can be done again
147 when you eventually call bt_ctf_event_create(),
148 bt_ctf_stream_class_add_event_class(), or
149 bt_ctf_trace_add_stream_class().
150
151 You \em must always use bt_ctf_field_type_compare() to compare two
152 field types. Since some parts of the Babeltrace system can copy field
153 types behind the scenes, you \em cannot rely on a simple field type
154 pointer comparison.
155
156 As with any Babeltrace object, CTF IR field type objects have
157 <a href="https://en.wikipedia.org/wiki/Reference_counting">reference
158 counts</a>. See \ref refs to learn more about the reference counting
159 management of Babeltrace objects.
160
161 The following functions can \em freeze field type objects:
162
163 - bt_ctf_field_create() freezes its field type parameter.
164 - bt_ctf_stream_class_add_event_class(), if its
165 \link ctfirstreamclass CTF IR stream class\endlink parameter has a
166 \link ctfirtraceclass CTF IR trace class\endlink parent, freezes
167 the root field types of its
168 \link ctfireventclass CTF IR event class\endlink parameter.
169 - bt_ctf_trace_add_stream_class() freezes the root field types of the
170 whole trace class hierarchy (trace class, children stream classes,
171 and their children event classes).
172 - bt_ctf_writer_create_stream() freezes the root field types of the
173 whole CTF writer's trace class hierarchy.
174 - bt_ctf_event_create() freezes the root field types of its event class
175 parameter and of ther parent stream class of this event class.
176
177 You cannot modify a frozen field type object: it is considered
178 immutable, except for \link refs reference counting\endlink.
179
180 @sa ctfirfields
181 @sa \ref ctfirfieldtypesexamples "Examples"
182
183 @file
184 @brief CTF IR field types type and functions.
185 @sa ctfirfieldtypes
186
187 @addtogroup ctfirfieldtypes
188 @{
189 */
190
191 /**
192 @struct bt_ctf_field_type
193 @brief A CTF IR field type.
194 @sa ctfirfieldtypes
195 */
196 struct bt_ctf_field_type;
197 struct bt_ctf_event_class;
198 struct bt_ctf_event;
199 struct bt_ctf_field;
200 struct bt_ctf_field_path;
201 struct bt_ctf_field_type_enumeration_mapping_iterator;
202
203 /** @cond DOCUMENT */
204
205 /*
206 * Babeltrace 1.x enumerations that were also used in CTF writer's API.
207 * They are left here for backward compatibility reasons, but
208 * enum bt_ctf_type_id and enum bt_ctf_string_encoding should be used
209 * in new code. Both new enumerations are compatible with their legacy
210 * counterpart.
211 */
212 enum ctf_type_id {
213 CTF_TYPE_UNKNOWN = 0,
214 CTF_TYPE_INTEGER,
215 CTF_TYPE_FLOAT,
216 CTF_TYPE_ENUM,
217 CTF_TYPE_STRING,
218 CTF_TYPE_STRUCT,
219 CTF_TYPE_UNTAGGED_VARIANT,
220 CTF_TYPE_VARIANT,
221 CTF_TYPE_ARRAY,
222 CTF_TYPE_SEQUENCE,
223 NR_CTF_TYPES,
224 };
225
226 /*
227 * Old enum.
228 */
229 enum ctf_string_encoding {
230 CTF_STRING_NONE = 0,
231 CTF_STRING_UTF8,
232 CTF_STRING_ASCII,
233 CTF_STRING_UNKNOWN,
234 };
235
236 /** @endcond */
237
238 /**
239 @brief CTF scope.
240 */
241 enum bt_ctf_scope {
242 /// Unknown, used for errors.
243 BT_CTF_SCOPE_UNKNOWN = -1,
244
245 /// Trace packet header.
246 BT_CTF_SCOPE_TRACE_PACKET_HEADER = 1,
247
248 /// Stream packet context.
249 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT = 2,
250
251 /// Stream event header.
252 BT_CTF_SCOPE_STREAM_EVENT_HEADER = 3,
253
254 /// Stream event context.
255 BT_CTF_SCOPE_STREAM_EVENT_CONTEXT = 4,
256
257 /// Event context.
258 BT_CTF_SCOPE_EVENT_CONTEXT = 5,
259
260 /// Event payload.
261 BT_CTF_SCOPE_EVENT_PAYLOAD = 6,
262
263 /// @cond DOCUMENT
264 BT_CTF_SCOPE_ENV = 0,
265 BT_CTF_SCOPE_EVENT_FIELDS = 6,
266 /// @endcond
267 };
268
269 /**
270 @name Type information
271 @{
272 */
273
274 /**
275 @brief Type ID of a @ft.
276 */
277 enum bt_ctf_type_id {
278 /// Unknown, used for errors.
279 BT_CTF_TYPE_ID_UNKNOWN = CTF_TYPE_UNKNOWN,
280
281 /// \ref ctfirintfieldtype
282 BT_CTF_TYPE_ID_INTEGER = CTF_TYPE_INTEGER,
283
284 /// \ref ctfirfloatfieldtype
285 BT_CTF_TYPE_ID_FLOAT = CTF_TYPE_FLOAT,
286
287 /// \ref ctfirenumfieldtype
288 BT_CTF_TYPE_ID_ENUM = CTF_TYPE_ENUM,
289
290 /// \ref ctfirstringfieldtype
291 BT_CTF_TYPE_ID_STRING = CTF_TYPE_STRING,
292
293 /// \ref ctfirstructfieldtype
294 BT_CTF_TYPE_ID_STRUCT = CTF_TYPE_STRUCT,
295
296 /// @cond DOCUMENT
297 BT_CTF_TYPE_ID_UNTAGGED_VARIANT = CTF_TYPE_UNTAGGED_VARIANT,
298 /// @endcond
299
300 /// \ref ctfirarrayfieldtype
301 BT_CTF_TYPE_ID_ARRAY = CTF_TYPE_ARRAY,
302
303 /// \ref ctfirseqfieldtype
304 BT_CTF_TYPE_ID_SEQUENCE = CTF_TYPE_SEQUENCE,
305
306 /// \ref ctfirvarfieldtype
307 BT_CTF_TYPE_ID_VARIANT = CTF_TYPE_VARIANT,
308
309 /// Number of enumeration entries.
310 BT_CTF_NR_TYPE_IDS = NR_CTF_TYPES,
311 };
312
313 /**
314 @brief Returns the type ID of the @ft \p field_type.
315
316 @param[in] field_type Field type of which to get the type ID.
317 @returns Type ID of \p field_type,
318 or #BT_CTF_TYPE_ID_UNKNOWN on error.
319
320 @prenotnull{field_type}
321 @postrefcountsame{field_type}
322
323 @sa #bt_ctf_type_id: CTF IR field type ID.
324 @sa bt_ctf_field_type_is_integer(): Returns whether or not a given
325 field type is a @intft.
326 @sa bt_ctf_field_type_is_floating_point(): Returns whether or not a
327 given field type is a @floatft.
328 @sa bt_ctf_field_type_is_enumeration(): Returns whether or not a given
329 field type is a @enumft.
330 @sa bt_ctf_field_type_is_string(): Returns whether or not a given
331 field type is a @stringft.
332 @sa bt_ctf_field_type_is_structure(): Returns whether or not a given
333 field type is a @structft.
334 @sa bt_ctf_field_type_is_array(): Returns whether or not a given
335 field type is a @arrayft.
336 @sa bt_ctf_field_type_is_sequence(): Returns whether or not a given
337 field type is a @seqft.
338 @sa bt_ctf_field_type_is_variant(): Returns whether or not a given
339 field type is a @varft.
340 */
341 extern enum bt_ctf_type_id bt_ctf_field_type_get_type_id(
342 struct bt_ctf_field_type *field_type);
343
344 /**
345 @brief Returns whether or not the @ft \p field_type is a @intft.
346
347 @param[in] field_type Field type to check (can be \c NULL).
348 @returns 1 if \p field_type is an integer field type,
349 or 0 otherwise (including if \p field_type is
350 \c NULL).
351
352 @prenotnull{field_type}
353 @postrefcountsame{field_type}
354
355 @sa bt_ctf_field_type_get_type_id(): Returns the type ID of a given
356 field type.
357 */
358 extern int bt_ctf_field_type_is_integer(struct bt_ctf_field_type *field_type);
359
360 /**
361 @brief Returns whether or not the @ft \p field_type is a @floatft.
362
363 @param[in] field_type Field type to check (can be \c NULL).
364 @returns 1 if \p field_type is a floating point
365 number field type,
366 or 0 otherwise (including if \p field_type is
367 \c NULL).
368
369 @postrefcountsame{field_type}
370
371 @sa bt_ctf_field_type_get_type_id(): Returns the type ID of a given
372 field type.
373 */
374 extern int bt_ctf_field_type_is_floating_point(struct bt_ctf_field_type *field_type);
375
376 /**
377 @brief Returns whether or not the @ft \p field_type is a @enumft.
378
379 @param[in] field_type Field type to check (can be \c NULL).
380 @returns 1 if \p field_type is an enumeration field type,
381 or 0 otherwise (including if \p field_type is
382 \c NULL).
383
384 @postrefcountsame{field_type}
385
386 @sa bt_ctf_field_type_get_type_id(): Returns the type ID of a given
387 field type.
388 */
389 extern int bt_ctf_field_type_is_enumeration(struct bt_ctf_field_type *field_type);
390
391 /**
392 @brief Returns whether or not the @ft \p field_type is a @stringft.
393
394 @param[in] field_type Field type to check (can be \c NULL).
395 @returns 1 if \p field_type is a string field type,
396 or 0 otherwise (including if \p field_type is
397 \c NULL).
398
399 @postrefcountsame{field_type}
400
401 @sa bt_ctf_field_type_get_type_id(): Returns the type ID of a given
402 field type.
403 */
404 extern int bt_ctf_field_type_is_string(struct bt_ctf_field_type *field_type);
405
406 /**
407 @brief Returns whether or not the @ft \p field_type is a @structft.
408
409 @param[in] field_type Field type to check (can be \c NULL).
410 @returns 1 if \p field_type is a structure field type,
411 or 0 otherwise (including if \p field_type is
412 \c NULL).
413
414 @postrefcountsame{field_type}
415
416 @sa bt_ctf_field_type_get_type_id(): Returns the type ID of a given
417 field type.
418 */
419 extern int bt_ctf_field_type_is_structure(struct bt_ctf_field_type *field_type);
420
421 /**
422 @brief Returns whether or not the @ft \p field_type is a @arrayft.
423
424 @param[in] field_type Field type to check (can be \c NULL).
425 @returns 1 if \p field_type is an array field type,
426 or 0 otherwise (including if \p field_type is
427 \c NULL).
428
429 @postrefcountsame{field_type}
430
431 @sa bt_ctf_field_type_get_type_id(): Returns the type ID of a given
432 field type.
433 */
434 extern int bt_ctf_field_type_is_array(struct bt_ctf_field_type *field_type);
435
436 /**
437 @brief Returns whether or not the @ft \p field_type is a @seqft.
438
439 @param[in] field_type Field type to check (can be \c NULL).
440 @returns 1 if \p field_type is a sequence field type,
441 or 0 otherwise (including if \p field_type is
442 \c NULL).
443
444 @postrefcountsame{field_type}
445
446 @sa bt_ctf_field_type_get_type_id(): Returns the type ID of a given
447 field type.
448 */
449 extern int bt_ctf_field_type_is_sequence(struct bt_ctf_field_type *field_type);
450
451 /**
452 @brief Returns whether or not the @ft \p field_type is a @varft.
453
454 @param[in] field_type Field type to check (can be \c NULL).
455 @returns 1 if \p field_type is a variant field type,
456 or 0 otherwise (including if \p field_type is
457 \c NULL).
458
459 @postrefcountsame{field_type}
460
461 @sa bt_ctf_field_type_get_type_id(): Returns the type ID of a given
462 field type.
463 */
464 extern int bt_ctf_field_type_is_variant(struct bt_ctf_field_type *field_type);
465
466 /** @} */
467
468 /**
469 @name Common properties types and functions
470 @{
471 */
472
473 /**
474 @brief <a href="https://en.wikipedia.org/wiki/Endianness">Byte order</a>
475 of a @ft.
476 */
477 enum bt_ctf_byte_order {
478 /// Unknown, used for errors.
479 BT_CTF_BYTE_ORDER_UNKNOWN = -1,
480
481 /*
482 * Note that native, in the context of the CTF specification, is defined
483 * as "the byte order described in the trace" and does not mean that the
484 * host's endianness will be used.
485 */
486 /// Native (default) byte order.
487 BT_CTF_BYTE_ORDER_NATIVE = 0,
488
489 /// Little-endian.
490 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN,
491
492 /// Big-endian.
493 BT_CTF_BYTE_ORDER_BIG_ENDIAN,
494
495 /// Network byte order (big-endian).
496 BT_CTF_BYTE_ORDER_NETWORK,
497 };
498
499 /**
500 @brief String encoding of a @ft.
501 */
502 enum bt_ctf_string_encoding {
503 /// Unknown, used for errors.
504 BT_CTF_STRING_ENCODING_UNKNOWN = CTF_STRING_UNKNOWN,
505
506 /// No encoding.
507 BT_CTF_STRING_ENCODING_NONE = CTF_STRING_NONE,
508
509 /// <a href="https://en.wikipedia.org/wiki/UTF-8">UTF-8</a>.
510 BT_CTF_STRING_ENCODING_UTF8 = CTF_STRING_UTF8,
511
512 /// <a href="https://en.wikipedia.org/wiki/ASCII">ASCII</a>.
513 BT_CTF_STRING_ENCODING_ASCII = CTF_STRING_ASCII,
514 };
515
516 /**
517 @brief Returns the alignment of the @fields described by
518 the @ft \p field_type.
519
520 @param[in] field_type Field type which describes the
521 fields of which to get the alignment.
522 @returns Alignment of the fields described by
523 \p field_type, or a negative value on error.
524
525 @prenotnull{field_type}
526 @postrefcountsame{field_type}
527
528 @sa bt_ctf_field_type_set_alignment(): Sets the alignment
529 of the fields described by a given field type.
530 */
531 extern int bt_ctf_field_type_get_alignment(
532 struct bt_ctf_field_type *field_type);
533
534 /**
535 @brief Sets the alignment of the @fields described by the
536 @ft \p field_type to \p alignment.
537
538 \p alignment \em must be greater than 0 and a power of two.
539
540 @param[in] field_type Field type which describes the fields of
541 which to set the alignment.
542 @param[in] alignment Alignment of the fields described by
543 \p field_type.
544 @returns 0 on success, or a negative value on error.
545
546 @prenotnull{field_type}
547 @prehot{field_type}
548 @pre \p alignment is greater than 0 and a power of two.
549 @postrefcountsame{field_type}
550
551 @sa bt_ctf_field_type_get_alignment(): Returns the alignment of the
552 fields described by a given field type.
553 */
554 extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *field_type,
555 unsigned int alignment);
556
557 /**
558 @brief Returns the byte order of the @fields described by
559 the @ft \p field_type.
560
561 You can only call this function if \p field_type is a @intft, a
562 @floatft, or a @enumft.
563
564 @param[in] field_type Field type which describes the
565 fields of which to get the byte order.
566 @returns Byte order of the fields described by
567 \p field_type, or #BT_CTF_BYTE_ORDER_UNKNOWN on
568 error.
569
570 @prenotnull{field_type}
571 @pre \p field_type is a @intft, a @floatft, or a @enumft.
572 @postrefcountsame{field_type}
573
574 @sa bt_ctf_field_type_set_byte_order(): Sets the byte order
575 of the fields described by a given field type.
576 */
577 extern enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(
578 struct bt_ctf_field_type *field_type);
579
580 /**
581 @brief Sets the byte order of the @fields described by the
582 @ft \p field_type to \p byte_order.
583
584 If \p field_type is a compound field type, this function also
585 recursively sets the byte order of its children to \p byte_order.
586
587 @param[in] field_type Field type which describes the fields of
588 which to set the byte order.
589 @param[in] byte_order Alignment of the fields described by
590 \p field_type.
591 @returns 0 on success, or a negative value on error.
592
593 @prenotnull{field_type}
594 @prehot{field_type}
595 @pre \p byte_order is #BT_CTF_BYTE_ORDER_NATIVE,
596 #BT_CTF_BYTE_ORDER_LITTLE_ENDIAN, #BT_CTF_BYTE_ORDER_BIG_ENDIAN,
597 or #BT_CTF_BYTE_ORDER_NETWORK.
598 @postrefcountsame{field_type}
599
600 @sa bt_ctf_field_type_get_byte_order(): Returns the byte order of the
601 fields described by a given field type.
602 */
603 extern int bt_ctf_field_type_set_byte_order(
604 struct bt_ctf_field_type *field_type,
605 enum bt_ctf_byte_order byte_order);
606
607 /** @} */
608
609 /**
610 @name Utility functions
611 @{
612 */
613
614 /**
615 @brief Returns whether or not the @ft \p field_type_a
616 is equivalent to the field type \p field_type_b.
617
618 You \em must use this function to compare two field types: it is not
619 safe to compare two pointer values directly, because, for internal
620 reasons, some parts of the Babeltrace system can copy user field types
621 and discard the original ones.
622
623 @param[in] field_type_a Field type to compare to \p field_type_b.
624 @param[in] field_type_b Field type to compare to \p field_type_a.
625 @returns 0 if \p field_type_a is equivalent to
626 \p field_type_b, 1 if they are not equivalent,
627 or a negative value on error.
628
629 @prenotnull{field_type_a}
630 @prenotnull{field_type_b}
631 @postrefcountsame{field_type_a}
632 @postrefcountsame{field_type_b}
633 */
634 extern int bt_ctf_field_type_compare(struct bt_ctf_field_type *field_type_a,
635 struct bt_ctf_field_type *field_type_b);
636
637 /**
638 @brief Creates a \em deep copy of the @ft \p field_type.
639
640 You can copy a frozen field type: the resulting copy is
641 <em>not frozen</em>.
642
643 This function resets the tag field type of a copied @varft. The
644 automatic field resolving which some functions of the API perform
645 can set it again when the returned field type is used (learn more
646 in the detailed description of this module).
647
648 @param[in] field_type Field type to copy.
649 @returns Deep copy of \p field_type on success,
650 or \c NULL on error.
651
652 @prenotnull{field_type}
653 @postrefcountsame{field_type}
654 @postsuccessrefcountret1
655 @post <strong>On success</strong>, the returned field type is not frozen.
656 */
657 extern struct bt_ctf_field_type *bt_ctf_field_type_copy(
658 struct bt_ctf_field_type *field_type);
659
660 /** @} */
661
662 /** @} */
663
664 /**
665 @defgroup ctfirintfieldtype CTF IR integer field type
666 @ingroup ctfirfieldtypes
667 @brief CTF IR integer field type.
668
669 @code
670 #include <babeltrace/ctf-ir/field-types.h>
671 @endcode
672
673 A CTF IR <strong><em>integer field type</em></strong> is a field type that
674 you can use to create concrete @intfield objects.
675
676 You can create an integer field type
677 with bt_ctf_field_type_integer_create().
678
679 An integer field type has the following properties:
680
681 <table>
682 <tr>
683 <th>Property
684 <th>Value at creation
685 <th>Getter
686 <th>Setter
687 </tr>
688 <tr>
689 <td>\b Alignment (bits) of the described integer fields
690 <td>1
691 <td>bt_ctf_field_type_get_alignment()
692 <td>bt_ctf_field_type_set_alignment()
693 </tr>
694 <tr>
695 <td><strong>Byte order</strong> of the described integer fields
696 <td>#BT_CTF_BYTE_ORDER_NATIVE
697 <td>bt_ctf_field_type_get_byte_order()
698 <td>bt_ctf_field_type_set_byte_order()
699 </tr>
700 <tr>
701 <td><strong>Storage size</strong> (bits) of the described
702 integer fields
703 <td>Specified at creation
704 <td>bt_ctf_field_type_integer_get_size()
705 <td>None: specified at creation (bt_ctf_field_type_integer_create())
706 </tr>
707 <tr>
708 <td><strong>Signedness</strong> of the described integer fields
709 <td>Unsigned
710 <td>bt_ctf_field_type_integer_get_signed()
711 <td>bt_ctf_field_type_integer_set_signed()
712 </tr>
713 <tr>
714 <td><strong>Preferred display base</strong> of the described
715 integer fields
716 <td>#BT_CTF_INTEGER_BASE_DECIMAL
717 <td>bt_ctf_field_type_integer_get_base()
718 <td>bt_ctf_field_type_integer_set_base()
719 </tr>
720 <tr>
721 <td>\b Encoding of the described integer fields
722 <td>#BT_CTF_STRING_ENCODING_NONE
723 <td>bt_ctf_field_type_integer_get_encoding()
724 <td>bt_ctf_field_type_integer_set_encoding()
725 </tr>
726 <tr>
727 <td><strong>Mapped
728 \link ctfirclockclass CTF IR clock class\endlink</strong>
729 <td>None
730 <td>bt_ctf_field_type_integer_get_mapped_clock_class()
731 <td>bt_ctf_field_type_integer_set_mapped_clock_class()
732 </tr>
733 </table>
734
735 @sa ctfirintfield
736 @sa ctfirfieldtypes
737 @sa \ref ctfirfieldtypesexamples_intfieldtype "Examples"
738
739 @addtogroup ctfirintfieldtype
740 @{
741 */
742
743 /**
744 @brief Preferred display base (radix) of a @intft.
745 */
746 enum bt_ctf_integer_base {
747 /// Unknown, used for errors.
748 BT_CTF_INTEGER_BASE_UNKNOWN = -1,
749
750 /// Binary.
751 BT_CTF_INTEGER_BASE_BINARY = 2,
752
753 /// Octal.
754 BT_CTF_INTEGER_BASE_OCTAL = 8,
755
756 /// Decimal.
757 BT_CTF_INTEGER_BASE_DECIMAL = 10,
758
759 /// Hexadecimal.
760 BT_CTF_INTEGER_BASE_HEXADECIMAL = 16,
761 };
762
763 /**
764 @brief Creates a default @intft with \p size bits as the storage size
765 of the @intfields it describes.
766
767 @param[in] size Storage size (bits) of the described integer fields.
768 @returns Created integer field type, or \c NULL on error.
769
770 @pre \p size is greater than 0 and lesser than or equal to 64.
771 @postsuccessrefcountret1
772 */
773 extern struct bt_ctf_field_type *bt_ctf_field_type_integer_create(
774 unsigned int size);
775
776 /**
777 @brief Returns the storage size, in bits, of the @intfields
778 described by the @intft \p int_field_type.
779
780 @param[in] int_field_type Integer field type which describes the
781 integer fields of which to get the
782 storage size.
783 @returns Storage size (bits) of the integer
784 fields described by \p int_field_type,
785 or a negative value on error.
786
787 @prenotnull{int_field_type}
788 @preisintft{int_field_type}
789 @postrefcountsame{int_field_type}
790 */
791 extern int bt_ctf_field_type_integer_get_size(
792 struct bt_ctf_field_type *int_field_type);
793
794 /**
795 @brief Returns whether or not the @intfields described by the @intft
796 \p int_field_type are signed.
797
798 @param[in] int_field_type Integer field type which describes the
799 integer fields of which to get the
800 signedness.
801 @returns 1 if the integer fields described by
802 \p int_field_type are signed, 0 if they
803 are unsigned, or a negative value on
804 error.
805
806 @prenotnull{int_field_type}
807 @preisintft{int_field_type}
808 @postrefcountsame{int_field_type}
809
810 @sa bt_ctf_field_type_integer_set_signed(): Sets the signedness of the
811 integer fields described by a given integer field type.
812 */
813 extern int bt_ctf_field_type_integer_get_signed(
814 struct bt_ctf_field_type *int_field_type);
815
816 /**
817 @brief Sets whether or not the @intfields described by
818 the @intft \p int_field_type are signed.
819
820 @param[in] int_field_type Integer field type which describes the
821 integer fields of which to set the
822 signedness.
823 @param[in] is_signed Signedness of the integer fields
824 described by \p int_field_type; 0 means
825 \em unsigned, 1 means \em signed.
826 @returns 0 on success, or a negative value on error.
827
828 @prenotnull{int_field_type}
829 @preisintft{int_field_type}
830 @prehot{int_field_type}
831 @pre \p is_signed is 0 or 1.
832 @postrefcountsame{event_class}
833
834 @sa bt_ctf_field_type_integer_get_signed(): Returns the signedness of
835 the integer fields described by a given integer field type.
836 */
837 extern int bt_ctf_field_type_integer_set_signed(
838 struct bt_ctf_field_type *int_field_type, int is_signed);
839
840 /**
841 @brief Returns the preferred display base (radix) of the @intfields
842 described by the @intft \p int_field_type.
843
844 @param[in] int_field_type Integer field type which describes the
845 integer fields of which to get the
846 preferred display base.
847 @returns Preferred display base of the integer
848 fields described by \p int_field_type,
849 or #BT_CTF_INTEGER_BASE_UNKNOWN on
850 error.
851
852 @prenotnull{int_field_type}
853 @preisintft{int_field_type}
854 @postrefcountsame{int_field_type}
855
856 @sa bt_ctf_field_type_integer_set_base(): Sets the preferred display
857 base of the integer fields described by a given integer field
858 type.
859 */
860 extern enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base(
861 struct bt_ctf_field_type *int_field_type);
862
863 /**
864 @brief Sets the preferred display base (radix) of the @intfields
865 described by the @intft \p int_field_type to \p base.
866
867 @param[in] int_field_type Integer field type which describes the
868 integer fields of which to set the
869 preferred display base.
870 @param[in] base Preferred display base of the integer
871 fields described by \p int_field_type.
872 @returns 0 on success, or a negative value on error.
873
874 @prenotnull{int_field_type}
875 @preisintft{int_field_type}
876 @prehot{int_field_type}
877 @pre \p base is #BT_CTF_INTEGER_BASE_BINARY, #BT_CTF_INTEGER_BASE_OCTAL,
878 #BT_CTF_INTEGER_BASE_DECIMAL, or
879 #BT_CTF_INTEGER_BASE_HEXADECIMAL.
880 @postrefcountsame{int_field_type}
881
882 @sa bt_ctf_field_type_integer_get_base(): Returns the preferred display
883 base of the integer fields described by a given
884 integer field type.
885 */
886 extern int bt_ctf_field_type_integer_set_base(
887 struct bt_ctf_field_type *int_field_type,
888 enum bt_ctf_integer_base base);
889
890 /**
891 @brief Returns the encoding of the @intfields described by
892 the @intft \p int_field_type.
893
894 @param[in] int_field_type Integer field type which describes the
895 integer fields of which to get the
896 encoding.
897 @returns Encoding of the integer
898 fields described by \p int_field_type,
899 or #BT_CTF_STRING_ENCODING_UNKNOWN on
900 error.
901
902 @prenotnull{int_field_type}
903 @preisintft{int_field_type}
904 @postrefcountsame{int_field_type}
905
906 @sa bt_ctf_field_type_integer_set_encoding(): Sets the encoding
907 of the integer fields described by a given integer field type.
908 */
909 extern enum bt_ctf_string_encoding bt_ctf_field_type_integer_get_encoding(
910 struct bt_ctf_field_type *int_field_type);
911
912 /**
913 @brief Sets the encoding of the @intfields described by the @intft
914 \p int_field_type to \p encoding.
915
916 You can use this property, in CTF IR, to create "text" @arrayfts or
917 @seqfts. A text array field type is array field type with an unsigned,
918 8-bit integer field type having an encoding as its element field type.
919
920 @param[in] int_field_type Integer field type which describes the
921 integer fields of which to set the
922 encoding.
923 @param[in] encoding Encoding of the integer
924 fields described by \p int_field_type.
925 @returns 0 on success, or a negative value on error.
926
927 @prenotnull{int_field_type}
928 @preisintft{int_field_type}
929 @prehot{int_field_type}
930 @pre \p encoding is #BT_CTF_STRING_ENCODING_NONE,
931 #BT_CTF_STRING_ENCODING_ASCII, or
932 #BT_CTF_STRING_ENCODING_UTF8.
933 @postrefcountsame{int_field_type}
934
935 @sa bt_ctf_field_type_integer_get_encoding(): Returns the encoding of
936 the integer fields described by a given integer field type.
937 */
938 extern int bt_ctf_field_type_integer_set_encoding(
939 struct bt_ctf_field_type *int_field_type,
940 enum bt_ctf_string_encoding encoding);
941
942 /**
943 @brief Returns the \link ctfirclockclass CTF IR clock class\endlink
944 mapped to the @intft \p int_field_type.
945
946 The mapped clock class, if any, indicates the class of the clock which
947 an @intfield described by \p int_field_type should sample or update.
948 This mapped clock class is only indicative.
949
950 @param[in] int_field_type Integer field type of which to get the
951 mapped clock class.
952 @returns Mapped clock class of \p int_field_type,
953 or \c NULL if there's no mapped clock
954 class or on error.
955
956 @prenotnull{int_field_type}
957 @preisintft{int_field_type}
958 @postrefcountsame{int_field_type}
959 @postsuccessrefcountretinc
960
961 @sa bt_ctf_field_type_integer_set_mapped_clock_class(): Sets the mapped
962 clock class of a given integer field type.
963 */
964 extern struct bt_ctf_clock_class *bt_ctf_field_type_integer_get_mapped_clock_class(
965 struct bt_ctf_field_type *int_field_type);
966
967 /**
968 @brief Sets the \link ctfirclockclass CTF IR clock class\endlink mapped
969 to the @intft \p int_field_type to \p clock_class.
970
971 The mapped clock class, if any, indicates the class of the clock which
972 an integer field described by \p int_field_type should sample or update.
973 This mapped clock class is only indicative.
974
975 @param[in] int_field_type Integer field type of which to set the
976 mapped clock class.
977 @param[in] clock_class Mapped clock class of \p int_field_type.
978 @returns 0 on success, or a negative value on error.
979
980 @prenotnull{int_field_type}
981 @prenotnull{clock_class}
982 @preisintft{int_field_type}
983 @prehot{int_field_type}
984 @postrefcountsame{int_field_type}
985 @postsuccessrefcountinc{clock_class}
986
987 @sa bt_ctf_field_type_integer_get_mapped_clock_class(): Returns the mapped
988 clock class of a given integer field type.
989 */
990 extern int bt_ctf_field_type_integer_set_mapped_clock_class(
991 struct bt_ctf_field_type *int_field_type,
992 struct bt_ctf_clock_class *clock_class);
993
994 /** @} */
995
996 /**
997 @defgroup ctfirfloatfieldtype CTF IR floating point number field type
998 @ingroup ctfirfieldtypes
999 @brief CTF IR floating point number field type.
1000
1001 @code
1002 #include <babeltrace/ctf-ir/field-types.h>
1003 @endcode
1004
1005 A CTF IR <strong><em>floating point number field type</em></strong> is
1006 a field type that you can use to create concrete @floatfields.
1007
1008 You can create a floating point number field type
1009 with bt_ctf_field_type_floating_point_create().
1010
1011 A floating point number field type has the following properties:
1012
1013 <table>
1014 <tr>
1015 <th>Property
1016 <th>Value at creation
1017 <th>Getter
1018 <th>Setter
1019 </tr>
1020 <tr>
1021 <td>\b Alignment (bits) of the described floating point
1022 number fields
1023 <td>1
1024 <td>bt_ctf_field_type_get_alignment()
1025 <td>bt_ctf_field_type_set_alignment()
1026 </tr>
1027 <tr>
1028 <td><strong>Byte order</strong> of the described floating point
1029 number fields
1030 <td>#BT_CTF_BYTE_ORDER_NATIVE
1031 <td>bt_ctf_field_type_get_byte_order()
1032 <td>bt_ctf_field_type_set_byte_order()
1033 </tr>
1034 <tr>
1035 <td><strong>Exponent storage size</strong> (bits) of the described
1036 floating point number fields
1037 <td>8
1038 <td>bt_ctf_field_type_floating_point_get_exponent_digits()
1039 <td>bt_ctf_field_type_floating_point_set_exponent_digits()
1040 </tr>
1041 <tr>
1042 <td><strong>Mantissa and sign storage size</strong> (bits) of the
1043 described floating point number fields
1044 <td>24 (23-bit mantissa, 1-bit sign)
1045 <td>bt_ctf_field_type_floating_point_get_mantissa_digits()
1046 <td>bt_ctf_field_type_floating_point_set_mantissa_digits()
1047 </tr>
1048 </table>
1049
1050 @sa ctfirfloatfield
1051 @sa ctfirfieldtypes
1052 @sa \ref ctfirfieldtypesexamples_floatfieldtype "Examples"
1053
1054 @addtogroup ctfirfloatfieldtype
1055 @{
1056 */
1057
1058 /**
1059 @brief Creates a default @floatft.
1060
1061 @returns Created floating point number field type,
1062 or \c NULL on error.
1063
1064 @postsuccessrefcountret1
1065 */
1066 extern struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
1067
1068 /**
1069 @brief Returns the exponent storage size of the @floatfields
1070 described by the @floatft \p float_field_type.
1071
1072 @param[in] float_field_type Floating point number field type which
1073 describes the floating point number
1074 fields of which to get the exponent
1075 storage size.
1076 @returns Exponent storage size of the
1077 floating point number fields
1078 described by \p float_field_type,
1079 or a negative value on error.
1080
1081 @prenotnull{float_field_type}
1082 @preisfloatft{float_field_type}
1083 @postrefcountsame{float_field_type}
1084
1085 @sa bt_ctf_field_type_floating_point_set_exponent_digits(): Sets the
1086 exponent storage size of the floating point number fields
1087 described by a given floating point number field type.
1088 */
1089 extern int bt_ctf_field_type_floating_point_get_exponent_digits(
1090 struct bt_ctf_field_type *float_field_type);
1091
1092 /**
1093 @brief Sets the exponent storage size of the @floatfields described by
1094 the @floatft \p float_field_type to \p exponent_size.
1095
1096 As of Babeltrace \btversion, \p exponent_size can only be 8 or 11.
1097
1098 @param[in] float_field_type Floating point number field type which
1099 describes the floating point number
1100 fields of which to set the exponent
1101 storage size.
1102 @param[in] exponent_size Exponent storage size of the floating
1103 point number fields described by \p
1104 float_field_type.
1105 @returns 0 on success, or a negative value on error.
1106
1107 @prenotnull{float_field_type}
1108 @preisfloatft{float_field_type}
1109 @prehot{float_field_type}
1110 @pre \p exponent_size is 8 or 11.
1111 @postrefcountsame{float_field_type}
1112
1113 @sa bt_ctf_field_type_floating_point_get_exponent_digits(): Returns the
1114 exponent storage size of the floating point number fields
1115 described by a given floating point number field type.
1116 */
1117 extern int bt_ctf_field_type_floating_point_set_exponent_digits(
1118 struct bt_ctf_field_type *float_field_type,
1119 unsigned int exponent_size);
1120
1121 /**
1122 @brief Returns the mantissa and sign storage size of the @floatfields
1123 described by the @floatft \p float_field_type.
1124
1125 On success, the returned value is the sum of the mantissa \em and
1126 sign storage sizes.
1127
1128 @param[in] float_field_type Floating point number field type which
1129 describes the floating point number
1130 fields of which to get the mantissa and
1131 sign storage size.
1132 @returns Mantissa and sign storage size of the
1133 floating point number fields
1134 described by \p float_field_type,
1135 or a negative value on error.
1136
1137 @prenotnull{float_field_type}
1138 @preisfloatft{float_field_type}
1139 @postrefcountsame{float_field_type}
1140
1141 @sa bt_ctf_field_type_floating_point_set_mantissa_digits(): Sets the
1142 mantissa and size storage size of the floating point number
1143 fields described by a given floating point number field type.
1144 */
1145 extern int bt_ctf_field_type_floating_point_get_mantissa_digits(
1146 struct bt_ctf_field_type *float_field_type);
1147
1148 /**
1149 @brief Sets the mantissa and sign storage size of the @floatfields
1150 described by the @floatft \p float_field_type to \p
1151 mantissa_sign_size.
1152
1153 As of Babeltrace \btversion, \p mantissa_sign_size can only be 24 or 53.
1154
1155 @param[in] float_field_type Floating point number field type which
1156 describes the floating point number
1157 fields of which to set the mantissa and
1158 sign storage size.
1159 @param[in] mantissa_sign_size Mantissa and sign storage size of the
1160 floating point number fields described
1161 by \p float_field_type.
1162 @returns 0 on success, or a negative value on error.
1163
1164 @prenotnull{float_field_type}
1165 @preisfloatft{float_field_type}
1166 @prehot{float_field_type}
1167 @pre \p mantissa_sign_size is 24 or 53.
1168 @postrefcountsame{float_field_type}
1169
1170 @sa bt_ctf_field_type_floating_point_get_mantissa_digits(): Returns the
1171 mantissa and sign storage size of the floating point number
1172 fields described by a given floating point number field type.
1173 */
1174 extern int bt_ctf_field_type_floating_point_set_mantissa_digits(
1175 struct bt_ctf_field_type *float_field_type,
1176 unsigned int mantissa_sign_size);
1177
1178 /** @} */
1179
1180 extern int bt_ctf_field_type_enumeration_mapping_iterator_get_name(
1181 struct bt_ctf_field_type_enumeration_mapping_iterator *iter,
1182 const char **mapping_name);
1183
1184 extern int bt_ctf_field_type_enumeration_mapping_iterator_get_signed(
1185 struct bt_ctf_field_type_enumeration_mapping_iterator *iter,
1186 const char **mapping_name, int64_t *lower, int64_t *upper);
1187
1188 extern int bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned(
1189 struct bt_ctf_field_type_enumeration_mapping_iterator *iter,
1190 const char **mapping_name, uint64_t *lower, uint64_t *upper);
1191
1192 extern int bt_ctf_field_type_enumeration_mapping_iterator_next(
1193 struct bt_ctf_field_type_enumeration_mapping_iterator *iter);
1194
1195 /**
1196 @defgroup ctfirenumfieldtype CTF IR enumeration field type
1197 @ingroup ctfirfieldtypes
1198 @brief CTF IR enumeration field type.
1199
1200 @code
1201 #include <babeltrace/ctf-ir/field-types.h>
1202 @endcode
1203
1204 A CTF IR <strong><em>enumeration field type</em></strong> is
1205 a field type that you can use to create concrete @enumfields.
1206
1207 You can create an enumeration field type with
1208 bt_ctf_field_type_enumeration_create(). This function needs a @intft
1209 which represents the storage field type of the created enumeration field
1210 type. In other words, an enumeration field type wraps an integer field
1211 type and adds label-value mappings to it.
1212
1213 An enumeration mapping has:
1214
1215 - A <strong>name</strong>.
1216 - A <strong>range of values</strong> given by a beginning and an ending
1217 value, both included in the range.
1218
1219 You can add a mapping to an enumeration field type with
1220 bt_ctf_field_type_enumeration_add_mapping() or
1221 bt_ctf_field_type_enumeration_add_mapping_unsigned(), depending on the
1222 signedness of the wrapped @intft.
1223
1224 Many mappings can share the same name, and the ranges of a given
1225 enumeration field type are allowed to overlap. For example,
1226 this is a valid set of mappings:
1227
1228 @verbatim
1229 APPLE -> [ 3, 19]
1230 BANANA -> [-15, 1]
1231 CHERRY -> [ 25, 34]
1232 APPLE -> [ 55, 55]
1233 @endverbatim
1234
1235 The following set of mappings is also valid:
1236
1237 @verbatim
1238 APPLE -> [ 3, 19]
1239 BANANA -> [-15, 1]
1240 CHERRY -> [ 25, 34]
1241 APPLE -> [ 30, 55]
1242 @endverbatim
1243
1244 Here, the range of the second \c APPLE mapping overlaps the range of
1245 the \c CHERRY mapping.
1246
1247 @sa ctfirenumfield
1248 @sa ctfirfieldtypes
1249 @sa ctfirenummappingiter
1250
1251 @addtogroup ctfirenumfieldtype
1252 @{
1253 */
1254
1255 /**
1256 @brief Creates a default @enumft wrapping the @intft \p int_field_type.
1257
1258 @param[in] int_field_type Integer field type wrapped by the
1259 created enumeration field type.
1260 @returns Created enumeration field type,
1261 or \c NULL on error.
1262
1263 @prenotnull{int_field_type}
1264 @preisintft{int_field_type}
1265 @postsuccessrefcountinc{int_field_type}
1266 @postsuccessrefcountret1
1267 */
1268 extern struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(
1269 struct bt_ctf_field_type *int_field_type);
1270
1271 /**
1272 @brief Returns the @intft wrapped by the @enumft \p enum_field_type.
1273
1274 @param[in] enum_field_type Enumeration field type of which to get
1275 the wrapped integer field type.
1276 @returns Integer field type wrapped by
1277 \p enum_field_type, or \c NULL on
1278 error.
1279
1280 @prenotnull{enum_field_type}
1281 @preisenumft{enum_field_type}
1282 @postrefcountsame{enum_field_type}
1283 @postsuccessrefcountretinc
1284 */
1285 extern
1286 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type(
1287 struct bt_ctf_field_type *enum_field_type);
1288
1289 /**
1290 @brief Returns the number of mappings contained in the
1291 @enumft \p enum_field_type.
1292
1293 @param[in] enum_field_type Enumeration field type of which to get
1294 the number of contained mappings.
1295 @returns Number of mappings contained in
1296 \p enum_field_type, or a negative
1297 value on error.
1298
1299 @prenotnull{enum_field_type}
1300 @preisenumft{enum_field_type}
1301 @postrefcountsame{enum_field_type}
1302 */
1303 extern int bt_ctf_field_type_enumeration_get_mapping_count(
1304 struct bt_ctf_field_type *enum_field_type);
1305
1306 /**
1307 @brief Returns the signed mapping of the @enumft
1308 \p enum_field_type at index \p index.
1309
1310 The @intft wrapped by \p enum_field_type, as returned by
1311 bt_ctf_field_type_enumeration_get_container_type(), must be \b signed
1312 to use this function.
1313
1314 On success, \p enum_field_type remains the sole owner of \p *name.
1315
1316 @param[in] enum_field_type Enumeration field type of which to get
1317 the mapping at index \p index.
1318 @param[in] index Index of the mapping to get from
1319 \p enum_field_type.
1320 @param[out] name Returned name of the mapping at index
1321 \p index.
1322 @param[out] range_begin Returned beginning of the range
1323 (included) of the mapping at index \p
1324 index.
1325 @param[out] range_end Returned end of the range (included) of
1326 the mapping at index \p index.
1327 @returns 0 on success, or a negative value on error.
1328
1329 @prenotnull{enum_field_type}
1330 @prenotnull{name}
1331 @prenotnull{range_begin}
1332 @prenotnull{range_end}
1333 @preisenumft{enum_field_type}
1334 @pre The wrapped @intft of \p enum_field_type is signed.
1335 @pre \p index is lesser than the number of mappings contained in the
1336 enumeration field type \p enum_field_type (see
1337 bt_ctf_field_type_enumeration_get_mapping_count()).
1338 @postrefcountsame{enum_field_type}
1339
1340 @sa bt_ctf_field_type_enumeration_get_mapping_signed(): Returns the
1341 signed mapping contained by a given enumeration field type
1342 at a given index.
1343 */
1344 extern int bt_ctf_field_type_enumeration_get_mapping_signed(
1345 struct bt_ctf_field_type *enum_field_type, int index,
1346 const char **name, int64_t *range_begin, int64_t *range_end);
1347
1348 /**
1349 @brief Returns the unsigned mapping of the @enumft
1350 \p enum_field_type at index \p index.
1351
1352 The @intft wrapped by \p enum_field_type, as returned by
1353 bt_ctf_field_type_enumeration_get_container_type(), must be
1354 \b unsigned to use this function.
1355
1356 On success, \p enum_field_type remains the sole owner of \p *name.
1357
1358 @param[in] enum_field_type Enumeration field type of which to get
1359 the mapping at index \p index.
1360 @param[in] index Index of the mapping to get from
1361 \p enum_field_type.
1362 @param[out] name Returned name of the mapping at index
1363 \p index.
1364 @param[out] range_begin Returned beginning of the range
1365 (included) of the mapping at index \p
1366 index.
1367 @param[out] range_end Returned end of the range (included) of
1368 the mapping at index \p index.
1369 @returns 0 on success, or a negative value on error.
1370
1371 @prenotnull{enum_field_type}
1372 @prenotnull{name}
1373 @prenotnull{range_begin}
1374 @prenotnull{range_end}
1375 @preisenumft{enum_field_type}
1376 @pre The wrapped @intft of \p enum_field_type is unsigned.
1377 @pre \p index is lesser than the number of mappings contained in the
1378 enumeration field type \p enum_field_type (see
1379 bt_ctf_field_type_enumeration_get_mapping_count()).
1380 @postrefcountsame{enum_field_type}
1381
1382 @sa bt_ctf_field_type_enumeration_get_mapping_unsigned(): Returns the
1383 unsigned mapping contained by a given enumeration field type
1384 at a given index.
1385 */
1386 extern int bt_ctf_field_type_enumeration_get_mapping_unsigned(
1387 struct bt_ctf_field_type *enum_field_type, int index,
1388 const char **name, uint64_t *range_begin,
1389 uint64_t *range_end);
1390
1391 /**
1392 @brief Returns a @enumiter on the mappings of the @enumft
1393 \p enum_field_type that match \p name.
1394
1395 @param[in] enum_field_type Enumeration field type of which to get
1396 the mapping at index \p index.
1397 @param[in] name Name of the mappings to find.
1398 @returns @enumiter that
1399 match \p name, or \c NULL on error.
1400
1401 @prenotnull{enum_field_type}
1402 @prenotnull{name}
1403 @preisenumft{enum_field_type}
1404 @postrefcountsame{enum_field_type}
1405 @postsuccessrefcountret1
1406 */
1407 extern struct bt_ctf_field_type_enumeration_mapping_iterator *
1408 bt_ctf_field_type_enumeration_find_mappings_by_name(
1409 struct bt_ctf_field_type *enum_field_type,
1410 const char *name);
1411
1412 /**
1413 @brief Returns the mappings of the @enumft
1414 \p enum_field_type that match \p value.
1415
1416 @param[in] enum_field_type Enumeration field type of which to get
1417 the mapping at index \p index.
1418 @param[in] value Signed value of the mappings to find.
1419 @returns Iterator on enumeration mappings that
1420 match \p value, or \c NULL on error.
1421
1422 @prenotnull{enum_field_type}
1423 @prenotnull{name}
1424 @preisenumft{enum_field_type}
1425 @postrefcountsame{enum_field_type}
1426 @postsuccessrefcountret1
1427 */
1428 extern struct bt_ctf_field_type_enumeration_mapping_iterator *
1429 bt_ctf_field_type_enumeration_find_mappings_by_signed_value(
1430 struct bt_ctf_field_type *enum_field_type,
1431 int64_t value);
1432
1433 /**
1434 @brief Returns the mappings of the @enumft
1435 \p enum_field_type that match \p value.
1436
1437 @param[in] enum_field_type Enumeration field type of which to get
1438 the mapping at index \p index.
1439 @param[in] value Unsigned value of the mappings to find.
1440 @returns Iterator on enumeration mappings that
1441 match \p value, or \c NULL on error.
1442
1443 @prenotnull{enum_field_type}
1444 @prenotnull{name}
1445 @preisenumft{enum_field_type}
1446 @postrefcountsame{enum_field_type}
1447 @postsuccessrefcountret1
1448 */
1449 extern struct bt_ctf_field_type_enumeration_mapping_iterator *
1450 bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
1451 struct bt_ctf_field_type *enum_field_type,
1452 uint64_t value);
1453
1454 /**
1455 @brief Adds a mapping to the @enumft \p enum_field_type which maps the
1456 name \p name to the signed range \p range_begin (included) to
1457 \p range_end (included).
1458
1459 Make \p range_begin and \p range_end the same value to add a mapping
1460 to a single value.
1461
1462 The @intft wrapped by \p enum_field_type, as returned by
1463 bt_ctf_field_type_enumeration_get_container_type(), must be
1464 \b signed to use this function.
1465
1466 A mapping in \p enum_field_type can exist with the name \p name.
1467
1468 @param[in] enum_field_type Enumeration field type to which to add
1469 a mapping.
1470 @param[in] name Name of the mapping to add (copied
1471 on success).
1472 @param[in] range_begin Beginning of the range of the mapping
1473 (included).
1474 @param[in] range_end End of the range of the mapping
1475 (included).
1476 @returns 0 on success, or a negative value on error.
1477
1478 @prenotnull{enum_field_type}
1479 @prenotnull{name}
1480 @preisenumft{enum_field_type}
1481 @pre The wrapped @intft of \p enum_field_type is signed.
1482 @pre \p range_end is greater than or equal to \p range_begin.
1483 @postrefcountsame{enum_field_type}
1484
1485 @sa bt_ctf_field_type_enumeration_add_mapping_unsigned(): Adds an
1486 unsigned mapping to a given enumeration field type.
1487 */
1488 extern int bt_ctf_field_type_enumeration_add_mapping(
1489 struct bt_ctf_field_type *enum_field_type, const char *name,
1490 int64_t range_begin, int64_t range_end);
1491
1492 /**
1493 @brief Adds a mapping to the @enumft \p enum_field_type which maps
1494 the name \p name to the unsigned
1495 range \p range_begin (included) to \p range_end (included).
1496
1497 Make \p range_begin and \p range_end the same value to add a mapping
1498 to a single value.
1499
1500 The @intft wrapped by \p enum_field_type, as returned by
1501 bt_ctf_field_type_enumeration_get_container_type(), must be
1502 \b unsigned to use this function.
1503
1504 A mapping in \p enum_field_type can exist with the name \p name.
1505
1506 @param[in] enum_field_type Enumeration field type to which to add
1507 a mapping.
1508 @param[in] name Name of the mapping to add (copied
1509 on success).
1510 @param[in] range_begin Beginning of the range of the mapping
1511 (included).
1512 @param[in] range_end End of the range of the mapping
1513 (included).
1514 @returns 0 on success, or a negative value on error.
1515
1516 @prenotnull{enum_field_type}
1517 @prenotnull{name}
1518 @preisenumft{enum_field_type}
1519 @pre The wrapped @intft of \p enum_field_type is unsigned.
1520 @pre \p range_end is greater than or equal to \p range_begin.
1521 @postrefcountsame{enum_field_type}
1522
1523 @sa bt_ctf_field_type_enumeration_add_mapping(): Adds a signed
1524 mapping to a given enumeration field type.
1525 */
1526 extern int bt_ctf_field_type_enumeration_add_mapping_unsigned(
1527 struct bt_ctf_field_type *enum_field_type, const char *name,
1528 uint64_t range_begin, uint64_t range_end);
1529
1530 /** @} */
1531
1532 /**
1533 @defgroup ctfirstringfieldtype CTF IR string field type
1534 @ingroup ctfirfieldtypes
1535 @brief CTF IR string field type.
1536
1537 @code
1538 #include <babeltrace/ctf-ir/field-types.h>
1539 @endcode
1540
1541 A CTF IR <strong><em>string field type</em></strong> is a field type that
1542 you can use to create concrete @stringfields.
1543
1544 You can create a string field type
1545 with bt_ctf_field_type_string_create().
1546
1547 A string field type has only one property: the \b encoding of its
1548 described @stringfields. By default, the encoding of the string fields
1549 described by a string field type is #BT_CTF_STRING_ENCODING_UTF8. You
1550 can set the encoding of the string fields described by a string field
1551 type with bt_ctf_field_type_string_set_encoding().
1552
1553 @sa ctfirstringfield
1554 @sa ctfirfieldtypes
1555
1556 @addtogroup ctfirstringfieldtype
1557 @{
1558 */
1559
1560 /**
1561 @brief Creates a default @stringft.
1562
1563 @returns Created string field type, or \c NULL on error.
1564
1565 @postsuccessrefcountret1
1566 */
1567 extern struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
1568
1569 /**
1570 @brief Returns the encoding of the @stringfields described by
1571 the @stringft \p string_field_type.
1572
1573 @param[in] string_field_type String field type which describes the
1574 string fields of which to get the
1575 encoding.
1576 @returns Encoding of the string
1577 fields described by \p string_field_type,
1578 or #BT_CTF_STRING_ENCODING_UNKNOWN on
1579 error.
1580
1581 @prenotnull{string_field_type}
1582 @preisstringft{string_field_type}
1583 @postrefcountsame{string_field_type}
1584
1585 @sa bt_ctf_field_type_string_set_encoding(): Sets the encoding
1586 of the string fields described by a given string field type.
1587 */
1588 extern enum bt_ctf_string_encoding bt_ctf_field_type_string_get_encoding(
1589 struct bt_ctf_field_type *string_field_type);
1590
1591 /**
1592 @brief Sets the encoding of the @stringfields described by the
1593 @stringft \p string_field_type to \p encoding.
1594
1595 @param[in] string_field_type String field type which describes the
1596 string fields of which to set the
1597 encoding.
1598 @param[in] encoding Encoding of the string fields described
1599 by \p string_field_type.
1600 @returns 0 on success, or a negative value on error.
1601
1602 @prenotnull{string_field_type}
1603 @preisstringft{string_field_type}
1604 @prehot{string_field_type}
1605 @pre \p encoding is #BT_CTF_STRING_ENCODING_ASCII or
1606 #BT_CTF_STRING_ENCODING_UTF8.
1607 @postrefcountsame{string_field_type}
1608
1609 @sa bt_ctf_field_type_string_get_encoding(): Returns the encoding of
1610 the string fields described by a given string field type.
1611 */
1612 extern int bt_ctf_field_type_string_set_encoding(
1613 struct bt_ctf_field_type *string_field_type,
1614 enum bt_ctf_string_encoding encoding);
1615
1616 /** @} */
1617
1618 /**
1619 @defgroup ctfirstructfieldtype CTF IR structure field type
1620 @ingroup ctfirfieldtypes
1621 @brief CTF IR structure field type.
1622
1623 @code
1624 #include <babeltrace/ctf-ir/field-types.h>
1625 @endcode
1626
1627 A CTF IR <strong><em>structure field type</em></strong> is
1628 a field type that you can use to create concrete @structfields.
1629
1630 You can create a structure field type
1631 with bt_ctf_field_type_structure_create(). This function creates
1632 an empty structure field type, with no fields.
1633
1634 You can add a field to a structure field type with
1635 bt_ctf_field_type_structure_add_field(). Two fields in a structure
1636 field type cannot have the same name.
1637
1638 You can set the \em minimum alignment of the structure fields described
1639 by a structure field type with the common
1640 bt_ctf_field_type_set_alignment() function. The \em effective alignment
1641 of the structure fields described by a structure field type, as per
1642 <a href="http://diamon.org/ctf/">CTF</a>, is the \em maximum value amongst
1643 the effective alignments of all its fields. Note that the effective
1644 alignment of @varfields is always 1.
1645
1646 You can set the byte order of <em>all the contained fields</em>,
1647 recursively, of a structure field type with the common
1648 bt_ctf_field_type_set_byte_order() function.
1649
1650 @sa ctfirstructfield
1651 @sa ctfirfieldtypes
1652
1653 @addtogroup ctfirstructfieldtype
1654 @{
1655 */
1656
1657 /**
1658 @brief Creates a default, empty @structft.
1659
1660 @returns Created structure field type,
1661 or \c NULL on error.
1662
1663 @postsuccessrefcountret1
1664 */
1665 extern struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1666
1667 /**
1668 @brief Returns the number of fields contained in the
1669 @structft \p struct_field_type.
1670
1671 @param[in] struct_field_type Structure field type of which to get
1672 the number of contained fields.
1673 @returns Number of fields contained in
1674 \p struct_field_type, or a negative
1675 value on error.
1676
1677 @prenotnull{struct_field_type}
1678 @preisstructft{struct_field_type}
1679 @postrefcountsame{struct_field_type}
1680 */
1681 extern int bt_ctf_field_type_structure_get_field_count(
1682 struct bt_ctf_field_type *struct_field_type);
1683
1684 /**
1685 @brief Returns the field of the @structft \p struct_field_type
1686 at index \p index.
1687
1688 On success, the field's type is placed in \p *field_type if
1689 \p field_type is not \c NULL. The field's name is placed in
1690 \p *field_name if \p field_name is not \c NULL.
1691 \p struct_field_type remains the sole owner of \p *field_name.
1692
1693 @param[in] struct_field_type Structure field type of which to get
1694 the field at index \p index.
1695 @param[out] field_name Returned name of the field at index
1696 \p index (can be \c NULL).
1697 @param[out] field_type Returned field type of the field
1698 at index \p index (can be \c NULL).
1699 ­@param[in] index Index of the field to get from
1700 \p struct_field_type.
1701 @returns 0 on success, or a negative value on error.
1702
1703 @prenotnull{struct_field_type}
1704 @preisstructft{struct_field_type}
1705 @pre \p index is lesser than the number of fields contained in the
1706 structure field type \p struct_field_type (see
1707 bt_ctf_field_type_structure_get_field_count()).
1708 @postrefcountsame{struct_field_type}
1709 @post <strong>On success</strong>, the returned field's type is placed
1710 in \p *field_type and its reference count is incremented.
1711
1712 @sa bt_ctf_field_type_structure_get_field_type_by_name(): Finds a
1713 structure field type's field by name.
1714 */
1715 extern int bt_ctf_field_type_structure_get_field(
1716 struct bt_ctf_field_type *struct_field_type,
1717 const char **field_name, struct bt_ctf_field_type **field_type,
1718 int index);
1719
1720 /**
1721 @brief Returns the type of the field named \p field_name found in
1722 the @structft \p struct_field_type.
1723
1724 @param[in] struct_field_type Structure field type of which to get
1725 a field's type.
1726 @param[in] field_name Name of the field to find.
1727 @returns Type of the field named \p field_name in
1728 \p struct_field_type, or
1729 \c NULL on error.
1730
1731 @prenotnull{struct_field_type}
1732 @prenotnull{field_name}
1733 @preisstructft{struct_field_type}
1734 @postrefcountsame{struct_field_type}
1735 @postsuccessrefcountretinc
1736
1737 @sa bt_ctf_field_type_structure_get_field(): Finds a
1738 structure field type's field by index.
1739 */
1740 extern
1741 struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name(
1742 struct bt_ctf_field_type *struct_field_type,
1743 const char *field_name);
1744
1745 /**
1746 @brief Adds a field named \p field_name with the @ft
1747 \p field_type to the @structft \p struct_field_type.
1748
1749 On success, \p field_type becomes the child of \p struct_field_type.
1750
1751 This function adds the new field after the current last field of
1752 \p struct_field_type (append mode).
1753
1754 You \em cannot add a field named \p field_name if there's already a
1755 field named \p field_name in \p struct_field_type.
1756
1757 @param[in] struct_field_type Structure field type to which to add
1758 a new field.
1759 @param[in] field_type Field type of the field to add to
1760 \p struct_field_type.
1761 @param[in] field_name Name of the field to add to
1762 \p struct_field_type
1763 (copied on success).
1764 @returns 0 on success, or a negative value on error.
1765
1766 @prenotnull{struct_field_type}
1767 @prenotnull{field_type}
1768 @prenotnull{field_name}
1769 @preisstructft{struct_field_type}
1770 @pre \p field_type is not and does not contain \p struct_field_type,
1771 recursively, as a field's type.
1772 @prehot{struct_field_type}
1773 @postrefcountsame{struct_field_type}
1774 @postsuccessrefcountinc{field_type}
1775 */
1776 extern int bt_ctf_field_type_structure_add_field(
1777 struct bt_ctf_field_type *struct_field_type,
1778 struct bt_ctf_field_type *field_type,
1779 const char *field_name);
1780
1781 /** @} */
1782
1783 /**
1784 @defgroup ctfirarrayfieldtype CTF IR array field type
1785 @ingroup ctfirfieldtypes
1786 @brief CTF IR array field type.
1787
1788 @code
1789 #include <babeltrace/ctf-ir/field-types.h>
1790 @endcode
1791
1792 A CTF IR <strong><em>array field type</em></strong> is a field type that
1793 you can use to create concrete @arrayfields.
1794
1795 You can create an array field type
1796 with bt_ctf_field_type_array_create(). This function needs
1797 the @ft of the fields contained by the array fields described by the
1798 array field type to create.
1799
1800 @sa ctfirarrayfield
1801 @sa ctfirfieldtypes
1802
1803 @addtogroup ctfirarrayfieldtype
1804 @{
1805 */
1806
1807 /**
1808 @brief Creates a default @arrayft with
1809 \p element_field_type as the field type of the fields contained
1810 in its described @arrayfields of length \p length.
1811
1812 @param[in] element_field_type Field type of the fields contained in
1813 the array fields described by the
1814 created array field type.
1815 @param[in] length Length of the array fields described by
1816 the created array field type.
1817 @returns Created array field type, or
1818 \c NULL on error.
1819
1820 @prenotnull{element_field_type}
1821 @postsuccessrefcountinc{element_field_type}
1822 @postsuccessrefcountret1
1823 */
1824 extern struct bt_ctf_field_type *bt_ctf_field_type_array_create(
1825 struct bt_ctf_field_type *element_field_type,
1826 unsigned int length);
1827
1828 /**
1829 @brief Returns the @ft of the @fields contained in
1830 the @arrayfields described by the @arrayft \p array_field_type.
1831
1832 @param[in] array_field_type Array field type of which to get
1833 the type of the fields contained in its
1834 described array fields.
1835 @returns Type of the fields contained in the
1836 array fields described by
1837 \p array_field_type, or \c NULL
1838 on error.
1839
1840 @prenotnull{array_field_type}
1841 @preisarrayft{array_field_type}
1842 @postrefcountsame{array_field_type}
1843 @postsuccessrefcountretinc
1844 */
1845 extern struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type(
1846 struct bt_ctf_field_type *array_field_type);
1847
1848 /**
1849 @brief Returns the number of @fields contained in the
1850 @arrayfields described by the @arrayft \p array_field_type.
1851
1852 @param[in] array_field_type Array field type of which to get
1853 the number of fields contained in its
1854 described array fields.
1855 @returns Number of fields contained in the
1856 array fields described by
1857 \p array_field_type, or a negative value
1858 on error.
1859
1860 @prenotnull{array_field_type}
1861 @preisarrayft{array_field_type}
1862 @postrefcountsame{array_field_type}
1863 */
1864 extern int64_t bt_ctf_field_type_array_get_length(
1865 struct bt_ctf_field_type *array_field_type);
1866
1867 /** @} */
1868
1869 /**
1870 @defgroup ctfirseqfieldtype CTF IR sequence field type
1871 @ingroup ctfirfieldtypes
1872 @brief CTF IR sequence field type.
1873
1874 @code
1875 #include <babeltrace/ctf-ir/field-types.h>
1876 @endcode
1877
1878 A CTF IR <strong><em>sequence field type</em></strong> is
1879 a field type that you can use to create concrete @seqfields.
1880
1881 You can create a sequence field type with
1882 bt_ctf_field_type_sequence_create(). This function needs the @ft
1883 of the fields contained by the sequence fields described by the created
1884 sequence field type. This function also needs the length name of the
1885 sequence field type to create. The length name is used to automatically
1886 resolve the length's field type. See \ref ctfirfieldtypes to learn more
1887 about the automatic resolving.
1888
1889 @sa ctfirseqfield
1890 @sa ctfirfieldtypes
1891
1892 @addtogroup ctfirseqfieldtype
1893 @{
1894 */
1895
1896 /**
1897 @brief Creates a default @seqft with \p element_field_type as the
1898 @ft of the @fields contained in its described @seqfields
1899 with the length name \p length_name.
1900
1901 \p length_name can be an absolute or relative reference. See
1902 <a href="http://diamon.org/ctf/">CTF</a> for more details.
1903
1904 @param[in] element_field_type Field type of the fields contained in
1905 the sequence fields described by the
1906 created sequence field type.
1907 @param[in] length_name Length name (copied on success).
1908 @returns Created array field type, or
1909 \c NULL on error.
1910
1911 @prenotnull{element_field_type}
1912 @prenotnull{length_name}
1913 @postsuccessrefcountinc{element_field_type}
1914 @postsuccessrefcountret1
1915 */
1916 extern struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(
1917 struct bt_ctf_field_type *element_field_type,
1918 const char *length_name);
1919
1920 /**
1921 @brief Returns the @ft of the @fields contained in the @seqft
1922 described by the @seqft \p sequence_field_type.
1923
1924 @param[in] sequence_field_type Sequence field type of which to get
1925 the type of the fields contained in its
1926 described sequence fields.
1927 @returns Type of the fields contained in the
1928 sequence fields described by
1929 \p sequence_field_type, or \c NULL
1930 on error.
1931
1932 @prenotnull{sequence_field_type}
1933 @preisseqft{sequence_field_type}
1934 @postrefcountsame{sequence_field_type}
1935 @postsuccessrefcountretinc
1936 */
1937 extern struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type(
1938 struct bt_ctf_field_type *sequence_field_type);
1939
1940 /**
1941 @brief Returns the length name of the @seqft \p sequence_field_type.
1942
1943 On success, \p sequence_field_type remains the sole owner of
1944 the returned string.
1945
1946 @param[in] sequence_field_type Sequence field type of which to get the
1947 length name.
1948 @returns Length name of \p sequence_field_type,
1949 or \c NULL on error.
1950
1951 @prenotnull{sequence_field_type}
1952 @preisseqft{sequence_field_type}
1953
1954 @sa bt_ctf_field_type_sequence_get_length_field_path(): Returns the
1955 length's CTF IR field path of a given sequence field type.
1956 */
1957 extern const char *bt_ctf_field_type_sequence_get_length_field_name(
1958 struct bt_ctf_field_type *sequence_field_type);
1959
1960 /**
1961 @brief Returns the length's CTF IR field path of the @seqft
1962 \p sequence_field_type.
1963
1964 The length's field path of a sequence field type is set when automatic
1965 resolving is performed (see \ref ctfirfieldtypes).
1966
1967 @param[in] sequence_field_type Sequence field type of which to get the
1968 length's field path.
1969 @returns Length's field path of
1970 \p sequence_field_type, or
1971 \c NULL if the length's field path is
1972 not set yet is not set or on error.
1973
1974 @prenotnull{sequence_field_type}
1975 @preisseqft{sequence_field_type}
1976 @postsuccessrefcountretinc
1977
1978 @sa bt_ctf_field_type_sequence_get_length_field_name(): Returns the
1979 length's name of a given sequence field type.
1980 */
1981 extern struct bt_ctf_field_path *bt_ctf_field_type_sequence_get_length_field_path(
1982 struct bt_ctf_field_type *sequence_field_type);
1983
1984 /** @} */
1985
1986 /**
1987 @defgroup ctfirvarfieldtype CTF IR variant field type
1988 @ingroup ctfirfieldtypes
1989 @brief CTF IR variant field type.
1990
1991 @code
1992 #include <babeltrace/ctf-ir/field-types.h>
1993 @endcode
1994
1995 A CTF IR <strong><em>variant field type</em></strong> is
1996 a field type that you can use to create concrete @varfields.
1997
1998 You can create a variant field type with
1999 bt_ctf_field_type_variant_create(). This function expects you to pass
2000 both the tag's @enumft and the tag name of the variant field type to
2001 create. The tag's field type is optional, as the Babeltrace system can
2002 automatically resolve it using the tag name. You can leave the tag name
2003 to \c NULL initially, and set it later with
2004 bt_ctf_field_type_variant_set_tag_name(). The tag name must be set when
2005 the variant field type is frozen. See \ref ctfirfieldtypes to learn more
2006 about the automatic resolving and the conditions under which a field
2007 type can be frozen.
2008
2009 You can add a field to a variant field type with
2010 bt_ctf_field_type_variant_add_field(). All the field names of a
2011 variant field type \em must exist as mapping names in its tag's @enumft.
2012
2013 The effective alignment of the @varfields described by a
2014 variant field type is always 1, but the individual fields of a
2015 @varfield can have custom alignments.
2016
2017 You can set the byte order of <em>all the contained fields</em>,
2018 recursively, of a variant field type with the common
2019 bt_ctf_field_type_set_byte_order() function.
2020
2021 @sa ctfirvarfield
2022 @sa ctfirfieldtypes
2023
2024 @addtogroup ctfirvarfieldtype
2025 @{
2026 */
2027
2028 /**
2029 @brief Creates a default, empty @varft with the tag's @enumft
2030 \p tag_field_type and the tag name \p tag_name.
2031
2032 \p tag_field_type can be \c NULL; the tag's field type can be
2033 automatically resolved from the variant field type's tag name (see
2034 \ref ctfirfieldtypes). If \p tag_name is \c NULL, it \em must be set
2035 with bt_ctf_field_type_variant_set_tag_name() \em before the variant
2036 field type is frozen.
2037
2038 \p tag_name can be an absolute or relative reference. See
2039 <a href="http://diamon.org/ctf/">CTF</a> for more details.
2040
2041 @param[in] tag_field_type Tag's enumeration field type
2042 (can be \c NULL).
2043 @param[in] tag_name Tag name (copied on success,
2044 can be \c NULL).
2045 @returns Created variant field type, or
2046 \c NULL on error.
2047
2048 @pre \p tag_field_type is an enumeration field type or \c NULL.
2049 @post <strong>On success, if \p tag_field_type is not \c NULL</strong>,
2050 its reference count is incremented.
2051 @postsuccessrefcountret1
2052 */
2053 extern struct bt_ctf_field_type *bt_ctf_field_type_variant_create(
2054 struct bt_ctf_field_type *tag_field_type,
2055 const char *tag_name);
2056
2057 /**
2058 @brief Returns the tag's @enumft of the @varft \p variant_field_type.
2059
2060 @param[in] variant_field_type Variant field type of which to get
2061 the tag's enumeration field type.
2062 @returns Tag's enumeration field type of
2063 \p variant_field_type, or \c NULL if the
2064 tag's field type is not set or on
2065 error.
2066
2067 @prenotnull{variant_field_type}
2068 @preisvarft{variant_field_type}
2069 @postrefcountsame{variant_field_type}
2070 @postsuccessrefcountretinc
2071 */
2072 extern struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type(
2073 struct bt_ctf_field_type *variant_field_type);
2074
2075 /**
2076 @brief Returns the tag name of the @varft \p variant_field_type.
2077
2078 On success, \p variant_field_type remains the sole owner of
2079 the returned string.
2080
2081 @param[in] variant_field_type Variant field type of which to get the
2082 tag name.
2083 @returns Tag name of \p variant_field_type, or
2084 \c NULL if the tag name is not set or
2085 on error.
2086
2087 @prenotnull{variant_field_type}
2088 @preisvarft{variant_field_type}
2089
2090 @sa bt_ctf_field_type_variant_set_tag_name(): Sets the tag name of
2091 a given variant field type.
2092 @sa bt_ctf_field_type_variant_get_tag_field_path(): Returns the tag's
2093 CTF IR field path of a given variant field type.
2094 */
2095 extern const char *bt_ctf_field_type_variant_get_tag_name(
2096 struct bt_ctf_field_type *variant_field_type);
2097
2098 /**
2099 @brief Sets the tag name of the @varft \p variant_field_type.
2100
2101 \p tag_name can be an absolute or relative reference. See
2102 <a href="http://diamon.org/ctf/">CTF</a> for more details.
2103
2104 @param[in] variant_field_type Variant field type of which to set
2105 the tag name.
2106 @param[in] tag_name Tag name of \p variant_field_type
2107 (copied on success).
2108 @returns 0 on success, or a negative value on error.
2109
2110 @prenotnull{variant_field_type}
2111 @prenotnull{name}
2112 @prehot{variant_field_type}
2113 @postrefcountsame{variant_field_type}
2114
2115 @sa bt_ctf_field_type_variant_get_tag_name(): Returns the tag name of
2116 a given variant field type.
2117 */
2118 extern int bt_ctf_field_type_variant_set_tag_name(
2119 struct bt_ctf_field_type *variant_field_type,
2120 const char *tag_name);
2121
2122 /**
2123 @brief Returns the tag's CTF IR field path of the @varft
2124 \p variant_field_type.
2125
2126 The tag's field path of a variant field type is set when automatic
2127 resolving is performed (see \ref ctfirfieldtypes).
2128
2129 @param[in] variant_field_type Variant field type of which to get the
2130 tag's field path.
2131 @returns Tag's field path of
2132 \p variant_field_type, or
2133 \c NULL if the tag's field path is not
2134 set yet is not set or on error.
2135
2136 @prenotnull{variant_field_type}
2137 @preisvarft{variant_field_type}
2138 @postsuccessrefcountretinc
2139
2140 @sa bt_ctf_field_type_variant_get_tag_name(): Returns the tag's
2141 name of a given variant field type.
2142 */
2143 extern struct bt_ctf_field_path *bt_ctf_field_type_variant_get_tag_field_path(
2144 struct bt_ctf_field_type *variant_field_type);
2145
2146 /**
2147 @brief Returns the number of fields (choices) contained in the @varft
2148 \p variant_field_type.
2149
2150 @param[in] variant_field_type Variant field type of which to get
2151 the number of contained fields.
2152 @returns Number of fields contained in
2153 \p variant_field_type, or a negative
2154 value on error.
2155
2156 @prenotnull{variant_field_type}
2157 @preisvarft{variant_field_type}
2158 @postrefcountsame{variant_field_type}
2159 */
2160 extern int bt_ctf_field_type_variant_get_field_count(
2161 struct bt_ctf_field_type *variant_field_type);
2162
2163 /**
2164 @brief Returns the field (choice) of the @varft \p variant_field_type
2165 at index \p index.
2166
2167 On success, the field's type is placed in \p *field_type if
2168 \p field_type is not \c NULL. The field's name is placed in
2169 \p *field_name if \p field_name is not \c NULL.
2170 \p variant_field_type remains the sole owner of \p *field_name.
2171
2172 @param[in] variant_field_type Variant field type of which to get
2173 the field at index \p index.
2174 @param[out] field_name Returned name of the field at index
2175 \p index (can be \c NULL).
2176 @param[out] field_type Returned field type of the field
2177 at index \p index (can be \c NULL).
2178 ­@param[in] index Index of the field to get from
2179 \p variant_field_type.
2180 @returns 0 on success, or a negative value on error.
2181
2182 @prenotnull{variant_field_type}
2183 @preisvarft{variant_field_type}
2184 @pre \p index is lesser than the number of fields contained in the
2185 variant field type \p variant_field_type (see
2186 bt_ctf_field_type_variant_get_field_count()).
2187 @postrefcountsame{variant_field_type}
2188 @post <strong>On success</strong>, the returned field's type is placed
2189 in \p *field_type and its reference count is incremented.
2190
2191 @sa bt_ctf_field_type_variant_get_field_type_by_name(): Finds a variant
2192 field type's field by name.
2193 @sa bt_ctf_field_type_variant_get_field_type_from_tag(): Finds a variant
2194 field type's field by current tag value.
2195 */
2196 extern int bt_ctf_field_type_variant_get_field(
2197 struct bt_ctf_field_type *variant_field_type,
2198 const char **field_name,
2199 struct bt_ctf_field_type **field_type, int index);
2200
2201 /**
2202 @brief Returns the type of the field (choice) named \p field_name
2203 found in the @varft \p variant_field_type.
2204
2205 @param[in] variant_field_type Variant field type of which to get
2206 a field's type.
2207 @param[in] field_name Name of the field to find.
2208 @returns Type of the field named \p field_name in
2209 \p variant_field_type, or
2210 \c NULL on error.
2211
2212 @prenotnull{variant_field_type}
2213 @prenotnull{field_name}
2214 @preisvarft{variant_field_type}
2215 @postrefcountsame{variant_field_type}
2216 @postsuccessrefcountretinc
2217
2218 @sa bt_ctf_field_type_variant_get_field(): Finds a variant field type's
2219 field by index.
2220 @sa bt_ctf_field_type_variant_get_field_type_from_tag(): Finds a variant
2221 field type's field by current tag value.
2222 */
2223 extern
2224 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name(
2225 struct bt_ctf_field_type *variant_field_type,
2226 const char *field_name);
2227
2228 /**
2229 @brief Returns the type of the field (choice) selected by the value of
2230 the @enumfield \p tag_field in the @varft \p variant_field_type.
2231
2232 \p tag_field is the current tag value.
2233
2234 The field type of \p tag_field, as returned by bt_ctf_field_get_type(),
2235 \em must be equivalent to the field type returned by
2236 bt_ctf_field_type_variant_get_tag_type() for \p variant_field_type.
2237
2238 @param[in] variant_field_type Variant field type of which to get
2239 a field's type.
2240 @param[in] tag_field Current tag value (variant field type's
2241 selector).
2242 @returns Type of the field selected by
2243 \p tag_field in \p variant_field_type,
2244 or \c NULL on error.
2245
2246 @prenotnull{variant_field_type}
2247 @prenotnull{tag_field}
2248 @preisvarft{variant_field_type}
2249 @preisenumfield{tag_field}
2250 @postrefcountsame{variant_field_type}
2251 @postrefcountsame{tag_field}
2252 @postsuccessrefcountretinc
2253
2254 @sa bt_ctf_field_type_variant_get_field(): Finds a variant field type's
2255 field by index.
2256 @sa bt_ctf_field_type_variant_get_field_type_by_name(): Finds a variant
2257 field type's field by name.
2258 */
2259 extern
2260 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_from_tag(
2261 struct bt_ctf_field_type *variant_field_type,
2262 struct bt_ctf_field *tag_field);
2263
2264 /**
2265 @brief Adds a field (a choice) named \p field_name with the @ft
2266 \p field_type to the @varft \p variant_field_type.
2267
2268 On success, \p field_type becomes the child of \p variant_field_type.
2269
2270 You \em cannot add a field named \p field_name if there's already a
2271 field named \p field_name in \p variant_field_type.
2272
2273 \p field_name \em must name an existing mapping in the tag's
2274 enumeration field type of \p variant_field_type.
2275
2276 @param[in] variant_field_type Variant field type to which to add
2277 a new field.
2278 @param[in] field_type Field type of the field to add to
2279 \p variant_field_type.
2280 @param[in] field_name Name of the field to add to
2281 \p variant_field_type
2282 (copied on success).
2283 @returns 0 on success, or a negative value on error.
2284
2285 @prenotnull{variant_field_type}
2286 @prenotnull{field_type}
2287 @prenotnull{field_name}
2288 @preisvarft{variant_field_type}
2289 @pre \p field_type is not and does not contain \p variant_field_type,
2290 recursively, as a field's type.
2291 @prehot{variant_field_type}
2292 @postrefcountsame{variant_field_type}
2293 @postsuccessrefcountinc{field_type}
2294 */
2295 extern int bt_ctf_field_type_variant_add_field(
2296 struct bt_ctf_field_type *variant_field_type,
2297 struct bt_ctf_field_type *field_type,
2298 const char *field_name);
2299
2300 /** @} */
2301
2302 #ifdef __cplusplus
2303 }
2304 #endif
2305
2306 #endif /* BABELTRACE_CTF_IR_FIELD_TYPES_H */
This page took 0.107764 seconds and 5 git commands to generate.