Relicense BabelTrace library to MIT (BSD-style)
[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
bed864a7 23GQuark ctf_enum_read(struct stream_pos *pos,
448d3cc7
MD
24 const struct type_class_enum *src)
25{
7fe00194 26 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);
448d3cc7
MD
32 return enum_uint_to_quark(src, v);
33 } else {
34 int64_t v;
35
7fe00194 36 v = fsrc->ctf_int_read(pos, int_class);
448d3cc7
MD
37 return enum_int_to_quark(src, v);
38 }
39}
40
bed864a7
MD
41size_t ctf_enum_write(struct stream_pos *pos,
42 const struct type_class_enum *dest,
448d3cc7
MD
43 GQuark q)
44{
7fe00194 45 struct type_class_integer *int_class = &dest->p;
448d3cc7
MD
46
47 if (!int_class->signedness) {
48 uint64_t v;
49
50 v = enum_quark_to_uint(dest, q);
7fe00194 51 return ctf_uint_write(pos, int_class, v);
448d3cc7
MD
52 } else {
53 int64_t v;
54
55 v = enum_quark_to_int(dest, q);
7fe00194 56 return ctf_int_write(pos, int_class, v);
448d3cc7 57 }
6dc2ca62 58}
This page took 0.03495 seconds and 4 git commands to generate.