1 #ifndef BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H
2 #define BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H
5 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 #include <babeltrace/assert-pre-internal.h>
28 #include <babeltrace/common-internal.h>
29 #include <babeltrace/trace-ir/field-class-internal.h>
30 #include <babeltrace/trace-ir/utils-internal.h>
31 #include <babeltrace/object-internal.h>
32 #include <babeltrace/babeltrace-internal.h>
33 #include <babeltrace/types.h>
40 #define BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(_field, _cls_type, _name) \
41 BT_ASSERT_PRE(((const struct bt_field *) (_field))->class->type == (_cls_type), \
42 _name " has the wrong class type: expected-class-type=%s, " \
44 bt_common_field_class_type_string(_cls_type), (_field))
46 #define BT_ASSERT_PRE_FIELD_IS_UNSIGNED_INT(_field, _name) \
48 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
49 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, \
50 _name " is not an unsigned integer field: %![field-]+f", \
53 #define BT_ASSERT_PRE_FIELD_IS_SIGNED_INT(_field, _name) \
55 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \
56 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, \
57 _name " is not a signed integer field: %![field-]+f", \
60 #define BT_ASSERT_PRE_FIELD_IS_ARRAY(_field, _name) \
62 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \
63 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, \
64 _name " is not an array field: %![field-]+f", (_field))
66 #define BT_ASSERT_PRE_FIELD_IS_SET(_field, _name) \
67 BT_ASSERT_PRE(bt_field_is_set(_field), \
68 _name " is not set: %!+f", (_field))
70 #define BT_ASSERT_PRE_FIELD_HOT(_field, _name) \
71 BT_ASSERT_PRE_HOT((const struct bt_field *) (_field), (_name), \
76 typedef struct bt_field
*(* bt_field_create_func
)(struct bt_field_class
*);
77 typedef void (*bt_field_method_set_is_frozen
)(struct bt_field
*, bool);
78 typedef bool (*bt_field_method_is_set
)(const struct bt_field
*);
79 typedef void (*bt_field_method_reset
)(struct bt_field
*);
81 struct bt_field_methods
{
82 bt_field_method_set_is_frozen set_is_frozen
;
83 bt_field_method_is_set is_set
;
84 bt_field_method_reset reset
;
88 struct bt_object base
;
91 struct bt_field_class
*class;
93 /* Virtual table for slow path (dev mode) operations */
94 struct bt_field_methods
*methods
;
100 struct bt_field_integer
{
101 struct bt_field common
;
109 struct bt_field_real
{
110 struct bt_field common
;
114 struct bt_field_structure
{
115 struct bt_field common
;
117 /* Array of `struct bt_field *`, owned by this */
121 struct bt_field_variant
{
122 struct bt_field common
;
124 /* Weak: belongs to `fields` below */
125 struct bt_field
*selected_field
;
127 /* Index of currently selected field */
128 uint64_t selected_index
;
130 /* Array of `struct bt_field *`, owned by this */
134 struct bt_field_array
{
135 struct bt_field common
;
137 /* Array of `struct bt_field *`, owned by this */
140 /* Current effective length */
144 struct bt_field_string
{
145 struct bt_field common
;
151 # define bt_field_set_is_frozen _bt_field_set_is_frozen
152 # define bt_field_is_set _bt_field_is_set
153 # define bt_field_reset _bt_field_reset
154 # define bt_field_set_single _bt_field_set_single
156 # define bt_field_set_is_frozen(_field, _is_frozen)
157 # define bt_field_is_set(_field) (BT_FALSE)
158 # define bt_field_reset(_field)
159 # define bt_field_set_single(_field, _val)
163 void _bt_field_set_is_frozen(const struct bt_field
*field
, bool is_frozen
);
166 void _bt_field_reset(const struct bt_field
*field
)
169 BT_ASSERT(field
->methods
->reset
);
170 field
->methods
->reset((void *) field
);
174 void _bt_field_set_single(struct bt_field
*field
, bool value
)
177 field
->is_set
= value
;
181 bt_bool
_bt_field_is_set(const struct bt_field
*field
)
183 bt_bool is_set
= BT_FALSE
;
189 BT_ASSERT(bt_field_class_has_known_type(field
->class));
190 BT_ASSERT(field
->methods
->is_set
);
191 is_set
= field
->methods
->is_set(field
);
198 struct bt_field
*bt_field_create(struct bt_field_class
*class);
201 void bt_field_destroy(struct bt_field
*field
);
203 #endif /* BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H */