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