Hide new bt_ctf_field_path_* symbols
[babeltrace.git] / formats / ctf / ir / field-path.c
1 /*
2 * field-path.c
3 *
4 * Babeltrace CTF IR - Field path
5 *
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28 #include <babeltrace/ctf-ir/field-types.h>
29 #include <babeltrace/ctf-ir/field-types-internal.h>
30 #include <babeltrace/ctf-ir/field-path-internal.h>
31 #include <babeltrace/ctf-ir/field-path.h>
32 #include <limits.h>
33 #include <glib.h>
34
35 static
36 void field_path_destroy(struct bt_object *obj)
37 {
38 struct bt_ctf_field_path *field_path = (struct bt_ctf_field_path *) obj;
39
40 if (!field_path) {
41 return;
42 }
43
44 if (field_path->indexes) {
45 g_array_free(field_path->indexes, TRUE);
46 }
47 g_free(field_path);
48 }
49
50 BT_HIDDEN
51 struct bt_ctf_field_path *bt_ctf_field_path_create(void)
52 {
53 struct bt_ctf_field_path *field_path = NULL;
54
55 field_path = g_new0(struct bt_ctf_field_path, 1);
56 if (!field_path) {
57 goto error;
58 }
59
60 bt_object_init(field_path, field_path_destroy);
61 field_path->root = BT_CTF_SCOPE_UNKNOWN;
62 field_path->indexes = g_array_new(TRUE, FALSE, sizeof(int));
63 if (!field_path->indexes) {
64 goto error;
65 }
66
67 return field_path;
68
69 error:
70 BT_PUT(field_path);
71 return NULL;
72 }
73
74 BT_HIDDEN
75 void bt_ctf_field_path_clear(struct bt_ctf_field_path *field_path)
76 {
77 if (field_path->indexes->len > 0) {
78 g_array_remove_range(field_path->indexes, 0,
79 field_path->indexes->len);
80 }
81 }
82
83 BT_HIDDEN
84 struct bt_ctf_field_path *bt_ctf_field_path_copy(
85 struct bt_ctf_field_path *path)
86 {
87 struct bt_ctf_field_path *new_path = bt_ctf_field_path_create();
88
89 if (!new_path) {
90 goto end;
91 }
92
93 new_path->root = path->root;
94 g_array_insert_vals(new_path->indexes, 0,
95 path->indexes->data, path->indexes->len);
96 end:
97 return new_path;
98 }
99
100 BT_HIDDEN
101 enum bt_ctf_scope bt_ctf_field_path_get_root_scope(
102 const struct bt_ctf_field_path *field_path)
103 {
104 enum bt_ctf_scope scope = BT_CTF_SCOPE_UNKNOWN;
105
106 if (!field_path) {
107 goto end;
108 }
109
110 scope = field_path->root;
111
112 end:
113 return scope;
114 }
115
116 BT_HIDDEN
117 int bt_ctf_field_path_get_index_count(
118 const struct bt_ctf_field_path *field_path)
119 {
120 int ret = -1;
121
122 if (!field_path) {
123 goto end;
124 }
125
126 ret = field_path->indexes->len;
127
128 end:
129 return ret;
130 }
131
132 BT_HIDDEN
133 int bt_ctf_field_path_get_index(const struct bt_ctf_field_path *field_path,
134 int index)
135 {
136 int ret = INT_MIN;
137
138 if (!field_path || index < 0) {
139 goto end;
140 }
141
142 if (index >= field_path->indexes->len) {
143 goto end;
144 }
145
146 ret = g_array_index(field_path->indexes, int, index);
147
148 end:
149 return ret;
150 }
This page took 0.032298 seconds and 4 git commands to generate.