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

login
register
mail settings
Submitter Markus Armbruster
Date Jan. 20, 2010, 4:08 p.m.
Message ID <1264003702-17329-3-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/43305/
State New
Headers show

Comments

Markus Armbruster - Jan. 20, 2010, 4:08 p.m.
Helper function just like qdict_get_int(), just for QFloat/double.

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

Patch

diff --git a/qdict.c b/qdict.c
index ba8eef0..de278b1 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,20 @@  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 object.
+ *
+ * Return number mapped by 'key'.
+ */
+double qdict_get_double(const QDict *qdict, const char *key)
+{
+    QObject *obj = qdict_get_obj(qdict, key, QTYPE_QFLOAT);
+    return qfloat_get_double(qobject_to_qfloat(obj));
+}
+
+/**
  * 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);