4 * Enumeration mapping strings (quarks) from/to integers.
6 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <babeltrace/ctf/types.h>
34 int ctf_enum_read(struct bt_stream_pos
*ppos
, struct bt_definition
*definition
)
36 struct definition_enum
*enum_definition
=
37 container_of(definition
, struct definition_enum
, p
);
38 const struct declaration_enum
*enum_declaration
=
39 enum_definition
->declaration
;
40 struct definition_integer
*integer_definition
=
41 enum_definition
->integer
;
42 const struct declaration_integer
*integer_declaration
=
43 integer_definition
->declaration
;
47 ret
= ctf_integer_read(ppos
, &integer_definition
->p
);
50 if (!integer_declaration
->signedness
) {
51 qs
= bt_enum_uint_to_quark_set(enum_declaration
,
52 integer_definition
->value
._unsigned
);
54 fprintf(stderr
, "[warning] Unknown value %" PRIu64
" in enum.\n",
55 integer_definition
->value
._unsigned
);
58 qs
= bt_enum_int_to_quark_set(enum_declaration
,
59 integer_definition
->value
._signed
);
61 fprintf(stderr
, "[warning] Unknown value %" PRId64
" in enum.\n",
62 integer_definition
->value
._signed
);
65 /* unref previous quark set */
66 if (enum_definition
->value
)
67 g_array_unref(enum_definition
->value
);
68 enum_definition
->value
= qs
;
72 int ctf_enum_write(struct bt_stream_pos
*pos
, struct bt_definition
*definition
)
74 struct definition_enum
*enum_definition
=
75 container_of(definition
, struct definition_enum
, p
);
76 struct definition_integer
*integer_definition
=
77 enum_definition
->integer
;
79 return ctf_integer_write(pos
, &integer_definition
->p
);
This page took 0.031786 seconds and 4 git commands to generate.