4 * BabelTrace - Integer Type Converter
6 * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
19 #include <babeltrace/compiler.h>
20 #include <babeltrace/align.h>
21 #include <babeltrace/format.h>
25 struct definition
*_integer_definition_new(struct declaration
*declaration
,
26 struct definition_scope
*parent_scope
);
28 void _integer_definition_free(struct definition
*definition
);
30 void integer_copy(struct stream_pos
*dest
, const struct format
*fdest
,
31 struct stream_pos
*src
, const struct format
*fsrc
,
32 struct definition
*definition
)
34 struct definition_integer
*integer
=
35 container_of(definition
, struct definition_integer
, p
);
36 struct declaration_integer
*integer_declaration
= integer
->declaration
;
38 if (!integer_declaration
->signedness
) {
41 v
= fsrc
->uint_read(src
, integer_declaration
);
42 fdest
->uint_write(dest
, integer_declaration
, v
);
46 v
= fsrc
->int_read(src
, integer_declaration
);
47 fdest
->int_write(dest
, integer_declaration
, v
);
52 void _integer_declaration_free(struct declaration
*declaration
)
54 struct declaration_integer
*integer_declaration
=
55 container_of(declaration
, struct declaration_integer
, p
);
56 g_free(integer_declaration
);
59 struct declaration_integer
*
60 integer_declaration_new(const char *name
, size_t len
, int byte_order
,
61 int signedness
, size_t alignment
)
63 struct declaration_integer
*integer_declaration
;
65 integer_declaration
= g_new(struct declaration_integer
, 1);
66 integer_declaration
->p
.id
= CTF_TYPE_INTEGER
;
67 integer_declaration
->p
.name
= g_quark_from_string(name
);
68 integer_declaration
->p
.alignment
= alignment
;
69 integer_declaration
->p
.copy
= integer_copy
;
70 integer_declaration
->p
.declaration_free
= _integer_declaration_free
;
71 integer_declaration
->p
.definition_free
= _integer_definition_free
;
72 integer_declaration
->p
.definition_new
= _integer_definition_new
;
73 integer_declaration
->p
.ref
= 1;
74 integer_declaration
->len
= len
;
75 integer_declaration
->byte_order
= byte_order
;
76 integer_declaration
->signedness
= signedness
;
77 return integer_declaration
;
82 _integer_definition_new(struct declaration
*declaration
,
83 struct definition_scope
*parent_scope
)
85 struct declaration_integer
*integer_declaration
=
86 container_of(declaration
, struct declaration_integer
, p
);
87 struct definition_integer
*integer
;
89 integer
= g_new(struct definition_integer
, 1);
90 declaration_ref(&integer_declaration
->p
);
91 integer
->p
.declaration
= declaration
;
92 integer
->declaration
= integer_declaration
;
94 integer
->value
._unsigned
= 0;
99 void _integer_definition_free(struct definition
*definition
)
101 struct definition_integer
*integer
=
102 container_of(definition
, struct definition_integer
, p
);
104 declaration_unref(integer
->p
.declaration
);