ir: make bt_ctf_field_type_copy() public
[babeltrace.git] / include / babeltrace / ctf-ir / field-types.h
CommitLineData
2e33ac5a
PP
1#ifndef BABELTRACE_CTF_IR_FIELD_TYPES_H
2#define BABELTRACE_CTF_IR_FIELD_TYPES_H
adc315b8
JG
3
4/*
2e33ac5a 5 * BabelTrace - CTF IR: Event field types
adc315b8 6 *
de9dd397 7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
adc315b8
JG
8 *
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 *
29 * The Common Trace Format (CTF) Specification is available at
30 * http://www.efficios.com/ctf
31 */
32
adc315b8
JG
33#include <stdint.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39struct bt_ctf_event_class;
40struct bt_ctf_event;
41struct bt_ctf_field_type;
b92ddaaa 42struct bt_ctf_field;
b011f6b0 43struct bt_ctf_field_path;
adc315b8 44
9a19a512
PP
45/*
46 * Babeltrace 1.x enumerations that were also used in CTF writer's API.
47 * They are left here for backward compatibility reasons, but
48 * enum bt_ctf_type_id and enum bt_ctf_string_encoding should be used
49 * in new code. Both new enumerations are compatible with their legacy
50 * counterpart.
51 */
52enum ctf_type_id {
53 CTF_TYPE_UNKNOWN = 0,
54 CTF_TYPE_INTEGER,
55 CTF_TYPE_FLOAT,
56 CTF_TYPE_ENUM,
57 CTF_TYPE_STRING,
58 CTF_TYPE_STRUCT,
59 CTF_TYPE_UNTAGGED_VARIANT,
60 CTF_TYPE_VARIANT,
61 CTF_TYPE_ARRAY,
62 CTF_TYPE_SEQUENCE,
63 NR_CTF_TYPES,
64};
65
66/*
67 * Old enum.
68 */
69enum ctf_string_encoding {
70 CTF_STRING_NONE = 0,
71 CTF_STRING_UTF8,
72 CTF_STRING_ASCII,
73 CTF_STRING_UNKNOWN,
74};
75
76enum bt_ctf_type_id {
77 BT_CTF_TYPE_ID_UNKNOWN = CTF_TYPE_UNKNOWN,
78 BT_CTF_TYPE_ID_INTEGER = CTF_TYPE_INTEGER,
79 BT_CTF_TYPE_ID_FLOAT = CTF_TYPE_FLOAT,
80 BT_CTF_TYPE_ID_ENUM = CTF_TYPE_ENUM,
81 BT_CTF_TYPE_ID_STRING = CTF_TYPE_STRING,
82 BT_CTF_TYPE_ID_STRUCT = CTF_TYPE_STRUCT,
83 BT_CTF_TYPE_ID_UNTAGGED_VARIANT = CTF_TYPE_UNTAGGED_VARIANT,
84 BT_CTF_TYPE_ID_VARIANT = CTF_TYPE_VARIANT,
85 BT_CTF_TYPE_ID_ARRAY = CTF_TYPE_ARRAY,
86 BT_CTF_TYPE_ID_SEQUENCE = CTF_TYPE_SEQUENCE,
87 BT_CTF_NR_TYPE_IDS,
88};
89
adc315b8
JG
90enum bt_ctf_integer_base {
91 BT_CTF_INTEGER_BASE_UNKNOWN = -1,
92 BT_CTF_INTEGER_BASE_BINARY = 2,
93 BT_CTF_INTEGER_BASE_OCTAL = 8,
94 BT_CTF_INTEGER_BASE_DECIMAL = 10,
95 BT_CTF_INTEGER_BASE_HEXADECIMAL = 16,
96};
97
98enum bt_ctf_byte_order {
b92ddaaa 99 BT_CTF_BYTE_ORDER_UNKNOWN = -1,
c35a1669 100 /*
46df6b28
PP
101 * Note that native, in the context of the CTF specification, is defined
102 * as "the byte order described in the trace" and does not mean that the
103 * host's endianness will be used.
c35a1669 104 */
adc315b8
JG
105 BT_CTF_BYTE_ORDER_NATIVE = 0,
106 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN,
107 BT_CTF_BYTE_ORDER_BIG_ENDIAN,
108 BT_CTF_BYTE_ORDER_NETWORK,
109};
110
87b41f95
PP
111enum bt_ctf_string_encoding {
112 BT_CTF_STRING_ENCODING_NONE = CTF_STRING_NONE,
113 BT_CTF_STRING_ENCODING_UTF8 = CTF_STRING_UTF8,
114 BT_CTF_STRING_ENCODING_ASCII = CTF_STRING_ASCII,
115 BT_CTF_STRING_ENCODING_UNKNOWN = CTF_STRING_UNKNOWN,
116};
117
46df6b28
PP
118enum bt_ctf_scope {
119 BT_CTF_SCOPE_UNKNOWN = -1,
120 BT_CTF_SCOPE_ENV = 0,
121 BT_CTF_SCOPE_TRACE_PACKET_HEADER = 1,
122 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT = 2,
123 BT_CTF_SCOPE_STREAM_EVENT_HEADER = 3,
124 BT_CTF_SCOPE_STREAM_EVENT_CONTEXT = 4,
125 BT_CTF_SCOPE_EVENT_CONTEXT = 5,
126 BT_CTF_SCOPE_EVENT_FIELDS = 6,
b011f6b0
PP
127};
128
adc315b8
JG
129/*
130 * bt_ctf_field_type_integer_create: create an integer field type.
131 *
132 * Allocate a new integer field type of the given size. The creation of a field
0ce5791b 133 * type sets its reference count to 1.
adc315b8
JG
134 *
135 * @param size Integer field type size/length in bits.
136 *
137 * Returns an allocated field type on success, NULL on error.
138 */
139extern struct bt_ctf_field_type *bt_ctf_field_type_integer_create(
140 unsigned int size);
141
b92ddaaa
JG
142/*
143 * bt_ctf_field_type_integer_get_size: get an integer type's size.
144 *
145 * Get an integer type's size.
146 *
147 * @param integer Integer type.
148 *
149 * Returns the integer type's size, a negative value on error.
150 */
151extern int bt_ctf_field_type_integer_get_size(
152 struct bt_ctf_field_type *integer);
153
154/*
155 * bt_ctf_field_type_integer_get_signed: get an integer type's signedness.
156 *
157 * Get an integer type's signedness attribute.
158 *
159 * @param integer Integer type.
160 *
161 * Returns the integer's signedness, a negative value on error.
162 */
163extern int bt_ctf_field_type_integer_get_signed(
164 struct bt_ctf_field_type *integer);
165
adc315b8
JG
166/*
167 * bt_ctf_field_type_integer_set_signed: set an integer type's signedness.
168 *
169 * Set an integer type's signedness attribute.
170 *
171 * @param integer Integer type.
172 * @param is_signed Integer's signedness, defaults to FALSE.
173 *
174 * Returns 0 on success, a negative value on error.
175 */
176extern int bt_ctf_field_type_integer_set_signed(
177 struct bt_ctf_field_type *integer, int is_signed);
178
b92ddaaa
JG
179/*
180 * bt_ctf_field_type_integer_get_base: get an integer type's base.
181 *
182 * Get an integer type's base used to pretty-print the resulting trace.
183 *
184 * @param integer Integer type.
185 *
186 * Returns the integer type's base on success, BT_CTF_INTEGER_BASE_UNKNOWN on
187 * error.
188 */
189extern enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base(
190 struct bt_ctf_field_type *integer);
191
adc315b8
JG
192/*
193 * bt_ctf_field_type_integer_set_base: set an integer type's base.
194 *
195 * Set an integer type's base used to pretty-print the resulting trace.
196 *
197 * @param integer Integer type.
198 * @param base Integer base, defaults to BT_CTF_INTEGER_BASE_DECIMAL.
199 *
200 * Returns 0 on success, a negative value on error.
201 */
2c4a0758 202extern int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer,
adc315b8
JG
203 enum bt_ctf_integer_base base);
204
b92ddaaa
JG
205/*
206 * bt_ctf_field_type_integer_get_encoding: get an integer type's encoding.
207 *
208 * @param integer Integer type.
209 *
87b41f95
PP
210 * Returns the string field's encoding on success,
211 * BT_CTF_STRING_ENCODING_UNKNOWN on error.
b92ddaaa 212 */
87b41f95 213extern enum bt_ctf_string_encoding bt_ctf_field_type_integer_get_encoding(
b92ddaaa
JG
214 struct bt_ctf_field_type *integer);
215
adc315b8
JG
216/*
217 * bt_ctf_field_type_integer_set_encoding: set an integer type's encoding.
218 *
219 * An integer encoding may be set to signal that the integer must be printed as
220 * a text character.
221 *
222 * @param integer Integer type.
87b41f95
PP
223 * @param encoding Integer output encoding, defaults to
224 * BT_CTF_STRING_ENCODING_NONE
adc315b8
JG
225 *
226 * Returns 0 on success, a negative value on error.
227 */
228extern int bt_ctf_field_type_integer_set_encoding(
229 struct bt_ctf_field_type *integer,
87b41f95 230 enum bt_ctf_string_encoding encoding);
adc315b8 231
6cfb906f
JG
232/**
233 * bt_ctf_field_type_integer_get_mapped_clock: get an integer type's mapped clock.
234 *
235 * @param integer Integer type.
236 *
237 * Returns the integer's mapped clock (if any), NULL on error.
238 */
239extern struct bt_ctf_clock *bt_ctf_field_type_integer_get_mapped_clock(
240 struct bt_ctf_field_type *integer);
241
242/**
243 * bt_ctf_field_type_integer_set_mapped_clock: set an integer type's mapped clock.
244 *
245 * @param integer Integer type.
246 * @param clock Clock to map.
247 *
248 * Returns 0 on success, a negative value on error.
249 */
250extern int bt_ctf_field_type_integer_set_mapped_clock(
251 struct bt_ctf_field_type *integer,
252 struct bt_ctf_clock *clock);
253
adc315b8
JG
254/*
255 * bt_ctf_field_type_enumeration_create: create an enumeration field type.
256 *
257 * Allocate a new enumeration field type with the given underlying type. The
258 * creation of a field type sets its reference count to 1.
259 * The resulting enumeration will share the integer_container_type's ownership
260 * by increasing its reference count.
261 *
262 * @param integer_container_type Underlying integer type of the enumeration
263 * type.
264 *
265 * Returns an allocated field type on success, NULL on error.
266 */
267extern struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(
268 struct bt_ctf_field_type *integer_container_type);
269
b92ddaaa
JG
270/*
271 * bt_ctf_field_type_enumeration_get_container_type: get underlying container.
272 *
273 * Get the enumeration type's underlying integer container type.
274 *
275 * @param enumeration Enumeration type.
276 *
277 * Returns an allocated field type on success, NULL on error.
278 */
279extern
280struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type(
281 struct bt_ctf_field_type *enumeration);
282
adc315b8
JG
283/*
284 * bt_ctf_field_type_enumeration_add_mapping: add an enumeration mapping.
285 *
286 * Add a mapping to the enumeration. The range's values are inclusive.
287 *
288 * @param enumeration Enumeration type.
b92ddaaa 289 * @param name Enumeration mapping name (will be copied).
adc315b8
JG
290 * @param range_start Enumeration mapping range start.
291 * @param range_end Enumeration mapping range end.
292 *
293 * Returns 0 on success, a negative value on error.
294 */
295extern int bt_ctf_field_type_enumeration_add_mapping(
b92ddaaa 296 struct bt_ctf_field_type *enumeration, const char *name,
adc315b8
JG
297 int64_t range_start, int64_t range_end);
298
b92ddaaa
JG
299/*
300 * bt_ctf_field_type_enumeration_add_mapping_unsigned: add an enumeration
301 * mapping.
302 *
303 * Add a mapping to the enumeration. The range's values are inclusive.
304 *
305 * @param enumeration Enumeration type.
306 * @param name Enumeration mapping name (will be copied).
307 * @param range_start Enumeration mapping range start.
308 * @param range_end Enumeration mapping range end.
309 *
310 * Returns 0 on success, a negative value on error.
311 */
312extern int bt_ctf_field_type_enumeration_add_mapping_unsigned(
313 struct bt_ctf_field_type *enumeration, const char *name,
314 uint64_t range_start, uint64_t range_end);
315
316/*
317 * bt_ctf_field_type_enumeration_get_mapping_count: Get the number of mappings
318 * defined in the enumeration.
319 *
320 * @param enumeration Enumeration type.
321 *
322 * Returns the mapping count on success, a negative value on error.
323 */
074ee56d 324extern int bt_ctf_field_type_enumeration_get_mapping_count(
b92ddaaa
JG
325 struct bt_ctf_field_type *enumeration);
326
327/*
328 * bt_ctf_field_type_enumeration_get_mapping: get an enumeration mapping.
329 *
330 * @param enumeration Enumeration type.
331 * @param index Index of mapping.
332 * @param name Pointer where the mapping's name will be returned (valid for
333 * the lifetime of the enumeration).
334 * @param range_start Pointer where the enumeration mapping's range start will
335 * be returned.
336 * @param range_end Pointer where the enumeration mapping's range end will
337 * be returned.
338 *
339 * Returns 0 on success, a negative value on error.
340 */
341extern int bt_ctf_field_type_enumeration_get_mapping(
074ee56d 342 struct bt_ctf_field_type *enumeration, int index,
b92ddaaa
JG
343 const char **name, int64_t *range_start, int64_t *range_end);
344
345/*
346 * bt_ctf_field_type_enumeration_get_mapping_unsigned: get a mapping.
347 *
348 * @param enumeration Enumeration type.
349 * @param index Index of mapping.
350 * @param name Pointer where the mapping's name will be returned (valid for
351 * the lifetime of the enumeration).
352 * @param range_start Pointer where the enumeration mapping's range start will
353 * be returned.
354 * @param range_end Pointer where the enumeration mapping's range end will
355 * be returned.
356 *
357 * Returns 0 on success, a negative value on error.
358 */
359extern int bt_ctf_field_type_enumeration_get_mapping_unsigned(
074ee56d 360 struct bt_ctf_field_type *enumeration, int index,
b92ddaaa
JG
361 const char **name, uint64_t *range_start,
362 uint64_t *range_end);
363
364/*
365 * bt_ctf_field_type_enumeration_get_mapping_index_by_name: get an enumerations'
366 * mapping index by name.
367 *
368 * @param enumeration Enumeration type.
369 * @param name Mapping name.
b92ddaaa 370 *
074ee56d 371 * Returns mapping index on success, a negative value on error.
b92ddaaa
JG
372 */
373extern int bt_ctf_field_type_enumeration_get_mapping_index_by_name(
074ee56d 374 struct bt_ctf_field_type *enumeration, const char *name);
b92ddaaa
JG
375
376/*
377 * bt_ctf_field_type_enumeration_get_mapping_index_by_value: get an
378 * enumerations' mapping index by value.
379 *
380 * @param enumeration Enumeration type.
381 * @param value Value.
b92ddaaa 382 *
074ee56d 383 * Returns mapping index on success, a negative value on error.
b92ddaaa
JG
384 */
385extern int bt_ctf_field_type_enumeration_get_mapping_index_by_value(
074ee56d 386 struct bt_ctf_field_type *enumeration, int64_t value);
b92ddaaa
JG
387
388/*
389 * bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value: get an
390 * enumerations' mapping index by value.
391 *
392 * @param enumeration Enumeration type.
393 * @param value Value.
b92ddaaa
JG
394 *
395 * Returns 0 on success, a negative value on error.
396 */
397extern int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(
074ee56d 398 struct bt_ctf_field_type *enumeration, uint64_t value);
b92ddaaa 399
adc315b8
JG
400/*
401 * bt_ctf_field_type_floating_point_create: create a floating point field type.
402 *
403 * Allocate a new floating point field type. The creation of a field type sets
404 * its reference count to 1.
405 *
406 * Returns an allocated field type on success, NULL on error.
407 */
408extern struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
409
b92ddaaa
JG
410/*
411 * bt_ctf_field_type_floating_point_get_exponent_digits: get exponent digit
412 * count.
413 *
414 * @param floating_point Floating point type.
415 *
416 * Returns the exponent digit count on success, a negative value on error.
417 */
418extern int bt_ctf_field_type_floating_point_get_exponent_digits(
419 struct bt_ctf_field_type *floating_point);
420
adc315b8
JG
421/*
422 * bt_ctf_field_type_floating_point_set_exponent_digits: set exponent digit
b92ddaaa 423 * count.
adc315b8
JG
424 *
425 * Set the number of exponent digits to use to store the floating point field.
426 * The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG.
427 *
428 * @param floating_point Floating point type.
429 * @param exponent_digits Number of digits to allocate to the exponent (defaults
430 * to FLT_EXP_DIG).
431 *
432 * Returns 0 on success, a negative value on error.
433 */
434extern int bt_ctf_field_type_floating_point_set_exponent_digits(
435 struct bt_ctf_field_type *floating_point,
436 unsigned int exponent_digits);
437
438/*
b92ddaaa 439 * bt_ctf_field_type_floating_point_get_mantissa_digits: get mantissa digit
adc315b8
JG
440 * count.
441 *
b92ddaaa
JG
442 * @param floating_point Floating point type.
443 *
444 * Returns the mantissa digit count on success, a negative value on error.
445 */
446extern int bt_ctf_field_type_floating_point_get_mantissa_digits(
447 struct bt_ctf_field_type *floating_point);
448
449/*
450 * bt_ctf_field_type_floating_point_set_mantissa_digits: set mantissa digit
451 * count.
452 *
adc315b8
JG
453 * Set the number of mantissa digits to use to store the floating point field.
454 * The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG.
455 *
456 * @param floating_point Floating point type.
457 * @param mantissa_digits Number of digits to allocate to the mantissa (defaults
458 * to FLT_MANT_DIG).
459 *
460 * Returns 0 on success, a negative value on error.
461 */
462extern int bt_ctf_field_type_floating_point_set_mantissa_digits(
463 struct bt_ctf_field_type *floating_point,
464 unsigned int mantissa_digits);
465
466/*
467 * bt_ctf_field_type_structure_create: create a structure field type.
468 *
469 * Allocate a new structure field type. The creation of a field type sets
470 * its reference count to 1.
471 *
472 * Returns an allocated field type on success, NULL on error.
473 */
474extern struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
475
476/*
477 * bt_ctf_field_type_structure_add_field: add a field to a structure.
478 *
479 * Add a field of type "field_type" to the structure. The structure will share
480 * field_type's ownership by increasing its reference count.
481 *
482 * @param structure Structure type.
483 * @param field_type Type of the field to add to the structure type.
484 * @param field_name Name of the structure's new field (will be copied).
485 *
486 * Returns 0 on success, a negative value on error.
487 */
488extern int bt_ctf_field_type_structure_add_field(
489 struct bt_ctf_field_type *structure,
490 struct bt_ctf_field_type *field_type,
491 const char *field_name);
492
b92ddaaa
JG
493/*
494 * bt_ctf_field_type_structure_get_field_count: Get the number of fields defined
495 * in the structure.
496 *
497 * @param structure Structure type.
498 *
499 * Returns the field count on success, a negative value on error.
500 */
074ee56d 501extern int bt_ctf_field_type_structure_get_field_count(
b92ddaaa
JG
502 struct bt_ctf_field_type *structure);
503
504/*
505 * bt_ctf_field_type_structure_get_field: get a structure's field type and name.
506 *
507 * @param structure Structure type.
508 * @param field_type Pointer to a const char* where the field's name will
509 * be returned.
510 * @param field_type Pointer to a bt_ctf_field_type* where the field's type will
511 * be returned.
512 * @param index Index of field.
513 *
514 * Returns 0 on success, a negative value on error.
515 */
516extern int bt_ctf_field_type_structure_get_field(
517 struct bt_ctf_field_type *structure,
518 const char **field_name, struct bt_ctf_field_type **field_type,
074ee56d 519 int index);
b92ddaaa
JG
520
521/*
522 * bt_ctf_field_type_structure_get_field_type_by_name: get a structure field's
523 * type by name.
524 *
525 * @param structure Structure type.
526 * @param field_name Name of the structure's field.
527 *
528 * Returns a field type instance on success, NULL on error.
529 */
530extern
531struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name(
532 struct bt_ctf_field_type *structure, const char *field_name);
533
adc315b8
JG
534/*
535 * bt_ctf_field_type_variant_create: create a variant field type.
536 *
537 * Allocate a new variant field type. The creation of a field type sets
538 * its reference count to 1. tag_name must be the name of an enumeration
539 * field declared in the same scope as this variant.
540 *
541 * @param enum_tag Type of the variant's tag/selector (must be an enumeration).
542 * @param tag_name Name of the variant's tag/selector field (will be copied).
543 *
544 * Returns an allocated field type on success, NULL on error.
545 */
546extern struct bt_ctf_field_type *bt_ctf_field_type_variant_create(
b92ddaaa
JG
547 struct bt_ctf_field_type *enum_tag, const char *tag_name);
548
549/*
550 * bt_ctf_field_type_variant_get_tag_type: get a variant's tag type.
551 *
552 * @param variant Variant type.
553 *
6964b7fd 554 * Returns a field type instance on success, NULL if unset.
b92ddaaa
JG
555 */
556extern struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type(
557 struct bt_ctf_field_type *variant);
558
559/*
560 * bt_ctf_field_type_variant_get_tag_name: get a variant's tag name.
561 *
562 * @param variant Variant type.
563 *
6964b7fd 564 * Returns the tag field's name, NULL if unset.
b92ddaaa
JG
565 */
566extern const char *bt_ctf_field_type_variant_get_tag_name(
567 struct bt_ctf_field_type *variant);
adc315b8 568
d9b1ab6d
JG
569/*
570 * bt_ctf_field_type_variant_set_tag_name: set a variant's tag name.
571 *
572 * @param variant Variant type.
573 * @param name Tag field name.
574 *
575 * Returns 0 on success, a negative value on error.
576 */
577extern int bt_ctf_field_type_variant_set_tag_name(
578 struct bt_ctf_field_type *variant, const char *name);
579
adc315b8
JG
580/*
581 * bt_ctf_field_type_variant_add_field: add a field to a variant.
582 *
b92ddaaa 583 * Add a field of type "field_type" to the variant. The variant will share
adc315b8
JG
584 * field_type's ownership by increasing its reference count. The "field_name"
585 * will be copied. field_name must match a mapping in the tag/selector
586 * enumeration.
587 *
588 * @param variant Variant type.
589 * @param field_type Type of the variant type's new field.
590 * @param field_name Name of the variant type's new field (will be copied).
591 *
592 * Returns 0 on success, a negative value on error.
593 */
594extern int bt_ctf_field_type_variant_add_field(
595 struct bt_ctf_field_type *variant,
596 struct bt_ctf_field_type *field_type,
597 const char *field_name);
598
b92ddaaa
JG
599/*
600 * bt_ctf_field_type_variant_get_field_type_by_name: get variant field's type.
601 *
602 * @param structure Variant type.
603 * @param field_name Name of the variant's field.
604 *
605 * Returns a field type instance on success, NULL on error.
606 */
607extern
608struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name(
609 struct bt_ctf_field_type *variant, const char *field_name);
610
611/*
612 * bt_ctf_field_type_variant_get_field_type_from_tag: get variant field's type.
613 *
614 * @param variant Variant type.
615 * @param tag Type tag (enum).
616 *
617 * Returns a field type instance on success, NULL on error.
618 */
619extern
620struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_from_tag(
621 struct bt_ctf_field_type *variant, struct bt_ctf_field *tag);
622
623/*
624 * bt_ctf_field_type_variant_get_field_count: Get the number of fields defined
625 * in the variant.
626 *
627 * @param variant Variant type.
628 *
629 * Returns the field count on success, a negative value on error.
630 */
074ee56d 631extern int bt_ctf_field_type_variant_get_field_count(
b92ddaaa
JG
632 struct bt_ctf_field_type *variant);
633
634/*
635 * bt_ctf_field_type_variant_get_field: get a variant's field name and type.
636 *
637 * @param variant Variant type.
638 * @param field_type Pointer to a const char* where the field's name will
639 * be returned.
640 * @param field_type Pointer to a bt_ctf_field_type* where the field's type will
641 * be returned.
642 * @param index Index of field.
643 *
644 * Returns 0 on success, a negative value on error.
645 */
646extern int bt_ctf_field_type_variant_get_field(
647 struct bt_ctf_field_type *variant, const char **field_name,
074ee56d 648 struct bt_ctf_field_type **field_type, int index);
b92ddaaa 649
adc315b8
JG
650/*
651 * bt_ctf_field_type_array_create: create an array field type.
652 *
653 * Allocate a new array field type. The creation of a field type sets
654 * its reference count to 1.
655 *
656 * @param element_type Array's element type.
657 * @oaram length Array type's length.
658 *
659 * Returns an allocated field type on success, NULL on error.
660 */
661extern struct bt_ctf_field_type *bt_ctf_field_type_array_create(
b92ddaaa
JG
662 struct bt_ctf_field_type *element_type, unsigned int length);
663
664/*
665 * bt_ctf_field_type_array_get_element_type: get an array's element type.
666 *
667 * @param array Array type.
668 *
669 * Returns a field type instance on success, NULL on error.
670 */
671extern struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type(
672 struct bt_ctf_field_type *array);
673
674/*
675 * bt_ctf_field_type_array_get_length: get an array's length.
676 *
677 * @param array Array type.
678 *
679 * Returns the array's length on success, a negative value on error.
680 */
681extern int64_t bt_ctf_field_type_array_get_length(
682 struct bt_ctf_field_type *array);
adc315b8
JG
683
684/*
685 * bt_ctf_field_type_sequence_create: create a sequence field type.
686 *
687 * Allocate a new sequence field type. The creation of a field type sets
688 * its reference count to 1. "length_field_name" must match an integer field
689 * declared in the same scope.
690 *
691 * @param element_type Sequence's element type.
692 * @param length_field_name Name of the sequence's length field (will be
693 * copied).
694 *
695 * Returns an allocated field type on success, NULL on error.
696 */
697extern struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(
698 struct bt_ctf_field_type *element_type,
699 const char *length_field_name);
700
b92ddaaa
JG
701/*
702 * bt_ctf_field_type_sequence_get_element_type: get a sequence's element type.
703 *
704 * @param sequence Sequence type.
705 *
706 * Returns a field type instance on success, NULL on error.
707 */
708extern struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type(
709 struct bt_ctf_field_type *sequence);
710
711/*
712 * bt_ctf_field_type_sequence_get_length_field_name: get length field name.
713 *
714 * @param sequence Sequence type.
715 *
716 * Returns the sequence's length field on success, NULL on error.
717 */
718extern const char *bt_ctf_field_type_sequence_get_length_field_name(
719 struct bt_ctf_field_type *sequence);
720
adc315b8
JG
721/*
722 * bt_ctf_field_type_string_create: create a string field type.
723 *
724 * Allocate a new string field type. The creation of a field type sets
725 * its reference count to 1.
726 *
727 * Returns an allocated field type on success, NULL on error.
728 */
729extern struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
730
b92ddaaa
JG
731/*
732 * bt_ctf_field_type_string_get_encoding: get a string type's encoding.
733 *
734 * Get the string type's encoding.
735 *
736 * @param string_type String type.
737 *
87b41f95
PP
738 * Returns the string's encoding on success, a BT_CTF_STRING_ENCODING_UNKNOWN
739 * on error.
b92ddaaa 740 */
87b41f95 741extern enum bt_ctf_string_encoding bt_ctf_field_type_string_get_encoding(
b92ddaaa
JG
742 struct bt_ctf_field_type *string_type);
743
adc315b8
JG
744/*
745 * bt_ctf_field_type_string_set_encoding: set a string type's encoding.
746 *
747 * Set the string type's encoding.
748 *
b92ddaaa 749 * @param string_type String type.
87b41f95
PP
750 * @param encoding String field encoding, default BT_CTF_STRING_ENCODING_ASCII.
751 * Valid values are BT_CTF_STRING_ENCODING_ASCII and
752 * BT_CTF_STRING_ENCODING_UTF8.
adc315b8
JG
753 *
754 * Returns 0 on success, a negative value on error.
755 */
756extern int bt_ctf_field_type_string_set_encoding(
b92ddaaa 757 struct bt_ctf_field_type *string_type,
87b41f95 758 enum bt_ctf_string_encoding encoding);
adc315b8 759
b92ddaaa
JG
760/*
761 * bt_ctf_field_type_get_alignment: get a field type's alignment.
762 *
763 * Get the field type's alignment.
764 *
765 * @param type Field type.
766 *
46caf2cb
JG
767 * Returns the field type's alignment on success, a negative value on error and
768 * 0 if the alignment is undefined (as in the case of a variant).
b92ddaaa
JG
769 */
770extern int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
771
adc315b8
JG
772/*
773 * bt_ctf_field_type_set_alignment: set a field type's alignment.
774 *
775 * Set the field type's alignment.
776 *
777 * @param type Field type.
778 * @param alignment Type's alignment. Defaults to 1 (bit-aligned). However,
779 * some types, such as structures and string, may impose other alignment
780 * constraints.
781 *
782 * Returns 0 on success, a negative value on error.
783 */
784extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type,
785 unsigned int alignment);
786
b92ddaaa
JG
787/*
788 * bt_ctf_field_type_get_byte_order: get a field type's byte order.
789 *
790 * @param type Field type.
791 *
792 * Returns the field type's byte order on success, a negative value on error.
793 */
794extern enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(
795 struct bt_ctf_field_type *type);
796
adc315b8
JG
797/*
798 * bt_ctf_field_type_set_byte_order: set a field type's byte order.
799 *
800 * Set the field type's byte order.
801 *
802 * @param type Field type.
803 * @param byte_order Field type's byte order. Defaults to
c35a1669 804 * BT_CTF_BYTE_ORDER_NATIVE; the trace's endianness.
adc315b8
JG
805 *
806 * Returns 0 on success, a negative value on error.
807 */
808extern int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type,
809 enum bt_ctf_byte_order byte_order);
810
b011f6b0
PP
811/*
812 * bt_ctf_field_type_variant_get_tag_field_path: get a variant's tag's field
813 * path.
814 *
815 * Get the variant's tag's field path.
816 *
817 * @param type Field type.
818 *
819 * Returns the field path on success, NULL on error or if no field path is set.
820 */
821extern struct bt_ctf_field_path *bt_ctf_field_type_variant_get_tag_field_path(
822 struct bt_ctf_field_type *type);
823
824/*
825 * bt_ctf_field_type_sequence_get_length_field_path: get a sequence's length's
826 * field path.
827 *
828 * Get the sequence's length's field path.
829 *
830 * @param type Field type.
831 *
832 * Returns the field path on success, NULL on error or if no field path is set.
833 */
834extern struct bt_ctf_field_path *bt_ctf_field_type_sequence_get_length_field_path(
835 struct bt_ctf_field_type *type);
836
265e809c
PP
837/*
838 * bt_ctf_field_type_compare: compare two field types recursively
839 *
840 * Compare two field types recursively.
841 *
842 * The registered tag field type of a variant field type is ignored:
843 * only the tag strings are compared.
844 *
845 * @param type_a Field type A.
846 * @param type_b Field type B.
847 *
81e36fac
PP
848 * Returns 0 if both field types are semantically equivalent, a positive
849 * value if they are not equivalent, or a negative value on error.
265e809c
PP
850 */
851extern int bt_ctf_field_type_compare(struct bt_ctf_field_type *type_a,
852 struct bt_ctf_field_type *type_b);
853
06629ab3
PP
854extern struct bt_ctf_field_type *bt_ctf_field_type_copy(
855 struct bt_ctf_field_type *type);
856
b92ddaaa 857/*
9a19a512 858 * bt_ctf_field_type_get_type_id: get a field type's bt_ctf_type_id.
b92ddaaa
JG
859 *
860 * @param type Field type.
861 *
9a19a512 862 * Returns the field type's bt_ctf_type_id, CTF_TYPE_UNKNOWN on error.
b92ddaaa 863 */
9a19a512 864extern enum bt_ctf_type_id bt_ctf_field_type_get_type_id(
b92ddaaa
JG
865 struct bt_ctf_field_type *type);
866
56db8d7a
PP
867/*
868 * bt_ctf_field_type_is_integer: returns whether or not a given field
869 * type is an integer type.
870 *
871 * @param type Field type.
872 *
873 * Returns 1 if the field type is an integer type, 0 otherwise.
874 */
875extern int bt_ctf_field_type_is_integer(struct bt_ctf_field_type *type);
876
877/*
878 * bt_ctf_field_type_is_floating_point: returns whether or not a given field
879 * type is a floating point number type.
880 *
881 * @param type Field type.
882 *
883 * Returns 1 if the field type is a floating point number type, 0 otherwise.
884 */
885extern int bt_ctf_field_type_is_floating_point(struct bt_ctf_field_type *type);
886
887/*
888 * bt_ctf_field_type_is_enumeration: returns whether or not a given field
889 * type is an enumeration type.
890 *
891 * @param type Field type.
892 *
893 * Returns 1 if the field type is an enumeration type, 0 otherwise.
894 */
895extern int bt_ctf_field_type_is_enumeration(struct bt_ctf_field_type *type);
896
897/*
898 * bt_ctf_field_type_is_string: returns whether or not a given field
899 * type is a string type.
900 *
901 * @param type Field type.
902 *
903 * Returns 1 if the field type is a string type, 0 otherwise.
904 */
905extern int bt_ctf_field_type_is_string(struct bt_ctf_field_type *type);
906
907/*
908 * bt_ctf_field_type_is_structure: returns whether or not a given field
909 * type is a structure type.
910 *
911 * @param type Field type.
912 *
913 * Returns 1 if the field type is a structure type, 0 otherwise.
914 */
915extern int bt_ctf_field_type_is_structure(struct bt_ctf_field_type *type);
916
917/*
918 * bt_ctf_field_type_is_array: returns whether or not a given field
919 * type is an array type.
920 *
921 * @param type Field type.
922 *
923 * Returns 1 if the field type is an array type, 0 otherwise.
924 */
925extern int bt_ctf_field_type_is_array(struct bt_ctf_field_type *type);
926
927/*
928 * bt_ctf_field_type_is_sequence: returns whether or not a given field
929 * type is a sequence type.
930 *
931 * @param type Field type.
932 *
933 * Returns 1 if the field type is a sequence type, 0 otherwise.
934 */
935extern int bt_ctf_field_type_is_sequence(struct bt_ctf_field_type *type);
936
937/*
938 * bt_ctf_field_type_is_variant: returns whether or not a given field
939 * type is a variant type.
940 *
941 * @param type Field type.
942 *
943 * Returns 1 if the field type is a variant type, 0 otherwise.
944 */
945extern int bt_ctf_field_type_is_variant(struct bt_ctf_field_type *type);
946
adc315b8
JG
947#ifdef __cplusplus
948}
949#endif
950
2e33ac5a 951#endif /* BABELTRACE_CTF_IR_FIELD_TYPES_H */
This page took 0.071796 seconds and 4 git commands to generate.