libqos: drop duplicated virtio_scsi.h definitions
[qemu.git] / qobject / qfloat.c
blobd5da847701d269d2922f3aae23e62e911ed667ca
1 /*
2 * QFloat Module
4 * Copyright IBM, Corp. 2009
6 * Authors:
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 "qemu/osdep.h"
15 #include "qapi/qmp/qfloat.h"
16 #include "qapi/qmp/qobject.h"
17 #include "qemu-common.h"
19 /**
20 * qfloat_from_int(): Create a new QFloat from a float
22 * Return strong reference.
24 QFloat *qfloat_from_double(double value)
26 QFloat *qf;
28 qf = g_malloc(sizeof(*qf));
29 qobject_init(QOBJECT(qf), QTYPE_QFLOAT);
30 qf->value = value;
32 return qf;
35 /**
36 * qfloat_get_double(): Get the stored float
38 double qfloat_get_double(const QFloat *qf)
40 return qf->value;
43 /**
44 * qobject_to_qfloat(): Convert a QObject into a QFloat
46 QFloat *qobject_to_qfloat(const QObject *obj)
48 if (!obj || qobject_type(obj) != QTYPE_QFLOAT) {
49 return NULL;
51 return container_of(obj, QFloat, base);
54 /**
55 * qfloat_destroy_obj(): Free all memory allocated by a
56 * QFloat object
58 void qfloat_destroy_obj(QObject *obj)
60 assert(obj != NULL);
61 g_free(qobject_to_qfloat(obj));