c2b50fd532f1b3736a360f1e4bdab5e9cf80c66f
[babeltrace.git] / formats / ctf / types / enum.c
1 /*
2 * Common Trace Format
3 *
4 * Enumeration mapping strings (quarks) from/to integers.
5 *
6 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
7 *
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 */
20
21 #include <babeltrace/ctf/types.h>
22 #include <stdint.h>
23 #include <glib.h>
24
25 int ctf_enum_read(struct stream_pos *ppos, struct definition *definition)
26 {
27 struct definition_enum *enum_definition =
28 container_of(definition, struct definition_enum, p);
29 const struct declaration_enum *enum_declaration =
30 enum_definition->declaration;
31 struct definition_integer *integer_definition =
32 enum_definition->integer;
33 const struct declaration_integer *integer_declaration =
34 integer_definition->declaration;
35 GArray *qs;
36 int ret;
37
38 ret = ctf_integer_read(ppos, &integer_definition->p);
39 if (ret)
40 return ret;
41 if (!integer_declaration->signedness)
42 qs = enum_uint_to_quark_set(enum_declaration,
43 integer_definition->value._unsigned);
44 else
45 qs = enum_int_to_quark_set(enum_declaration,
46 integer_definition->value._signed);
47 assert(qs);
48 /* unref previous quark set */
49 if (enum_definition->value)
50 g_array_unref(enum_definition->value);
51 enum_definition->value = qs;
52 return 0;
53 }
54
55 int ctf_enum_write(struct stream_pos *pos, struct definition *definition)
56 {
57 struct definition_enum *enum_definition =
58 container_of(definition, struct definition_enum, p);
59 struct definition_integer *integer_definition =
60 enum_definition->integer;
61
62 return ctf_integer_write(pos, &integer_definition->p);
63 }
This page took 0.044809 seconds and 3 git commands to generate.