From: Philippe Proulx Date: Wed, 24 May 2017 21:59:03 +0000 (-0400) Subject: field-path.c: add internal function to stringify a field path X-Git-Tag: v2.0.0-pre1~199 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=331b8d44fe96f3a5e5d8a177e0eebda9838ac8d5 field-path.c: add internal function to stringify a field path This is to be used by logging statements. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/include/babeltrace/ctf-ir/field-path-internal.h b/include/babeltrace/ctf-ir/field-path-internal.h index de08a87e..b270094b 100644 --- a/include/babeltrace/ctf-ir/field-path-internal.h +++ b/include/babeltrace/ctf-ir/field-path-internal.h @@ -54,4 +54,7 @@ BT_HIDDEN struct bt_ctf_field_path *bt_ctf_field_path_copy( struct bt_ctf_field_path *path); +BT_HIDDEN +GString *bt_ctf_field_path_string(struct bt_ctf_field_path *path); + #endif /* BABELTRACE_CTF_IR_FIELD_PATH_INTERNAL */ diff --git a/lib/ctf-ir/field-path.c b/lib/ctf-ir/field-path.c index 9b991ded..ac42ef5c 100644 --- a/lib/ctf-ir/field-path.c +++ b/lib/ctf-ir/field-path.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -169,3 +170,29 @@ int bt_ctf_field_path_get_index(const struct bt_ctf_field_path *field_path, end: return ret; } + +BT_HIDDEN +GString *bt_ctf_field_path_string(struct bt_ctf_field_path *path) +{ + GString *str = g_string_new(NULL); + size_t i; + + assert(path); + + if (!str) { + goto end; + } + + g_string_append_printf(str, "[%s", bt_ctf_scope_string(path->root)); + + for (i = 0; i < path->indexes->len; i++) { + int index = g_array_index(path->indexes, int, i); + + g_string_append_printf(str, ", %d", index); + } + + g_string_append(str, "]"); + +end: + return str; +}