]> Git Repo - qemu.git/blob - qfloat.c
savevm.c: fix warning with _FORTIFY_SOURCE
[qemu.git] / qfloat.c
1 /*
2  * QFloat Module
3  *
4  * Copyright (C) 2009 Red Hat Inc.
5  *
6  * Authors:
7  *  Luiz Capitulino <[email protected]>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  *
12  * Copyright IBM, Corp. 2009
13  *
14  * Authors:
15  *  Anthony Liguori   <[email protected]>
16  *
17  * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
18  * See the COPYING.LIB file in the top-level directory.
19  *
20  */
21
22 #include "qfloat.h"
23 #include "qobject.h"
24 #include "qemu-common.h"
25
26 static void qfloat_destroy_obj(QObject *obj);
27
28 static const QType qfloat_type = {
29     .code = QTYPE_QFLOAT,
30     .destroy = qfloat_destroy_obj,
31 };
32
33 /**
34  * qfloat_from_int(): Create a new QFloat from a float
35  *
36  * Return strong reference.
37  */
38 QFloat *qfloat_from_double(double value)
39 {
40     QFloat *qf;
41
42     qf = qemu_malloc(sizeof(*qf));
43     qf->value = value;
44     QOBJECT_INIT(qf, &qfloat_type);
45
46     return qf;
47 }
48
49 /**
50  * qfloat_get_double(): Get the stored float
51  */
52 double qfloat_get_double(const QFloat *qf)
53 {
54     return qf->value;
55 }
56
57 /**
58  * qobject_to_qfloat(): Convert a QObject into a QFloat
59  */
60 QFloat *qobject_to_qfloat(const QObject *obj)
61 {
62     if (qobject_type(obj) != QTYPE_QFLOAT)
63         return NULL;
64
65     return container_of(obj, QFloat, base);
66 }
67
68 /**
69  * qfloat_destroy_obj(): Free all memory allocated by a
70  * QFloat object
71  */
72 static void qfloat_destroy_obj(QObject *obj)
73 {
74     assert(obj != NULL);
75     qemu_free(qobject_to_qfloat(obj));
76 }
This page took 0.026801 seconds and 4 git commands to generate.