]> Git Repo - qemu.git/commitdiff
QDict: New qdict_get_double()
authorMarkus Armbruster <[email protected]>
Wed, 27 Jan 2010 16:16:38 +0000 (17:16 +0100)
committerAnthony Liguori <[email protected]>
Wed, 3 Feb 2010 18:36:25 +0000 (12:36 -0600)
Helper function just like qdict_get_int(), just for QFloat/double.

Signed-off-by: Markus Armbruster <[email protected]>
Signed-off-by: Anthony Liguori <[email protected]>
Makefile
qdict.c
qdict.h

index 38486271c23ce6a77dd7a50452c7d5c5e6a46eb3..24938db916dacc4ff6eaf92ce08627a83b96bd91 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -140,7 +140,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 c6a5a425e5ccaa56b4e331f24f945ab8a5a804d3..7d1469d40855e07601e619814f10ae96deacefff 100644 (file)
--- 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'
  *
diff --git a/qdict.h b/qdict.h
index 2eaf6d54d30a5914d8c3ea741c1ab99b0c2ab24a..579dcddc74dbb7745dd381916fc48e4f455f06bc 100644 (file)
--- 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);
This page took 0.024449 seconds and 4 git commands to generate.