cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / lib / trace-ir / field-path.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2016-2018 Philippe Proulx <pproulx@efficios.com>
5 *
6 * The Common Trace Format (CTF) Specification is available at
7 * http://www.efficios.com/ctf
8 */
9
10 #ifndef BABELTRACE_TRACE_IR_FIELD_PATH_INTERNAL
11 #define BABELTRACE_TRACE_IR_FIELD_PATH_INTERNAL
12
13 #include "lib/object.h"
14 #include <babeltrace2/trace-ir/field-path.h>
15 #include "common/assert.h"
16 #include "common/macros.h"
17 #include <glib.h>
18
19 struct bt_field_path_item {
20 enum bt_field_path_item_type type;
21 uint64_t index;
22 };
23
24 struct bt_field_path {
25 struct bt_object base;
26 enum bt_field_path_scope root;
27
28 /* Array of `struct bt_field_path_item` (items) */
29 GArray *items;
30 };
31
32 struct bt_field_path *bt_field_path_create(void);
33
34 static inline
35 struct bt_field_path_item *bt_field_path_borrow_item_by_index_inline(
36 const struct bt_field_path *field_path, uint64_t index)
37 {
38 BT_ASSERT_DBG(field_path);
39 BT_ASSERT_DBG(index < field_path->items->len);
40 return &bt_g_array_index(field_path->items, struct bt_field_path_item,
41 index);
42 }
43
44 static inline
45 void bt_field_path_append_item(struct bt_field_path *field_path,
46 struct bt_field_path_item *item)
47 {
48 BT_ASSERT(field_path);
49 BT_ASSERT(item);
50 g_array_append_val(field_path->items, *item);
51 }
52
53 static inline
54 void bt_field_path_remove_last_item(struct bt_field_path *field_path)
55 {
56 BT_ASSERT(field_path);
57 BT_ASSERT(field_path->items->len > 0);
58 g_array_set_size(field_path->items, field_path->items->len - 1);
59 }
60
61 static inline
62 const char *bt_field_path_item_type_string(enum bt_field_path_item_type type)
63 {
64 switch (type) {
65 case BT_FIELD_PATH_ITEM_TYPE_INDEX:
66 return "INDEX";
67 case BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT:
68 return "CURRENT_ARRAY_ELEMENT";
69 default:
70 return "(unknown)";
71 }
72 };
73
74 #endif /* BABELTRACE_TRACE_IR_FIELD_PATH_INTERNAL */
This page took 0.032591 seconds and 4 git commands to generate.