4 * BabelTrace - Float 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/types.h>
22 void float_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_float
*float_class
=
27 container_of(type_class
, struct type_class_float
, p
);
29 if (fsrc
->float_copy
== fdest
->float_copy
) {
30 fsrc
->float_copy(dest
, src
, float_class
);
34 v
= fsrc
->double_read(src
, float_class
);
35 fdest
->double_write(dest
, float_class
, v
);
39 void float_type_free(struct type_class_float
*float_class
)
41 integer_type_free(float_class
->exp
);
42 integer_type_free(float_class
->mantissa
);
43 integer_type_free(float_class
->sign
);
47 static void _float_type_free(struct type_class
*type_class
)
49 struct type_class_float
*float_class
=
50 container_of(type_class
, struct type_class_float
, p
);
51 float_type_free(float_class
);
54 struct type_class_float
*float_type_new(const char *name
,
56 size_t exp_len
, int byte_order
,
59 struct type_class_float
*float_class
;
60 struct type_class_integer
*int_class
;
61 struct type_class
*type_class
;
64 float_class
= g_new(struct type_class_float
, 1);
65 type_class
= &float_class
->p
;
67 type_class
->name
= g_quark_from_string(name
);
68 type_class
->alignment
= alignment
;
69 type_class
->copy
= float_copy
;
70 type_class
->free
= _float_type_free
;
71 float_class
->byte_order
= byte_order
;
73 float_class
->sign
= integer_type_new(NULL
, 1,
74 byte_order
, false, 1);
75 if (!float_class
->mantissa
)
77 float_class
->mantissa
= integer_type_new(NULL
, mantissa_len
- 1,
78 byte_order
, false, 1);
79 if (!float_class
->mantissa
)
81 float_class
->exp
= integer_type_new(NULL
, exp_len
,
83 if (!float_class
->exp
)
86 if (float_class
->p
.name
) {
87 ret
= ctf_register_type(&float_class
->p
);
94 integer_type_free(float_class
->exp
);
96 integer_type_free(float_class
->mantissa
);
98 integer_type_free(float_class
->sign
);
This page took 0.03203 seconds and 5 git commands to generate.