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 "lib/assert-pre.h"
28 #include "common/common.h"
29 #include "lib/object.h"
30 #include "common/macros.h"
31 #include <babeltrace2/types.h>
38 #include "field-class.h"
41 #define BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(_field, _cls_type, _name) \
42 BT_ASSERT_PRE_DEV(((const struct bt_field *) (_field))->class->type == (_cls_type), \
43 _name " has the wrong class type: expected-class-type=%s, " \
45 bt_common_field_class_type_string(_cls_type), (_field))
47 #define BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(_field, _name) \
49 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
50 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, \
51 _name " is not an unsigned integer field: %![field-]+f", \
54 #define BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(_field, _name) \
56 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \
57 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, \
58 _name " is not a signed integer field: %![field-]+f", \
61 #define BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(_field, _name) \
63 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \
64 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, \
65 _name " is not an array field: %![field-]+f", (_field))
67 #define BT_ASSERT_PRE_DEV_FIELD_IS_OPTION(_field, _name) \
69 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR || \
70 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR || \
71 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR || \
72 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR, \
73 _name " is not an option field: %![field-]+f", (_field))
75 #define BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(_field, _name) \
77 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR || \
78 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR || \
79 ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR, \
80 _name " is not a variant field: %![field-]+f", (_field))
82 #define BT_ASSERT_PRE_DEV_FIELD_IS_SET(_field, _name) \
83 BT_ASSERT_PRE_DEV(bt_field_is_set(_field), \
84 _name " is not set: %!+f", (_field))
86 #define BT_ASSERT_PRE_DEV_FIELD_HOT(_field, _name) \
87 BT_ASSERT_PRE_DEV_HOT((const struct bt_field *) (_field), (_name), \
92 typedef struct bt_field
*(* bt_field_create_func
)(struct bt_field_class
*);
93 typedef void (*bt_field_method_set_is_frozen
)(struct bt_field
*, bool);
94 typedef bool (*bt_field_method_is_set
)(const struct bt_field
*);
95 typedef void (*bt_field_method_reset
)(struct bt_field
*);
97 struct bt_field_methods
{
98 bt_field_method_set_is_frozen set_is_frozen
;
99 bt_field_method_is_set is_set
;
100 bt_field_method_reset reset
;
104 struct bt_object base
;
107 struct bt_field_class
*class;
109 /* Virtual table for slow path (dev mode) operations */
110 struct bt_field_methods
*methods
;
116 struct bt_field_bool
{
117 struct bt_field common
;
121 struct bt_field_bit_array
{
122 struct bt_field common
;
123 uint64_t value_as_int
;
126 struct bt_field_integer
{
127 struct bt_field common
;
135 struct bt_field_real
{
136 struct bt_field common
;
140 struct bt_field_structure
{
141 struct bt_field common
;
143 /* Array of `struct bt_field *`, owned by this */
147 struct bt_field_option
{
148 struct bt_field common
;
151 struct bt_field
*content_field
;
153 /* Weak: equal to `content_field` above or `NULL` */
154 struct bt_field
*selected_field
;
157 struct bt_field_variant
{
158 struct bt_field common
;
160 /* Weak: belongs to `fields` below */
161 struct bt_field
*selected_field
;
163 /* Index of currently selected field */
164 uint64_t selected_index
;
166 /* Array of `struct bt_field *`, owned by this */
170 struct bt_field_array
{
171 struct bt_field common
;
173 /* Array of `struct bt_field *`, owned by this */
176 /* Current effective length */
180 struct bt_field_string
{
181 struct bt_field common
;
187 # define bt_field_set_is_frozen _bt_field_set_is_frozen
188 # define bt_field_is_set _bt_field_is_set
189 # define bt_field_reset _bt_field_reset
190 # define bt_field_set_single _bt_field_set_single
192 # define bt_field_set_is_frozen(_field, _is_frozen)
193 # define bt_field_is_set(_field) (BT_FALSE)
194 # define bt_field_reset(_field)
195 # define bt_field_set_single(_field, _val)
199 void _bt_field_set_is_frozen(const struct bt_field
*field
, bool is_frozen
);
202 void _bt_field_reset(const struct bt_field
*field
)
205 BT_ASSERT(field
->methods
->reset
);
206 field
->methods
->reset((void *) field
);
210 void _bt_field_set_single(struct bt_field
*field
, bool value
)
213 field
->is_set
= value
;
217 bt_bool
_bt_field_is_set(const struct bt_field
*field
)
219 bt_bool is_set
= BT_FALSE
;
225 BT_ASSERT(field
->methods
->is_set
);
226 is_set
= field
->methods
->is_set(field
);
233 struct bt_field
*bt_field_create(struct bt_field_class
*class);
236 void bt_field_destroy(struct bt_field
*field
);
238 #endif /* BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H */