From acc3b0336c24a0f8c2a9638fb7ae8580484b59ca Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 27 Jan 2010 17:16:38 +0100 Subject: QDict: New qdict_get_double() Helper function just like qdict_get_int(), just for QFloat/double. Signed-off-by: Markus Armbruster Signed-off-by: Anthony Liguori --- qdict.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'qdict.c') diff --git a/qdict.c b/qdict.c index c6a5a425e5..7d1469d408 100644 --- a/qdict.c +++ b/qdict.c @@ -11,6 +11,7 @@ */ #include "qint.h" +#include "qfloat.h" #include "qdict.h" #include "qbool.h" #include "qstring.h" @@ -174,6 +175,29 @@ static QObject *qdict_get_obj(const QDict *qdict, const char *key, return obj; } +/** + * qdict_get_double(): Get an number mapped by 'key' + * + * This function assumes that 'key' exists and it stores a + * QFloat or QInt object. + * + * Return number mapped by 'key'. + */ +double qdict_get_double(const QDict *qdict, const char *key) +{ + QObject *obj = qdict_get(qdict, key); + + assert(obj); + switch (qobject_type(obj)) { + case QTYPE_QFLOAT: + return qfloat_get_double(qobject_to_qfloat(obj)); + case QTYPE_QINT: + return qint_get_int(qobject_to_qint(obj)); + default: + assert(0); + } +} + /** * qdict_get_int(): Get an integer mapped by 'key' * -- cgit v1.2.3