4 * BabelTrace - Array 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/format.h>
23 struct type
*_array_type_new(struct type_class
*type_class
,
24 struct declaration_scope
*parent_scope
);
26 void _array_type_free(struct type
*type
);
28 void array_copy(struct stream_pos
*dest
, const struct format
*fdest
,
29 struct stream_pos
*src
, const struct format
*fsrc
,
32 struct type_sequence
*array
= container_of(type
, struct type_array
, p
);
33 struct type_class_array
*array_class
= array
->_class
;
36 fsrc
->array_begin(src
, array_class
);
37 fdest
->array_begin(dest
, array_class
);
39 for (i
= 0; i
< array_class
->len
; i
++) {
40 struct type_class
*elem_class
= array
->current_element
.type
;
41 elem_type
->p
._class
->copy(dest
, fdest
, src
, fsrc
, elem_type
);
43 fsrc
->array_end(src
, array_class
);
44 fdest
->array_end(dest
, array_class
);
48 void _array_type_class_free(struct type_class
*type_class
)
50 struct type_class_array
*array_class
=
51 container_of(type_class
, struct type_class_array
, p
);
53 type_class_unref(array_class
->elem
);
57 struct type_class_array
*
58 array_type_class_new(const char *name
, size_t len
, struct type_class
*elem
)
60 struct type_class_array
*array_class
;
61 struct type_class
*type_class
;
64 array_class
= g_new(struct type_class_array
, 1);
65 type_class
= &array_class
->p
;
66 array_class
->len
= len
;
68 array_class
->elem
= elem
;
69 type_class
->name
= g_quark_from_string(name
);
70 /* No need to align the array, the first element will align itself */
71 type_class
->alignment
= 1;
72 type_class
->copy
= array_copy
;
73 type_class
->class_free
= _array_type_class_free
;
74 type_class
->type_new
= _array_type_new
;
75 type_class
->type_free
= _array_type_free
;
78 if (type_class
->name
) {
79 ret
= register_type(type_class
);
86 type_class_unref(array_class
->elem
);
92 struct type_array
*_array_type_new(struct type_class
*type_class
,
93 struct declaration_scope
*parent_scope
)
95 struct type_class_array
*array_class
=
96 container_of(type_class
, struct type_class_array
, p
);
97 struct type_array
*array
;
99 array
= g_new(struct type_array
, 1);
100 type_class_ref(&array_class
->p
);
101 array
->p
._class
= array_class
;
103 array
->scope
= new_declaration_scope(parent_scope
);
104 array
->current_element
.type
=
105 array_class
->elem
.p
->type_new(&array_class
->elem
.p
,
111 void _array_type_free(struct type
*type
)
113 struct type_array
*array
=
114 container_of(type
, struct type_array
, p
);
115 struct type
*elem_type
= array
->current_element
.type
;
117 elem_type
->p
._class
->type_free(elem_type
);
118 free_declaration_scope(array
->scope
);
119 type_class_unref(array
->p
._class
);
This page took 0.037268 seconds and 4 git commands to generate.