]> Git Repo - qemu.git/blob - qobject/qfloat.c
qobject: Simplify QObject
[qemu.git] / qobject / qfloat.c
1 /*
2  * QFloat Module
3  *
4  * Copyright IBM, Corp. 2009
5  *
6  * Authors:
7  *  Anthony Liguori   <[email protected]>
8  *
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.
11  *
12  */
13
14 #include "qapi/qmp/qfloat.h"
15 #include "qapi/qmp/qobject.h"
16 #include "qemu-common.h"
17
18 /**
19  * qfloat_from_int(): Create a new QFloat from a float
20  *
21  * Return strong reference.
22  */
23 QFloat *qfloat_from_double(double value)
24 {
25     QFloat *qf;
26
27     qf = g_malloc(sizeof(*qf));
28     qobject_init(QOBJECT(qf), QTYPE_QFLOAT);
29     qf->value = value;
30
31     return qf;
32 }
33
34 /**
35  * qfloat_get_double(): Get the stored float
36  */
37 double qfloat_get_double(const QFloat *qf)
38 {
39     return qf->value;
40 }
41
42 /**
43  * qobject_to_qfloat(): Convert a QObject into a QFloat
44  */
45 QFloat *qobject_to_qfloat(const QObject *obj)
46 {
47     if (!obj || qobject_type(obj) != QTYPE_QFLOAT) {
48         return NULL;
49     }
50     return container_of(obj, QFloat, base);
51 }
52
53 /**
54  * qfloat_destroy_obj(): Free all memory allocated by a
55  * QFloat object
56  */
57 void qfloat_destroy_obj(QObject *obj)
58 {
59     assert(obj != NULL);
60     g_free(qobject_to_qfloat(obj));
61 }
This page took 0.027567 seconds and 4 git commands to generate.