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