1 #ifndef BABELTRACE_CTF_IR_FIELDS_INTERNAL_H
2 #define BABELTRACE_CTF_IR_FIELDS_INTERNAL_H
5 * Babeltrace - CTF IR: Event Fields internal
7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
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
30 #include <babeltrace/assert-pre-internal.h>
31 #include <babeltrace/common-internal.h>
32 #include <babeltrace/ctf-ir/field-types-internal.h>
33 #include <babeltrace/ctf-ir/utils-internal.h>
34 #include <babeltrace/object-internal.h>
35 #include <babeltrace/babeltrace-internal.h>
36 #include <babeltrace/types.h>
43 #define BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(_field, _type_id, _name) \
44 BT_ASSERT_PRE((_field)->type->id == ((int) (_type_id)), \
45 _name " has the wrong type ID: expected-type-id=%s, " \
47 bt_common_field_type_id_string((int) (_type_id)), (_field))
49 #define BT_ASSERT_PRE_FIELD_IS_SET(_field, _name) \
50 BT_ASSERT_PRE(bt_field_is_set_recursive(_field), \
51 _name " is not set: %!+f", (_field))
53 #define BT_ASSERT_PRE_FIELD_HOT(_field, _name) \
54 BT_ASSERT_PRE_HOT((_field), (_name), ": %!+f", (_field))
58 typedef void (*bt_field_method_set_is_frozen
)(struct bt_field
*,
60 typedef int (*bt_field_method_validate
)(struct bt_field
*);
61 typedef bt_bool (*bt_field_method_is_set
)(struct bt_field
*);
62 typedef void (*bt_field_method_reset
)(struct bt_field
*);
64 struct bt_field_methods
{
65 bt_field_method_set_is_frozen set_is_frozen
;
66 bt_field_method_validate validate
;
67 bt_field_method_is_set is_set
;
68 bt_field_method_reset reset
;
72 struct bt_object base
;
73 struct bt_field_type
*type
;
74 struct bt_field_methods
*methods
;
79 struct bt_field_integer
{
80 struct bt_field common
;
87 struct bt_field_enumeration
{
88 struct bt_field_integer common
;
91 struct bt_field_floating_point
{
92 struct bt_field common
;
96 struct bt_field_structure
{
97 struct bt_field common
;
99 /* Array of `struct bt_field *`, owned by this */
103 struct bt_field_variant
{
104 struct bt_field common
;
111 /* Weak: belongs to `choices` below */
112 struct bt_field
*current_field
;
114 /* Array of `struct bt_field *`, owned by this */
118 struct bt_field_array
{
119 struct bt_field common
;
121 /* Array of `struct bt_field *`, owned by this */
125 struct bt_field_sequence
{
126 struct bt_field common
;
129 * This is the true sequence field's length: its value can be
130 * less than `elements->len` below because we never shrink the
131 * array of elements to avoid reallocation.
135 /* Array of `struct bt_field *`, owned by this */
139 struct bt_field_string
{
140 struct bt_field common
;
146 # define bt_field_validate_recursive _bt_field_validate_recursive
147 # define bt_field_set_is_frozen_recursive _bt_field_set_is_frozen_recursive
148 # define bt_field_is_set_recursive _bt_field_is_set_recursive
149 # define bt_field_reset_recursive _bt_field_reset_recursive
150 # define bt_field_set _bt_field_set
152 # define bt_field_validate_recursive(_field) (-1)
153 # define bt_field_set_is_frozen_recursive(_field, _is_frozen)
154 # define bt_field_is_set_recursive(_field) (BT_FALSE)
155 # define bt_field_reset_recursive(_field)
156 # define bt_field_set(_field, _val)
160 void _bt_field_set_is_frozen_recursive(struct bt_field
*field
,
164 int _bt_field_validate_recursive(struct bt_field
*field
)
169 BT_ASSERT_PRE_MSG("%s", "Invalid field: field is NULL.");
174 BT_ASSERT(bt_field_type_has_known_id(field
->type
));
176 if (field
->methods
->validate
) {
177 ret
= field
->methods
->validate(field
);
185 void _bt_field_reset_recursive(struct bt_field
*field
)
188 BT_ASSERT(field
->methods
->reset
);
189 field
->methods
->reset(field
);
193 void _bt_field_set(struct bt_field
*field
, bool value
)
196 field
->payload_set
= value
;
200 bt_bool
_bt_field_is_set_recursive(struct bt_field
*field
)
202 bt_bool is_set
= BT_FALSE
;
208 BT_ASSERT(bt_field_type_has_known_id(field
->type
));
209 BT_ASSERT(field
->methods
->is_set
);
210 is_set
= field
->methods
->is_set(field
);
217 struct bt_field
*bt_field_create_recursive(struct bt_field_type
*type
);
220 void bt_field_destroy_recursive(struct bt_field
*field
);
222 #endif /* BABELTRACE_CTF_IR_FIELDS_INTERNAL_H */