Commit | Line | Data |
---|---|---|
6dc2ca62 MD |
1 | /* |
2 | * Common Trace Format | |
3 | * | |
4 | * Enumeration mapping strings (quarks) from/to integers. | |
5 | * | |
de0ba614 | 6 | * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
6dc2ca62 | 7 | * |
de0ba614 MD |
8 | * This library is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License as published by the Free Software Foundation; either | |
11 | * version 2.1 of the License, or (at your option) any later version. | |
12 | * | |
13 | * This library is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * Lesser General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU Lesser General Public | |
19 | * License along with this library; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
6dc2ca62 MD |
21 | */ |
22 | ||
d79865b9 | 23 | #include <babeltrace/ctf/types.h> |
6dc2ca62 MD |
24 | #include <stdint.h> |
25 | #include <glib.h> | |
26 | ||
bed864a7 | 27 | GQuark ctf_enum_read(struct stream_pos *pos, |
448d3cc7 MD |
28 | const struct type_class_enum *src) |
29 | { | |
7fe00194 | 30 | struct type_class_integer *int_class = &src->p; |
448d3cc7 MD |
31 | |
32 | if (!int_class->signedness) { | |
33 | uint64_t v; | |
34 | ||
7fe00194 | 35 | v = ctf_uint_read(pos, int_class); |
448d3cc7 MD |
36 | return enum_uint_to_quark(src, v); |
37 | } else { | |
38 | int64_t v; | |
39 | ||
7fe00194 | 40 | v = fsrc->ctf_int_read(pos, int_class); |
448d3cc7 MD |
41 | return enum_int_to_quark(src, v); |
42 | } | |
43 | } | |
44 | ||
bed864a7 MD |
45 | size_t ctf_enum_write(struct stream_pos *pos, |
46 | const struct type_class_enum *dest, | |
448d3cc7 MD |
47 | GQuark q) |
48 | { | |
7fe00194 | 49 | struct type_class_integer *int_class = &dest->p; |
448d3cc7 MD |
50 | |
51 | if (!int_class->signedness) { | |
52 | uint64_t v; | |
53 | ||
54 | v = enum_quark_to_uint(dest, q); | |
7fe00194 | 55 | return ctf_uint_write(pos, int_class, v); |
448d3cc7 MD |
56 | } else { |
57 | int64_t v; | |
58 | ||
59 | v = enum_quark_to_int(dest, q); | |
7fe00194 | 60 | return ctf_int_write(pos, int_class, v); |
448d3cc7 | 61 | } |
6dc2ca62 | 62 | } |