From patchwork Wed Jan 27 16:16:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 43822 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 F3574B80FD for ; Thu, 28 Jan 2010 03:17:24 +1100 (EST) Received: from localhost ([127.0.0.1]:36144 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NaAa1-0008Fj-Gh for incoming@patchwork.ozlabs.org; Wed, 27 Jan 2010 11:17:21 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NaAZT-0008Ef-Gs for qemu-devel@nongnu.org; Wed, 27 Jan 2010 11:16:47 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NaAZP-0008Az-JD for qemu-devel@nongnu.org; Wed, 27 Jan 2010 11:16:47 -0500 Received: from [199.232.76.173] (port=55189 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NaAZP-0008Aq-FT for qemu-devel@nongnu.org; Wed, 27 Jan 2010 11:16:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:31812) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NaAZP-0000Di-3a for qemu-devel@nongnu.org; Wed, 27 Jan 2010 11:16:43 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0RGGeDW012464 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 27 Jan 2010 11:16:41 -0500 Received: from blackfin.pond.sub.org (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0RGGdS4029535; Wed, 27 Jan 2010 11:16:40 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 5A227416; Wed, 27 Jan 2010 17:16:38 +0100 (CET) From: Markus Armbruster To: Anthony Liguori References: <1264425788-8245-1-git-send-email-armbru@redhat.com> <1264425788-8245-3-git-send-email-armbru@redhat.com> <4B5F576F.1060901@codemonkey.ws> Date: Wed, 27 Jan 2010 17:16:38 +0100 In-Reply-To: <4B5F576F.1060901@codemonkey.ws> (Anthony Liguori's message of "Tue, 26 Jan 2010 14:58:23 -0600") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH v4 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 --- Makefile | 2 +- qdict.c | 24 ++++++++++++++++++++++++ qdict.h | 1 + 3 files changed, 26 insertions(+), 1 deletions(-) diff --git a/Makefile b/Makefile index 60d5c66..3f02c66 100644 --- a/Makefile +++ b/Makefile @@ -147,7 +147,7 @@ qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx check-qint: check-qint.o qint.o qemu-malloc.o check-qstring: check-qstring.o qstring.o qemu-malloc.o -check-qdict: check-qdict.o qdict.o qint.o qstring.o qbool.o qemu-malloc.o qlist.o +check-qdict: check-qdict.o qdict.o qfloat.o qint.o qstring.o qbool.o qemu-malloc.o qlist.o check-qlist: check-qlist.o qlist.o qint.o qemu-malloc.o check-qfloat: check-qfloat.o qfloat.o qemu-malloc.o check-qjson: check-qjson.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o qjson.o json-streamer.o json-lexer.o json-parser.o qemu-malloc.o 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);