From cd4dde36ae8e7bd8e02839533c5708011bf994cf Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Thu, 10 Dec 2009 17:15:53 -0200 Subject: QDict: Introduce qdict_get_qbool() This is a helper function that does type checking before retrieving a QBool from the dictionary. Signed-off-by: Luiz Capitulino Signed-off-by: Anthony Liguori --- qdict.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'qdict.c') diff --git a/qdict.c b/qdict.c index 0e04cb1fed..45e08bec98 100644 --- a/qdict.c +++ b/qdict.c @@ -12,6 +12,7 @@ #include "qint.h" #include "qdict.h" +#include "qbool.h" #include "qstring.h" #include "qobject.h" #include "qemu-queue.h" @@ -188,6 +189,20 @@ int64_t qdict_get_int(const QDict *qdict, const char *key) return qint_get_int(qobject_to_qint(obj)); } +/** + * qdict_get_bool(): Get a bool mapped by 'key' + * + * This function assumes that 'key' exists and it stores a + * QBool object. + * + * Return bool mapped by 'key'. + */ +int qdict_get_bool(const QDict *qdict, const char *key) +{ + QObject *obj = qdict_get_obj(qdict, key, QTYPE_QBOOL); + return qbool_get_int(qobject_to_qbool(obj)); +} + /** * qdict_get_str(): Get a pointer to the stored string mapped * by 'key' -- cgit v1.2.3