]> git.proxmox.com Git - qemu.git/blame - qint.c
Bring pcbios, seabios, and vgabios into the tree as git submodules. Right now,
[qemu.git] / qint.c
CommitLineData
6b8d1ece
LC
1/*
2 * QInt data type.
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#include "qint.h"
13#include "qobject.h"
14#include "qemu-common.h"
15
16static const QType qint_type;
17
18/**
19 * qint_from_int(): Create a new QInt from an int64_t
20 *
21 * Return strong reference.
22 */
23QInt *qint_from_int(int64_t value)
24{
25 QInt *qi;
26
27 qi = qemu_malloc(sizeof(*qi));
28 qi->value = value;
29 QOBJECT_INIT(qi, &qint_type);
30
31 return qi;
32}
33
34/**
35 * qint_get_int(): Get the stored integer
36 */
37int64_t qint_get_int(const QInt *qi)
38{
39 return qi->value;
40}
41
42/**
43 * qobject_to_qint(): Convert a QObject into a QInt
44 */
45QInt *qobject_to_qint(const QObject *obj)
46{
47 if (qobject_type(obj) != QTYPE_QINT)
48 return NULL;
49
50 return container_of(obj, QInt, base);
51}
52
53/**
54 * qint_destroy_obj(): Free all memory allocated by a
55 * QInt object
56 */
57static void qint_destroy_obj(QObject *obj)
58{
59 assert(obj != NULL);
60 qemu_free(qobject_to_qint(obj));
61}
62
63static const QType qint_type = {
64 .code = QTYPE_QINT,
65 .destroy = qint_destroy_obj,
66};