cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / lib / trace-ir / field.h
CommitLineData
273b65be 1/*
0235b0db
MJ
2 * SPDX-License-Identifier: MIT
3 *
e2f7325d 4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
de9dd397 5 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
273b65be
JG
6 */
7
0235b0db
MJ
8#ifndef BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H
9#define BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H
10
578e048b 11#include "lib/object.h"
3fadfbc0 12#include <babeltrace2/types.h>
dc3fffef 13#include <stdint.h>
d990a4fb 14#include <stdbool.h>
273b65be
JG
15#include <glib.h>
16
578e048b 17#include "field-class.h"
578e048b 18
3dca2276 19struct bt_field;
3dca2276 20
5cd6d0e5 21typedef struct bt_field *(* bt_field_create_func)(struct bt_field_class *);
44c440bc 22typedef void (*bt_field_method_set_is_frozen)(struct bt_field *, bool);
40f4ba76 23typedef bool (*bt_field_method_is_set)(const struct bt_field *);
cb6f1f7d
PP
24typedef void (*bt_field_method_reset)(struct bt_field *);
25
26struct bt_field_methods {
27 bt_field_method_set_is_frozen set_is_frozen;
cb6f1f7d
PP
28 bt_field_method_is_set is_set;
29 bt_field_method_reset reset;
3dca2276
PP
30};
31
cb6f1f7d 32struct bt_field {
83509119 33 struct bt_object base;
44c440bc
PP
34
35 /* Owned by this */
5cd6d0e5 36 struct bt_field_class *class;
44c440bc
PP
37
38 /* Virtual table for slow path (dev mode) operations */
cb6f1f7d 39 struct bt_field_methods *methods;
44c440bc
PP
40
41 bool is_set;
d990a4fb 42 bool frozen;
273b65be
JG
43};
44
5cebbe7f
PP
45struct bt_field_bool {
46 struct bt_field common;
47 bool value;
48};
49
1094efa4
PP
50struct bt_field_bit_array {
51 struct bt_field common;
52 uint64_t value_as_int;
53};
54
cb6f1f7d
PP
55struct bt_field_integer {
56 struct bt_field common;
273b65be 57
44c440bc
PP
58 union {
59 uint64_t u;
60 int64_t i;
61 } value;
cb6f1f7d
PP
62};
63
44c440bc 64struct bt_field_real {
cb6f1f7d 65 struct bt_field common;
44c440bc 66 double value;
273b65be
JG
67};
68
cb6f1f7d
PP
69struct bt_field_structure {
70 struct bt_field common;
312c056a 71
cb6f1f7d 72 /* Array of `struct bt_field *`, owned by this */
312c056a 73 GPtrArray *fields;
273b65be
JG
74};
75
b38aea74
PP
76struct bt_field_option {
77 struct bt_field common;
78
79 /* Owned by this */
80 struct bt_field *content_field;
81
82 /* Weak: equal to `content_field` above or `NULL` */
83 struct bt_field *selected_field;
84};
85
cb6f1f7d
PP
86struct bt_field_variant {
87 struct bt_field common;
312c056a 88
44c440bc
PP
89 /* Weak: belongs to `fields` below */
90 struct bt_field *selected_field;
312c056a 91
44c440bc
PP
92 /* Index of currently selected field */
93 uint64_t selected_index;
312c056a 94
cb6f1f7d 95 /* Array of `struct bt_field *`, owned by this */
312c056a 96 GPtrArray *fields;
273b65be
JG
97};
98
cb6f1f7d
PP
99struct bt_field_array {
100 struct bt_field common;
312c056a 101
cb6f1f7d 102 /* Array of `struct bt_field *`, owned by this */
44c440bc 103 GPtrArray *fields;
312c056a 104
44c440bc 105 /* Current effective length */
312c056a 106 uint64_t length;
273b65be
JG
107};
108
cb6f1f7d
PP
109struct bt_field_string {
110 struct bt_field common;
4d4b475d 111 GArray *buf;
44c440bc 112 uint64_t length;
273b65be
JG
113};
114
f6ccaed9 115#ifdef BT_DEV_MODE
44c440bc
PP
116# define bt_field_set_is_frozen _bt_field_set_is_frozen
117# define bt_field_is_set _bt_field_is_set
118# define bt_field_reset _bt_field_reset
119# define bt_field_set_single _bt_field_set_single
f6ccaed9 120#else
44c440bc
PP
121# define bt_field_set_is_frozen(_field, _is_frozen)
122# define bt_field_is_set(_field) (BT_FALSE)
123# define bt_field_reset(_field)
124# define bt_field_set_single(_field, _val)
f6ccaed9 125#endif
918be005 126
40f4ba76 127void _bt_field_set_is_frozen(const struct bt_field *field, bool is_frozen);
3dca2276
PP
128
129static inline
40f4ba76 130void _bt_field_reset(const struct bt_field *field)
3dca2276 131{
98b15851
PP
132 BT_ASSERT_DBG(field);
133 BT_ASSERT_DBG(field->methods->reset);
40f4ba76 134 field->methods->reset((void *) field);
3dca2276
PP
135}
136
137static inline
44c440bc 138void _bt_field_set_single(struct bt_field *field, bool value)
3dca2276 139{
98b15851 140 BT_ASSERT_DBG(field);
44c440bc 141 field->is_set = value;
3dca2276
PP
142}
143
144static inline
40f4ba76 145bt_bool _bt_field_is_set(const struct bt_field *field)
3dca2276
PP
146{
147 bt_bool is_set = BT_FALSE;
148
149 if (!field) {
150 goto end;
151 }
152
98b15851 153 BT_ASSERT_DBG(field->methods->is_set);
3dca2276
PP
154 is_set = field->methods->is_set(field);
155
156end:
157 return is_set;
158}
159
5cd6d0e5 160struct bt_field *bt_field_create(struct bt_field_class *class);
312c056a 161
44c440bc 162void bt_field_destroy(struct bt_field *field);
312c056a 163
56e18c4c 164#endif /* BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H */
This page took 0.120377 seconds and 4 git commands to generate.