]> Git Repo - qemu.git/blame - qobject/qfloat.c
exec.c: Use correct AddressSpace in watch_mem_read and watch_mem_write
[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 <[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
7b1b5d19
PB
14#include "qapi/qmp/qfloat.h"
15#include "qapi/qmp/qobject.h"
ec072ced
AL
16#include "qemu-common.h"
17
ec072ced
AL
18/**
19 * qfloat_from_int(): Create a new QFloat from a float
20 *
21 * Return strong reference.
22 */
23QFloat *qfloat_from_double(double value)
24{
25 QFloat *qf;
26
7267c094 27 qf = g_malloc(sizeof(*qf));
55e1819c 28 qobject_init(QOBJECT(qf), QTYPE_QFLOAT);
ec072ced 29 qf->value = value;
ec072ced
AL
30
31 return qf;
32}
33
34/**
35 * qfloat_get_double(): Get the stored float
36 */
37double 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 */
45QFloat *qobject_to_qfloat(const QObject *obj)
46{
fcf73f66 47 if (!obj || qobject_type(obj) != QTYPE_QFLOAT) {
ec072ced 48 return NULL;
fcf73f66 49 }
ec072ced
AL
50 return container_of(obj, QFloat, base);
51}
52
53/**
54 * qfloat_destroy_obj(): Free all memory allocated by a
55 * QFloat object
56 */
55e1819c 57void qfloat_destroy_obj(QObject *obj)
ec072ced
AL
58{
59 assert(obj != NULL);
7267c094 60 g_free(qobject_to_qfloat(obj));
ec072ced 61}
This page took 0.539606 seconds and 4 git commands to generate.