]> git.proxmox.com Git - mirror_qemu.git/blame - qobject/qfloat.c
Merge remote-tracking branch 'remotes/ehabkost/tags/x86-pull-request' into staging
[mirror_qemu.git] / qobject / qfloat.c
CommitLineData
ec072ced
AL
1/*
2 * QFloat Module
3 *
ec072ced
AL
4 * Copyright IBM, Corp. 2009
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
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
f2ad72b3 14#include "qemu/osdep.h"
7b1b5d19
PB
15#include "qapi/qmp/qfloat.h"
16#include "qapi/qmp/qobject.h"
ec072ced
AL
17#include "qemu-common.h"
18
ec072ced
AL
19/**
20 * qfloat_from_int(): Create a new QFloat from a float
21 *
22 * Return strong reference.
23 */
24QFloat *qfloat_from_double(double value)
25{
26 QFloat *qf;
27
7267c094 28 qf = g_malloc(sizeof(*qf));
55e1819c 29 qobject_init(QOBJECT(qf), QTYPE_QFLOAT);
ec072ced 30 qf->value = value;
ec072ced
AL
31
32 return qf;
33}
34
35/**
36 * qfloat_get_double(): Get the stored float
37 */
38double qfloat_get_double(const QFloat *qf)
39{
40 return qf->value;
41}
42
43/**
44 * qobject_to_qfloat(): Convert a QObject into a QFloat
45 */
46QFloat *qobject_to_qfloat(const QObject *obj)
47{
fcf73f66 48 if (!obj || qobject_type(obj) != QTYPE_QFLOAT) {
ec072ced 49 return NULL;
fcf73f66 50 }
ec072ced
AL
51 return container_of(obj, QFloat, base);
52}
53
54/**
55 * qfloat_destroy_obj(): Free all memory allocated by a
56 * QFloat object
57 */
55e1819c 58void qfloat_destroy_obj(QObject *obj)
ec072ced
AL
59{
60 assert(obj != NULL);
7267c094 61 g_free(qobject_to_qfloat(obj));
ec072ced 62}