]> git.proxmox.com Git - mirror_qemu.git/blame - qobject/qobject.c
Eliminate qapi/qmp/types.h
[mirror_qemu.git] / qobject / qobject.c
CommitLineData
55e1819c
EB
1/*
2 * QObject
3 *
4 * Copyright (C) 2015 Red Hat, Inc.
5 *
6 * This work is licensed under the terms of the GNU LGPL, version 2.1
7 * or later. See the COPYING.LIB file in the top-level directory.
8 */
9
f2ad72b3 10#include "qemu/osdep.h"
55e1819c 11#include "qemu-common.h"
6b673957
MA
12#include "qapi/qmp/qbool.h"
13#include "qapi/qmp/qdict.h"
14#include "qapi/qmp/qstring.h"
55e1819c 15
7264f5c5 16static void (*qdestroy[QTYPE__MAX])(QObject *) = {
55e1819c
EB
17 [QTYPE_NONE] = NULL, /* No such object exists */
18 [QTYPE_QNULL] = NULL, /* qnull_ is indestructible */
01b2ffce 19 [QTYPE_QNUM] = qnum_destroy_obj,
55e1819c
EB
20 [QTYPE_QSTRING] = qstring_destroy_obj,
21 [QTYPE_QDICT] = qdict_destroy_obj,
22 [QTYPE_QLIST] = qlist_destroy_obj,
55e1819c
EB
23 [QTYPE_QBOOL] = qbool_destroy_obj,
24};
25
26void qobject_destroy(QObject *obj)
27{
28 assert(!obj->refcnt);
7264f5c5 29 assert(QTYPE_QNULL < obj->type && obj->type < QTYPE__MAX);
55e1819c
EB
30 qdestroy[obj->type](obj);
31}
b38dd678
HR
32
33
34static bool (*qis_equal[QTYPE__MAX])(const QObject *, const QObject *) = {
35 [QTYPE_NONE] = NULL, /* No such object exists */
36 [QTYPE_QNULL] = qnull_is_equal,
37 [QTYPE_QNUM] = qnum_is_equal,
38 [QTYPE_QSTRING] = qstring_is_equal,
39 [QTYPE_QDICT] = qdict_is_equal,
40 [QTYPE_QLIST] = qlist_is_equal,
41 [QTYPE_QBOOL] = qbool_is_equal,
42};
43
44bool qobject_is_equal(const QObject *x, const QObject *y)
45{
46 /* We cannot test x == y because an object does not need to be
47 * equal to itself (e.g. NaN floats are not). */
48
49 if (!x && !y) {
50 return true;
51 }
52
53 if (!x || !y || x->type != y->type) {
54 return false;
55 }
56
57 assert(QTYPE_NONE < x->type && x->type < QTYPE__MAX);
58
59 return qis_equal[x->type](x, y);
60}