4 * BabelTrace - Array Type Converter
6 * Copyright 2010 - 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>
22 void array_copy(struct stream_pos
*dest
, const struct format
*fdest
,
23 struct stream_pos
*src
, const struct format
*fsrc
,
24 const struct type_class
*type_class
)
26 struct type_class_array
*array_class
=
27 container_of(type_class
, struct type_class_array
, p
);
30 fsrc
->array_begin(src
, array_class
);
31 fdest
->array_begin(dest
, array_class
);
33 for (i
= 0; i
< array_class
->len
; i
++) {
34 struct type_class
*elem_class
= array_class
->elem
;
35 elem_class
->copy(dest
, fdest
, src
, fsrc
, elem_class
);
37 fsrc
->array_end(src
, array_class
);
38 fdest
->array_end(dest
, array_class
);
41 void array_type_free(struct type_class_array
*array_class
)
43 type_unref(array_class
->elem
);
47 static void _array_type_free(struct type_class
*type_class
)
49 struct type_class_array
*array_class
=
50 container_of(type_class
, struct type_class_array
, p
);
51 array_type_free(array_class
);
54 struct type_class_array
*array_type_new(const char *name
, size_t len
,
55 struct type_class
*elem
)
57 struct type_class_array
*array_class
;
58 struct type_class
*type_class
;
61 array_class
= g_new(struct type_class_array
, 1);
62 type_class
= &array_class
->p
;
64 array_class
->len
= len
;
66 array_class
->elem
= elem
;
67 type_class
->name
= g_quark_from_string(name
);
68 /* No need to align the array, the first element will align itself */
69 type_class
->alignment
= 1;
70 type_class
->copy
= array_copy
;
71 type_class
->free
= _array_type_free
;
74 if (type_class
->name
) {
75 ret
= ctf_register_type(type_class
);
82 type_unref(array_class
->elem
);
This page took 0.031349 seconds and 4 git commands to generate.