Commit | Line | Data |
---|---|---|
bb8c17e0 PP |
1 | /** |
2 | @page ctfirexamples CTF IR examples | |
3 | ||
4 | <strong>List of CTF IR examples</strong>: | |
5 | ||
6 | - @subpage ctfirfieldtypesexamples CTF IR field types examples | |
7 | ||
8 | @sa ctfir (API reference) | |
9 | ||
10 | ||
11 | @page ctfirfieldtypesexamples CTF IR field types examples | |
12 | ||
13 | This page contains usage examples of the \ref ctfirfieldtypes API. | |
14 | ||
15 | @noteexamplesassert | |
16 | ||
17 | ||
18 | @section ctfirfieldtypesexamples_intfieldtype Integer field type | |
19 | ||
20 | @sa ctfirintfieldtype | |
21 | ||
22 | @subsection ctfirfieldtypesexamples_intfieldtype0 Create a default, 16-bit integer field type | |
23 | ||
24 | @code{.c} | |
25 | #include <assert.h> | |
26 | #include <babeltrace/ctf-ir/field-types.h> | |
27 | ||
50842bdc | 28 | struct bt_field_type *create_int_field_type(void) |
bb8c17e0 | 29 | { |
50842bdc | 30 | struct bt_field_type *field_type; |
bb8c17e0 | 31 | |
50842bdc | 32 | field_type = bt_field_type_integer_create(16); |
bb8c17e0 PP |
33 | assert(field_type); |
34 | ||
35 | return field_type; | |
36 | } | |
37 | @endcode | |
38 | ||
39 | @subsection ctfirfieldtypesexamples_intfieldtype1 Create a 23-bit, signed, big-endian integer field type | |
40 | ||
41 | @code{.c} | |
42 | #include <assert.h> | |
43 | #include <babeltrace/ctf-ir/field-types.h> | |
44 | ||
50842bdc | 45 | struct bt_field_type *create_int_field_type(void) |
bb8c17e0 PP |
46 | { |
47 | int ret; | |
50842bdc | 48 | struct bt_field_type *field_type; |
bb8c17e0 | 49 | |
50842bdc | 50 | field_type = bt_field_type_integer_create(23); |
bb8c17e0 PP |
51 | assert(field_type); |
52 | ||
50842bdc PP |
53 | ret = bt_field_type_set_byte_order(field_type, |
54 | BT_BYTE_ORDER_BIG_ENDIAN); | |
bb8c17e0 PP |
55 | assert(ret == 0); |
56 | ||
50842bdc | 57 | ret = bt_field_type_integer_set_signed(field_type, 1); |
bb8c17e0 PP |
58 | assert(ret == 0); |
59 | ||
60 | return field_type; | |
61 | } | |
62 | @endcode | |
63 | ||
64 | @subsection ctfirfieldtypesexamples_intfieldtype2 Create an 8-bit integer field type, displayed in hexadecimal, mapped to a CTF IR clock class | |
65 | ||
66 | @code{.c} | |
67 | #include <assert.h> | |
68 | #include <babeltrace/ctf-ir/field-types.h> | |
69 | ||
50842bdc PP |
70 | struct bt_field_type *create_int_field_type( |
71 | struct bt_clock_class *clock_class) | |
bb8c17e0 PP |
72 | { |
73 | int ret; | |
50842bdc | 74 | struct bt_field_type *field_type; |
bb8c17e0 | 75 | |
50842bdc | 76 | field_type = bt_field_type_integer_create(8); |
bb8c17e0 PP |
77 | assert(field_type); |
78 | ||
50842bdc PP |
79 | ret = bt_field_type_integer_set_base(field_type, |
80 | BT_INTEGER_BASE_HEXADECIMAL); | |
bb8c17e0 PP |
81 | assert(ret == 0); |
82 | ||
50842bdc | 83 | ret = bt_field_type_integer_set_mapped_clock(field_type, clock_class); |
bb8c17e0 PP |
84 | assert(ret == 0); |
85 | ||
86 | return field_type; | |
87 | } | |
88 | @endcode | |
89 | ||
90 | ||
91 | @section ctfirfieldtypesexamples_floatfieldtype Floating point number field type | |
92 | ||
93 | @sa ctfirfloatfieldtype | |
94 | ||
95 | @subsection ctfirfieldtypesexamples_floatfieldtype0 Create a default floating point number field type | |
96 | ||
97 | @code{.c} | |
98 | #include <assert.h> | |
99 | #include <babeltrace/ctf-ir/field-types.h> | |
100 | ||
50842bdc | 101 | struct bt_field_type *create_float_field_type(void) |
bb8c17e0 | 102 | { |
50842bdc | 103 | struct bt_field_type *field_type; |
bb8c17e0 | 104 | |
50842bdc | 105 | field_type = bt_field_type_floating_point_create(); |
bb8c17e0 PP |
106 | assert(field_type); |
107 | ||
108 | return field_type; | |
109 | } | |
110 | @endcode | |
111 | ||
112 | @subsection ctfirfieldtypesexamples_floatfieldtype1 Create a "double", little-endian floating point number field type | |
113 | ||
114 | @code{.c} | |
115 | #include <assert.h> | |
116 | #include <babeltrace/ctf-ir/field-types.h> | |
117 | ||
50842bdc | 118 | struct bt_field_type *create_float_field_type(void) |
bb8c17e0 PP |
119 | { |
120 | int ret; | |
50842bdc | 121 | struct bt_field_type *field_type; |
bb8c17e0 | 122 | |
50842bdc | 123 | field_type = bt_field_type_floating_point_create(); |
bb8c17e0 PP |
124 | assert(field_type); |
125 | ||
50842bdc PP |
126 | ret = bt_field_type_set_byte_order(field_type, |
127 | BT_BYTE_ORDER_LITTLE_ENDIAN); | |
bb8c17e0 PP |
128 | assert(ret == 0); |
129 | ||
50842bdc | 130 | ret = bt_field_type_floating_point_set_exponent_digits(field_type, 11); |
bb8c17e0 PP |
131 | assert(ret == 0); |
132 | ||
50842bdc | 133 | ret = bt_field_type_floating_point_set_mantissa_digits(field_type, 53); |
bb8c17e0 PP |
134 | assert(ret == 0); |
135 | ||
136 | return field_type; | |
137 | } | |
138 | @endcode | |
139 | */ |