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