Revision ec072ced

b/Makefile
137 137
obj-y += qemu-char.o aio.o savevm.o
138 138
obj-y += msmouse.o ps2.o
139 139
obj-y += qdev.o qdev-properties.o
140
obj-y += qint.o qstring.o qdict.o qlist.o qemu-config.o
141
obj-y += block-migration.o
140
obj-y += qint.o qstring.o qdict.o qlist.o qfloat.o
141
obj-y += qemu-config.o block-migration.o
142 142

  
143 143
obj-$(CONFIG_BRLAPI) += baum.o
144 144
obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
b/qfloat.c
1
/*
2
 * QFloat Module
3
 *
4
 * Copyright (C) 2009 Red Hat Inc.
5
 *
6
 * Authors:
7
 *  Luiz Capitulino <lcapitulino@redhat.com>
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   <aliguori@us.ibm.com>
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
}
b/qfloat.h
1
/*
2
 * QFloat Module
3
 *
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

  
14
#ifndef QFLOAT_H
15
#define QFLOAT_H
16

  
17
#include <stdint.h>
18
#include "qobject.h"
19

  
20
typedef struct QFloat {
21
    QObject_HEAD;
22
    double value;
23
} QFloat;
24

  
25
QFloat *qfloat_from_double(double value);
26
double qfloat_get_double(const QFloat *qi);
27
QFloat *qobject_to_qfloat(const QObject *obj);
28

  
29
#endif /* QFLOAT_H */
b/qobject.h
41 41
    QTYPE_QSTRING,
42 42
    QTYPE_QDICT,
43 43
    QTYPE_QLIST,
44
    QTYPE_QFLOAT,
44 45
} qtype_code;
45 46

  
46 47
struct QObject;

Also available in: Unified diff