diff mbox

[v3,2/8] QDict: New qdict_get_double()

Message ID 1264425788-8245-3-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster Jan. 25, 2010, 1:23 p.m. UTC
Helper function just like qdict_get_int(), just for QFloat/double.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 qdict.c |   24 ++++++++++++++++++++++++
 qdict.h |    1 +
 2 files changed, 25 insertions(+), 0 deletions(-)

Comments

Anthony Liguori Jan. 26, 2010, 8:58 p.m. UTC | #1
On 01/25/2010 07:23 AM, Markus Armbruster wrote:
> Helper function just like qdict_get_int(), just for QFloat/double.
>
> Signed-off-by: Markus Armbruster<armbru@redhat.com>
>    

Breaks check_qdict's build.  Need to update the Makefile.  You can just 
send a v4 of this patch.

Regards,

Anthony Liguori
diff mbox

Patch

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);