tap-driver.sh: flush stdout after each test result
[babeltrace.git] / include / babeltrace2 / trace-ir / field-internal.h
CommitLineData
108b91d0
PP
1#ifndef BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H
2#define BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H
273b65be
JG
3
4/*
f2b0325d 5 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
de9dd397 6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
273b65be 7 *
273b65be
JG
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:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
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
24 * SOFTWARE.
25 */
26
71c5da58
MJ
27#include <babeltrace2/assert-pre-internal.h>
28#include <babeltrace2/common-internal.h>
29#include <babeltrace2/trace-ir/field-class-internal.h>
30#include <babeltrace2/trace-ir/utils-internal.h>
31#include <babeltrace2/object-internal.h>
32#include <babeltrace2/babeltrace-internal.h>
33#include <babeltrace2/types.h>
dc3fffef 34#include <stdint.h>
e42dd763 35#include <string.h>
8deee039 36#include <inttypes.h>
a745c331 37#include <stdbool.h>
273b65be
JG
38#include <glib.h>
39
af0c18e3 40#define BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(_field, _cls_type, _name) \
78cf9df6 41 BT_ASSERT_PRE(((const struct bt_field *) (_field))->class->type == (_cls_type), \
af0c18e3 42 _name " has the wrong class type: expected-class-type=%s, " \
7b33a0e0 43 "%![field-]+f", \
af0c18e3 44 bt_common_field_class_type_string(_cls_type), (_field))
7b33a0e0
PP
45
46#define BT_ASSERT_PRE_FIELD_IS_UNSIGNED_INT(_field, _name) \
47 BT_ASSERT_PRE( \
78cf9df6
PP
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, \
7b33a0e0
PP
50 _name " is not an unsigned integer field: %![field-]+f", \
51 (_field))
52
53#define BT_ASSERT_PRE_FIELD_IS_SIGNED_INT(_field, _name) \
54 BT_ASSERT_PRE( \
78cf9df6
PP
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, \
7b33a0e0
PP
57 _name " is not a signed integer field: %![field-]+f", \
58 (_field))
59
60#define BT_ASSERT_PRE_FIELD_IS_ARRAY(_field, _name) \
61 BT_ASSERT_PRE( \
78cf9df6
PP
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, \
7b33a0e0
PP
64 _name " is not an array field: %![field-]+f", (_field))
65
66#define BT_ASSERT_PRE_FIELD_IS_SET(_field, _name) \
67 BT_ASSERT_PRE(bt_field_is_set(_field), \
18acc6f8 68 _name " is not set: %!+f", (_field))
8deee039 69
7b33a0e0 70#define BT_ASSERT_PRE_FIELD_HOT(_field, _name) \
78cf9df6 71 BT_ASSERT_PRE_HOT((const struct bt_field *) (_field), (_name), \
7b33a0e0 72 ": %!+f", (_field))
8deee039
PP
73
74struct bt_field;
8deee039 75
939190b3 76typedef struct bt_field *(* bt_field_create_func)(struct bt_field_class *);
7b33a0e0 77typedef void (*bt_field_method_set_is_frozen)(struct bt_field *, bool);
78cf9df6 78typedef bool (*bt_field_method_is_set)(const struct bt_field *);
18acc6f8
PP
79typedef void (*bt_field_method_reset)(struct bt_field *);
80
81struct bt_field_methods {
82 bt_field_method_set_is_frozen set_is_frozen;
18acc6f8
PP
83 bt_field_method_is_set is_set;
84 bt_field_method_reset reset;
8deee039
PP
85};
86
18acc6f8 87struct bt_field {
83509119 88 struct bt_object base;
7b33a0e0
PP
89
90 /* Owned by this */
939190b3 91 struct bt_field_class *class;
7b33a0e0
PP
92
93 /* Virtual table for slow path (dev mode) operations */
18acc6f8 94 struct bt_field_methods *methods;
7b33a0e0
PP
95
96 bool is_set;
a745c331 97 bool frozen;
273b65be
JG
98};
99
18acc6f8
PP
100struct bt_field_integer {
101 struct bt_field common;
273b65be 102
7b33a0e0
PP
103 union {
104 uint64_t u;
105 int64_t i;
106 } value;
18acc6f8
PP
107};
108
7b33a0e0 109struct bt_field_real {
18acc6f8 110 struct bt_field common;
7b33a0e0 111 double value;
273b65be
JG
112};
113
18acc6f8
PP
114struct bt_field_structure {
115 struct bt_field common;
a6918753 116
18acc6f8 117 /* Array of `struct bt_field *`, owned by this */
a6918753 118 GPtrArray *fields;
273b65be
JG
119};
120
18acc6f8
PP
121struct bt_field_variant {
122 struct bt_field common;
a6918753 123
7b33a0e0
PP
124 /* Weak: belongs to `fields` below */
125 struct bt_field *selected_field;
a6918753 126
7b33a0e0
PP
127 /* Index of currently selected field */
128 uint64_t selected_index;
a6918753 129
18acc6f8 130 /* Array of `struct bt_field *`, owned by this */
a6918753 131 GPtrArray *fields;
273b65be
JG
132};
133
18acc6f8
PP
134struct bt_field_array {
135 struct bt_field common;
a6918753 136
18acc6f8 137 /* Array of `struct bt_field *`, owned by this */
7b33a0e0 138 GPtrArray *fields;
a6918753 139
7b33a0e0 140 /* Current effective length */
a6918753 141 uint64_t length;
273b65be
JG
142};
143
18acc6f8
PP
144struct bt_field_string {
145 struct bt_field common;
e42dd763 146 GArray *buf;
7b33a0e0 147 uint64_t length;
273b65be
JG
148};
149
8b45963b 150#ifdef BT_DEV_MODE
7b33a0e0
PP
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
8b45963b 155#else
7b33a0e0
PP
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)
8b45963b 160#endif
918be005 161
18acc6f8 162BT_HIDDEN
78cf9df6 163void _bt_field_set_is_frozen(const struct bt_field *field, bool is_frozen);
8deee039
PP
164
165static inline
78cf9df6 166void _bt_field_reset(const struct bt_field *field)
8deee039
PP
167{
168 BT_ASSERT(field);
169 BT_ASSERT(field->methods->reset);
78cf9df6 170 field->methods->reset((void *) field);
8deee039
PP
171}
172
173static inline
7b33a0e0 174void _bt_field_set_single(struct bt_field *field, bool value)
8deee039
PP
175{
176 BT_ASSERT(field);
7b33a0e0 177 field->is_set = value;
8deee039
PP
178}
179
180static inline
78cf9df6 181bt_bool _bt_field_is_set(const struct bt_field *field)
8deee039
PP
182{
183 bt_bool is_set = BT_FALSE;
184
185 if (!field) {
186 goto end;
187 }
188
af0c18e3 189 BT_ASSERT(bt_field_class_has_known_type(field->class));
8deee039
PP
190 BT_ASSERT(field->methods->is_set);
191 is_set = field->methods->is_set(field);
192
193end:
194 return is_set;
195}
196
a6918753 197BT_HIDDEN
939190b3 198struct bt_field *bt_field_create(struct bt_field_class *class);
a6918753
PP
199
200BT_HIDDEN
7b33a0e0 201void bt_field_destroy(struct bt_field *field);
a6918753 202
108b91d0 203#endif /* BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H */
This page took 0.062512 seconds and 4 git commands to generate.