lib: use common precond. assert. macros from `assert-cond.h` thru lib
[babeltrace.git] / src / lib / trace-ir / field-class.h
... / ...
CommitLineData
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 */
7
8#ifndef BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
9#define BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
10
11#include "lib/assert-cond.h"
12#include <babeltrace2/trace-ir/clock-class.h>
13#include <babeltrace2/trace-ir/field-class.h>
14#include "common/macros.h"
15#include "common/common.h"
16#include "lib/object.h"
17#include <babeltrace2/types.h>
18#include <stdbool.h>
19#include <stdint.h>
20#include <glib.h>
21
22#define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \
23 (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \
24 struct bt_field_class_enumeration_mapping, (_index)))
25
26#define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \
27 (&g_array_index((_mapping)->ranges, \
28 struct bt_field_class_enumeration_mapping_range, (_index)))
29
30struct bt_field;
31struct bt_field_class;
32
33struct bt_field_class {
34 struct bt_object base;
35 enum bt_field_class_type type;
36 bool frozen;
37
38 /* Owned by this */
39 struct bt_value *user_attributes;
40
41 /*
42 * This flag indicates whether or not this field class is part
43 * of a trace class.
44 */
45 bool part_of_trace_class;
46};
47
48struct bt_field_class_bool {
49 struct bt_field_class common;
50};
51
52struct bt_field_class_bit_array {
53 struct bt_field_class common;
54 uint64_t length;
55};
56
57struct bt_field_class_integer {
58 struct bt_field_class common;
59
60 /*
61 * Value range of fields built from this integer field class:
62 * this is an equivalent integer size in bits. More formally,
63 * `range` is `n` in:
64 *
65 * Unsigned range: [0, 2^n - 1]
66 * Signed range: [-2^(n - 1), 2^(n - 1) - 1]
67 */
68 uint64_t range;
69
70 enum bt_field_class_integer_preferred_display_base base;
71};
72
73struct bt_field_class_enumeration_mapping {
74 GString *label;
75
76 /* Owner by this */
77 const struct bt_integer_range_set *range_set;
78};
79
80struct bt_field_class_enumeration_unsigned_mapping;
81struct bt_field_class_enumeration_signed_mapping;
82
83struct bt_field_class_enumeration {
84 struct bt_field_class_integer common;
85
86 /* Array of `struct bt_field_class_enumeration_mapping *` */
87 GArray *mappings;
88
89 /*
90 * This is an array of `const char *` which acts as a temporary
91 * (potentially growing) buffer for
92 * bt_field_class_enumeration_unsigned_get_mapping_labels_for_value()
93 * and
94 * bt_field_class_enumeration_signed_get_mapping_labels_for_value().
95 *
96 * The actual strings are owned by the mappings above.
97 */
98 GPtrArray *label_buf;
99};
100
101struct bt_field_class_real {
102 struct bt_field_class common;
103};
104
105struct bt_field_class_string {
106 struct bt_field_class common;
107};
108
109/* A named field class is a (name, field class) pair */
110struct bt_named_field_class {
111 GString *name;
112
113 /* Owned by this */
114 struct bt_value *user_attributes;
115
116 /* Owned by this */
117 struct bt_field_class *fc;
118
119 bool frozen;
120};
121
122struct bt_field_class_structure_member;
123struct bt_field_class_variant_option;
124struct bt_field_class_variant_with_selector_field_integer_unsigned_option;
125struct bt_field_class_variant_with_selector_field_integer_signed_option;
126
127struct bt_field_class_named_field_class_container {
128 struct bt_field_class common;
129
130 /*
131 * Key: `const char *`, not owned by this (owned by named field
132 * class objects contained in `named_fcs` below).
133 */
134 GHashTable *name_to_index;
135
136 /* Array of `struct bt_named_field_class *` */
137 GPtrArray *named_fcs;
138};
139
140struct bt_field_class_structure {
141 struct bt_field_class_named_field_class_container common;
142};
143
144struct bt_field_class_array {
145 struct bt_field_class common;
146
147 /* Owned by this */
148 struct bt_field_class *element_fc;
149};
150
151struct bt_field_class_array_static {
152 struct bt_field_class_array common;
153 uint64_t length;
154};
155
156struct bt_field_class_array_dynamic {
157 struct bt_field_class_array common;
158
159 /* Owned by this */
160 struct bt_field_class *length_fc;
161
162 /* Owned by this */
163 struct bt_field_path *length_field_path;
164};
165
166struct bt_field_class_option {
167 struct bt_field_class common;
168
169 /* Owned by this */
170 struct bt_field_class *content_fc;
171};
172
173struct bt_field_class_option_with_selector_field {
174 struct bt_field_class_option common;
175
176 /* Owned by this */
177 struct bt_field_class *selector_fc;
178
179 /* Owned by this */
180 struct bt_field_path *selector_field_path;
181};
182
183struct bt_field_class_option_with_selector_field_bool {
184 struct bt_field_class_option_with_selector_field common;
185
186 /* Owned by this */
187 bool sel_is_reversed;
188};
189
190struct bt_field_class_option_with_selector_field_integer {
191 struct bt_field_class_option_with_selector_field common;
192
193 /* Owned by this */
194 const struct bt_integer_range_set *range_set;
195};
196
197/* Variant FC (with selector) option: named field class + range set */
198struct bt_field_class_variant_with_selector_field_option {
199 struct bt_named_field_class common;
200
201 /* Owned by this */
202 const struct bt_integer_range_set *range_set;
203};
204
205struct bt_field_class_variant {
206 /*
207 * Depending on the variant field class type, the contained
208 * named field classes are of type
209 * `struct bt_named_field_class *` if the variant field class
210 * doesn't have a selector, or
211 * `struct bt_field_class_variant_with_selector_field_option *`
212 * if it has.
213 */
214 struct bt_field_class_named_field_class_container common;
215};
216
217struct bt_field_class_variant_with_selector_field {
218 struct bt_field_class_variant common;
219
220 /*
221 * Owned by this, but never dereferenced: only use to find it
222 * elsewhere.
223 */
224 const struct bt_field_class *selector_fc;
225
226 /* Owned by this */
227 struct bt_field_path *selector_field_path;
228};
229
230BT_HIDDEN
231void _bt_field_class_freeze(const struct bt_field_class *field_class);
232
233#ifdef BT_DEV_MODE
234# define bt_field_class_freeze _bt_field_class_freeze
235#else
236# define bt_field_class_freeze(_fc) ((void) _fc)
237#endif
238
239BT_HIDDEN
240void _bt_named_field_class_freeze(const struct bt_named_field_class *named_fc);
241
242#ifdef BT_DEV_MODE
243# define bt_named_field_class_freeze _bt_named_field_class_freeze
244#else
245# define bt_named_field_class_freeze(_named_fc) ((void) _named_fc)
246#endif
247
248/*
249 * This function recursively marks `field_class` and its children as
250 * being part of a trace. This is used to validate that all field classes
251 * are used at a single location within trace objects even if they are
252 * shared objects for other purposes.
253 */
254BT_HIDDEN
255void bt_field_class_make_part_of_trace_class(
256 const struct bt_field_class *field_class);
257
258#endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */
This page took 0.023903 seconds and 4 git commands to generate.