Babeltrace-wide warning fixes
[babeltrace.git] / formats / ctf / types / enum.c
CommitLineData
6dc2ca62
MD
1/*
2 * Common Trace Format
3 *
4 * Enumeration mapping strings (quarks) from/to integers.
5 *
ccd7e1c8 6 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6dc2ca62 7 *
ccd7e1c8
MD
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
de0ba614 14 *
ccd7e1c8
MD
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
6dc2ca62
MD
17 */
18
d79865b9 19#include <babeltrace/ctf/types.h>
6dc2ca62
MD
20#include <stdint.h>
21#include <glib.h>
22
47e0f2e2
MD
23GArray *ctf_enum_read(struct stream_pos *pos,
24 const struct type_class_enum *src)
448d3cc7 25{
4c8bfb7e 26 const struct type_class_integer *int_class = &src->p;
448d3cc7
MD
27
28 if (!int_class->signedness) {
29 uint64_t v;
30
7fe00194 31 v = ctf_uint_read(pos, int_class);
47e0f2e2 32 return enum_uint_to_quark_set(src, v);
448d3cc7
MD
33 } else {
34 int64_t v;
35
4c8bfb7e 36 v = ctf_int_read(pos, int_class);
47e0f2e2 37 return enum_int_to_quark_set(src, v);
448d3cc7
MD
38 }
39}
40
47e0f2e2
MD
41/*
42 * Arbitrarily choose the start of the first matching range.
43 */
4c8bfb7e 44void ctf_enum_write(struct stream_pos *pos,
47e0f2e2
MD
45 const struct type_class_enum *dest,
46 GQuark q)
448d3cc7 47{
4c8bfb7e 48 const struct type_class_integer *int_class = &dest->p;
47e0f2e2 49 GArray *array;
448d3cc7 50
47e0f2e2
MD
51 array = enum_quark_to_range_set(dest, q);
52 assert(array);
448d3cc7 53
47e0f2e2
MD
54 if (!int_class->signedness) {
55 uint64_t v = g_array_index(array, struct enum_range, 0).start._unsigned;
4c8bfb7e 56 ctf_uint_write(pos, int_class, v);
448d3cc7 57 } else {
47e0f2e2 58 int64_t v = g_array_index(array, struct enum_range, 0).start._unsigned;
4c8bfb7e 59 ctf_int_write(pos, int_class, v);
448d3cc7 60 }
6dc2ca62 61}
This page took 0.026914 seconds and 4 git commands to generate.