]>
Commit | Line | Data |
---|---|---|
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 | 12 | #include "qapi/qmp/qbool.h" |
15280c36 MA |
13 | #include "qapi/qmp/qnull.h" |
14 | #include "qapi/qmp/qnum.h" | |
6b673957 | 15 | #include "qapi/qmp/qdict.h" |
47e6b297 | 16 | #include "qapi/qmp/qlist.h" |
6b673957 | 17 | #include "qapi/qmp/qstring.h" |
55e1819c | 18 | |
7264f5c5 | 19 | static void (*qdestroy[QTYPE__MAX])(QObject *) = { |
55e1819c EB |
20 | [QTYPE_NONE] = NULL, /* No such object exists */ |
21 | [QTYPE_QNULL] = NULL, /* qnull_ is indestructible */ | |
01b2ffce | 22 | [QTYPE_QNUM] = qnum_destroy_obj, |
55e1819c EB |
23 | [QTYPE_QSTRING] = qstring_destroy_obj, |
24 | [QTYPE_QDICT] = qdict_destroy_obj, | |
25 | [QTYPE_QLIST] = qlist_destroy_obj, | |
55e1819c EB |
26 | [QTYPE_QBOOL] = qbool_destroy_obj, |
27 | }; | |
28 | ||
29 | void qobject_destroy(QObject *obj) | |
30 | { | |
31 | assert(!obj->refcnt); | |
7264f5c5 | 32 | assert(QTYPE_QNULL < obj->type && obj->type < QTYPE__MAX); |
55e1819c EB |
33 | qdestroy[obj->type](obj); |
34 | } | |
b38dd678 HR |
35 | |
36 | ||
37 | static bool (*qis_equal[QTYPE__MAX])(const QObject *, const QObject *) = { | |
38 | [QTYPE_NONE] = NULL, /* No such object exists */ | |
39 | [QTYPE_QNULL] = qnull_is_equal, | |
40 | [QTYPE_QNUM] = qnum_is_equal, | |
41 | [QTYPE_QSTRING] = qstring_is_equal, | |
42 | [QTYPE_QDICT] = qdict_is_equal, | |
43 | [QTYPE_QLIST] = qlist_is_equal, | |
44 | [QTYPE_QBOOL] = qbool_is_equal, | |
45 | }; | |
46 | ||
47 | bool qobject_is_equal(const QObject *x, const QObject *y) | |
48 | { | |
49 | /* We cannot test x == y because an object does not need to be | |
50 | * equal to itself (e.g. NaN floats are not). */ | |
51 | ||
52 | if (!x && !y) { | |
53 | return true; | |
54 | } | |
55 | ||
56 | if (!x || !y || x->type != y->type) { | |
57 | return false; | |
58 | } | |
59 | ||
60 | assert(QTYPE_NONE < x->type && x->type < QTYPE__MAX); | |
61 | ||
62 | return qis_equal[x->type](x, y); | |
63 | } |