From patchwork Mon Jan 25 13:23:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 43624 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2D177B7C33 for ; Tue, 26 Jan 2010 00:27:14 +1100 (EST) Received: from localhost ([127.0.0.1]:60429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZOy4-0002l1-CD for incoming@patchwork.ozlabs.org; Mon, 25 Jan 2010 08:27:00 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NZOuY-00010r-7k for qemu-devel@nongnu.org; Mon, 25 Jan 2010 08:23:22 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NZOuQ-0000sb-4C for qemu-devel@nongnu.org; Mon, 25 Jan 2010 08:23:19 -0500 Received: from [199.232.76.173] (port=42835 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZOuP-0000s4-Ez for qemu-devel@nongnu.org; Mon, 25 Jan 2010 08:23:13 -0500 Received: from oxygen.pond.sub.org ([213.239.205.148]:60562) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NZOuO-0003TJ-Mf for qemu-devel@nongnu.org; Mon, 25 Jan 2010 08:23:12 -0500 Received: from blackfin.pond.sub.org (pD9E3A875.dip.t-dialin.net [217.227.168.117]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 9CA2C276D6D for ; Mon, 25 Jan 2010 14:22:56 +0100 (CET) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 02D1C428; Mon, 25 Jan 2010 14:23:08 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 25 Jan 2010 14:23:02 +0100 Message-Id: <1264425788-8245-3-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.6.6 In-Reply-To: <1264425788-8245-1-git-send-email-armbru@redhat.com> References: <1264425788-8245-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [Qemu-devel] [PATCH v3 2/8] QDict: New qdict_get_double() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Helper function just like qdict_get_int(), just for QFloat/double. Signed-off-by: Markus Armbruster --- qdict.c | 24 ++++++++++++++++++++++++ qdict.h | 1 + 2 files changed, 25 insertions(+), 0 deletions(-) diff --git a/qdict.c b/qdict.c index ba8eef0..32119cf 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" @@ -175,6 +176,29 @@ static QObject *qdict_get_obj(const QDict *qdict, const char *key, } /** + * 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' * * This function assumes that 'key' exists and it stores a diff --git a/qdict.h b/qdict.h index 5fef1ea..5649ccf 100644 --- a/qdict.h +++ b/qdict.h @@ -37,6 +37,7 @@ void qdict_iter(const QDict *qdict, qdict_put_obj(qdict, key, QOBJECT(obj)) /* High level helpers */ +double qdict_get_double(const QDict *qdict, const char *key); int64_t qdict_get_int(const QDict *qdict, const char *key); int qdict_get_bool(const QDict *qdict, const char *key); QList *qdict_get_qlist(const QDict *qdict, const char *key);