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.
21 #include <babeltrace/ctf-text/types.h>
25 int ctf_text_enum_write(struct stream_pos
*ppos
, struct definition
*definition
)
27 struct definition_enum
*enum_definition
=
28 container_of(definition
, struct definition_enum
, p
);
29 struct definition_integer
*integer_definition
=
30 enum_definition
->integer
;
31 struct ctf_text_stream_pos
*pos
= ctf_text_pos(ppos
);
36 if (!print_field(definition
))
42 if (pos
->field_nr
++ != 0)
43 fprintf(pos
->fp
, ",");
44 fprintf(pos
->fp
, " ");
46 fprintf(pos
->fp
, "%s = ",
47 g_quark_to_string(definition
->name
));
49 field_nr_saved
= pos
->field_nr
;
51 fprintf(pos
->fp
, "(");
53 qs
= enum_definition
->value
;
56 for (i
= 0; i
< qs
->len
; i
++) {
57 GQuark q
= g_array_index(qs
, GQuark
, i
);
58 const char *str
= g_quark_to_string(q
);
61 if (pos
->field_nr
++ != 0)
62 fprintf(pos
->fp
, ",");
63 fprintf(pos
->fp
, " ");
64 fprintf(pos
->fp
, "%s", str
);
67 fprintf(pos
->fp
, " <unknown>");
71 fprintf(pos
->fp
, " :");
72 ret
= generic_rw(ppos
, &integer_definition
->p
);
75 fprintf(pos
->fp
, " )");
76 pos
->field_nr
= field_nr_saved
;
This page took 0.032579 seconds and 4 git commands to generate.