Rename: bt_put(), bt_get() -> bt_object_put_ref(), bt_object_get_ref()
[babeltrace.git] / lib / trace-ir / field-path.c
CommitLineData
b011f6b0
PP
1/*
2 * field-path.c
3 *
108b91d0 4 * Babeltrace trace IR - Field path
b011f6b0
PP
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
1e6cfa95
PP
28#define BT_LOG_TAG "FIELD-PATH"
29#include <babeltrace/lib-logging-internal.h>
30
7b33a0e0 31#include <babeltrace/assert-pre-internal.h>
939190b3
PP
32#include <babeltrace/trace-ir/field-classes.h>
33#include <babeltrace/trace-ir/field-classes-internal.h>
108b91d0
PP
34#include <babeltrace/trace-ir/field-path-internal.h>
35#include <babeltrace/trace-ir/field-path.h>
b011f6b0 36#include <limits.h>
544d0515 37#include <stdint.h>
1e6cfa95 38#include <inttypes.h>
8b45963b 39#include <babeltrace/assert-internal.h>
b011f6b0
PP
40#include <glib.h>
41
42static
7b33a0e0 43void destroy_field_path(struct bt_object *obj)
b011f6b0 44{
839d52a5 45 struct bt_field_path *field_path = (struct bt_field_path *) obj;
b011f6b0 46
7b33a0e0
PP
47 BT_ASSERT(field_path);
48 BT_LIB_LOGD("Destroying field path: %!+P", field_path);
49 g_array_free(field_path->indexes, TRUE);
b011f6b0
PP
50 g_free(field_path);
51}
52
53BT_HIDDEN
839d52a5 54struct bt_field_path *bt_field_path_create(void)
b011f6b0 55{
839d52a5 56 struct bt_field_path *field_path = NULL;
b011f6b0 57
1e6cfa95
PP
58 BT_LOGD_STR("Creating empty field path object.");
59
839d52a5 60 field_path = g_new0(struct bt_field_path, 1);
b011f6b0 61 if (!field_path) {
1e6cfa95 62 BT_LOGE_STR("Failed to allocate one field path.");
b011f6b0
PP
63 goto error;
64 }
65
7b33a0e0
PP
66 bt_object_init_shared(&field_path->base, destroy_field_path);
67 field_path->indexes = g_array_new(FALSE, FALSE, sizeof(uint64_t));
b011f6b0 68 if (!field_path->indexes) {
1e6cfa95 69 BT_LOGE_STR("Failed to allocate a GArray.");
b011f6b0
PP
70 goto error;
71 }
72
7b33a0e0
PP
73 BT_LIB_LOGD("Created empty field path object: %!+P", field_path);
74 goto end;
b011f6b0
PP
75
76error:
8138bfe1 77 BT_OBJECT_PUT_REF_AND_RESET(field_path);
b011f6b0 78
b011f6b0 79end:
7b33a0e0 80 return field_path;
b011f6b0
PP
81}
82
7b33a0e0 83enum bt_scope bt_field_path_get_root_scope(struct bt_field_path *field_path)
b011f6b0 84{
7b33a0e0
PP
85 BT_ASSERT_PRE_NON_NULL(field_path, "Field path");
86 return field_path->root;
b011f6b0
PP
87}
88
7b33a0e0 89uint64_t bt_field_path_get_index_count(struct bt_field_path *field_path)
b011f6b0 90{
7b33a0e0
PP
91 BT_ASSERT_PRE_NON_NULL(field_path, "Field path");
92 return (uint64_t) field_path->indexes->len;
b011f6b0
PP
93}
94
7b33a0e0 95uint64_t bt_field_path_get_index_by_index(struct bt_field_path *field_path,
9ac68eb1 96 uint64_t index)
b011f6b0 97{
7b33a0e0
PP
98 BT_ASSERT_PRE_NON_NULL(field_path, "Field path");
99 BT_ASSERT_PRE_VALID_INDEX(index, field_path->indexes->len);
100 return bt_field_path_get_index_by_index_inline(field_path, index);
b011f6b0 101}
This page took 0.042076 seconds and 4 git commands to generate.