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 | ||
28 | struct bt_ctf_field_type *create_int_field_type(void) | |
29 | { | |
30 | struct bt_ctf_field_type *field_type; | |
31 | ||
32 | field_type = bt_ctf_field_type_integer_create(16); | |
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 | ||
45 | struct bt_ctf_field_type *create_int_field_type(void) | |
46 | { | |
47 | int ret; | |
48 | struct bt_ctf_field_type *field_type; | |
49 | ||
50 | field_type = bt_ctf_field_type_integer_create(23); | |
51 | assert(field_type); | |
52 | ||
53 | ret = bt_ctf_field_type_set_byte_order(field_type, | |
54 | BT_CTF_BYTE_ORDER_BIG_ENDIAN); | |
55 | assert(ret == 0); | |
56 | ||
57 | ret = bt_ctf_field_type_integer_set_signed(field_type, 1); | |
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 | ||
70 | struct bt_ctf_field_type *create_int_field_type( | |
71 | struct bt_ctf_clock_class *clock_class) | |
72 | { | |
73 | int ret; | |
74 | struct bt_ctf_field_type *field_type; | |
75 | ||
76 | field_type = bt_ctf_field_type_integer_create(8); | |
77 | assert(field_type); | |
78 | ||
79 | ret = bt_ctf_field_type_integer_set_base(field_type, | |
80 | BT_CTF_INTEGER_BASE_HEXADECIMAL); | |
81 | assert(ret == 0); | |
82 | ||
83 | ret = bt_ctf_field_type_integer_set_mapped_clock(field_type, clock_class); | |
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 | ||
101 | struct bt_ctf_field_type *create_float_field_type(void) | |
102 | { | |
103 | struct bt_ctf_field_type *field_type; | |
104 | ||
105 | field_type = bt_ctf_field_type_floating_point_create(); | |
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 | ||
118 | struct bt_ctf_field_type *create_float_field_type(void) | |
119 | { | |
120 | int ret; | |
121 | struct bt_ctf_field_type *field_type; | |
122 | ||
123 | field_type = bt_ctf_field_type_floating_point_create(); | |
124 | assert(field_type); | |
125 | ||
126 | ret = bt_ctf_field_type_set_byte_order(field_type, | |
127 | BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
128 | assert(ret == 0); | |
129 | ||
130 | ret = bt_ctf_field_type_floating_point_set_exponent_digits(field_type, 11); | |
131 | assert(ret == 0); | |
132 | ||
133 | ret = bt_ctf_field_type_floating_point_set_mantissa_digits(field_type, 53); | |
134 | assert(ret == 0); | |
135 | ||
136 | return field_type; | |
137 | } | |
138 | @endcode | |
139 | */ |