]> Git Repo - qemu.git/blobdiff - qdict.c
QMP: Introduce the qmp_capabilities command
[qemu.git] / qdict.c
diff --git a/qdict.c b/qdict.c
index ef73265f49fc3074812fd1fbcdffadabd86156e2..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"
@@ -122,9 +123,8 @@ void qdict_put_obj(QDict *qdict, const char *key, QObject *value)
         /* allocate a new entry */
         entry = alloc_entry(key, value);
         QLIST_INSERT_HEAD(&qdict->table[hash], entry, next);
+        qdict->size++;
     }
-
-    qdict->size++;
 }
 
 /**
@@ -175,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'
  *
@@ -216,6 +239,19 @@ QList *qdict_get_qlist(const QDict *qdict, const char *key)
     return qobject_to_qlist(qdict_get_obj(qdict, key, QTYPE_QLIST));
 }
 
+/**
+ * qdict_get_qdict(): Get the QDict mapped by 'key'
+ *
+ * This function assumes that 'key' exists and it stores a
+ * QDict object.
+ *
+ * Return QDict mapped by 'key'.
+ */
+QDict *qdict_get_qdict(const QDict *qdict, const char *key)
+{
+    return qobject_to_qdict(qdict_get_obj(qdict, key, QTYPE_QDICT));
+}
+
 /**
  * qdict_get_str(): Get a pointer to the stored string mapped
  * by 'key'
This page took 0.024399 seconds and 4 git commands to generate.