4 * Copyright IBM, Corp. 2009
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10 * See the COPYING.LIB file in the top-level directory.
14 #include "qapi/qmp/qfloat.h"
15 #include "qapi/qmp/qobject.h"
16 #include "qemu-common.h"
18 static void qfloat_destroy_obj(QObject
*obj
);
20 static const QType qfloat_type
= {
22 .destroy
= qfloat_destroy_obj
,
26 * qfloat_from_int(): Create a new QFloat from a float
28 * Return strong reference.
30 QFloat
*qfloat_from_double(double value
)
34 qf
= g_malloc(sizeof(*qf
));
36 QOBJECT_INIT(qf
, &qfloat_type
);
42 * qfloat_get_double(): Get the stored float
44 double qfloat_get_double(const QFloat
*qf
)
50 * qobject_to_qfloat(): Convert a QObject into a QFloat
52 QFloat
*qobject_to_qfloat(const QObject
*obj
)
54 if (!obj
|| qobject_type(obj
) != QTYPE_QFLOAT
) {
57 return container_of(obj
, QFloat
, base
);
61 * qfloat_destroy_obj(): Free all memory allocated by a
64 static void qfloat_destroy_obj(QObject
*obj
)
67 g_free(qobject_to_qfloat(obj
));