From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, armbru@redhat.com, stefanha@redhat.com,
lcapitulino@redhat.com
Subject: [Qemu-devel] [RFC PATCH 09/11] Implement qdict_flatten()
Date: Tue, 9 Jul 2013 11:53:35 +0200 [thread overview]
Message-ID: <1373363617-4723-10-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1373363617-4723-1-git-send-email-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/qapi/qmp/qdict.h | 1 +
qobject/qdict.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+)
diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h
index 685b2e3..b261570 100644
--- a/include/qapi/qmp/qdict.h
+++ b/include/qapi/qmp/qdict.h
@@ -65,5 +65,6 @@ int qdict_get_try_bool(const QDict *qdict, const char *key, int def_value);
const char *qdict_get_try_str(const QDict *qdict, const char *key);
QDict *qdict_clone_shallow(const QDict *src);
+void qdict_flatten(QObject *obj);
#endif /* QDICT_H */
diff --git a/qobject/qdict.c b/qobject/qdict.c
index ed381f9..1c38943 100644
--- a/qobject/qdict.c
+++ b/qobject/qdict.c
@@ -476,3 +476,50 @@ static void qdict_destroy_obj(QObject *obj)
g_free(qdict);
}
+
+static void qdict_do_flatten(QDict *qdict, QDict *target, const char *prefix)
+{
+ QObject *value;
+ const QDictEntry *entry, *next;
+ const char *new_key;
+ bool delete;
+
+ entry = qdict_first(qdict);
+
+ while (entry != NULL) {
+
+ next = qdict_next(qdict, entry);
+ value = qdict_entry_value(entry);
+ new_key = NULL;
+ delete = false;
+
+ if (prefix) {
+ qobject_incref(value);
+ new_key = g_strdup_printf("%s.%s", prefix, entry->key);
+ qdict_put_obj(target, new_key, value);
+ delete = true;
+ }
+
+ if (qobject_type(value) == QTYPE_QDICT) {
+ qdict_do_flatten(qobject_to_qdict(value), target,
+ new_key ? new_key : entry->key);
+ delete = true;
+ }
+
+ if (delete) {
+ qdict_del(qdict, entry->key);
+ }
+
+ entry = next;
+ }
+}
+
+/**
+ * qdict_flatten(): For each nested QDict with key x, all fields with key y
+ * are moved to this QDict and their key is renamed to "x.y".
+ */
+void qdict_flatten(QObject *obj)
+{
+ QDict *qdict = qobject_to_qdict(obj);
+ qdict_do_flatten(qdict, qdict, NULL);
+}
--
1.8.1.4
next prev parent reply other threads:[~2013-07-09 9:54 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-09 9:53 [Qemu-devel] [RFC PATCH 00/11] qapi changes in preparation for blockdev-add Kevin Wolf
2013-07-09 9:53 ` [Qemu-devel] [RFC PATCH 01/11] qapi-types.py: Split off generate_struct_fields() Kevin Wolf
2013-07-11 11:45 ` Eric Blake
2013-07-09 9:53 ` [Qemu-devel] [RFC PATCH 02/11] qapi-types.py: Implement 'base' for unions Kevin Wolf
2013-07-11 11:57 ` Eric Blake
2013-07-11 12:46 ` Eric Blake
2013-07-09 9:53 ` [Qemu-devel] [RFC PATCH 03/11] qapi-visit.py: Split off generate_visit_struct_fields() Kevin Wolf
2013-07-11 12:18 ` Eric Blake
2013-07-09 9:53 ` [Qemu-devel] [RFC PATCH 04/11] qapi-visit.py: Implement 'base' for unions Kevin Wolf
2013-07-11 12:21 ` Eric Blake
2013-07-09 9:53 ` [Qemu-devel] [RFC PATCH 05/11] qapi: Add visitor for implicit structs Kevin Wolf
2013-07-11 12:41 ` Eric Blake
2013-07-11 12:51 ` Eric Blake
2013-07-09 9:53 ` [Qemu-devel] [RFC PATCH 06/11] qapi: Flat unions with arbitrary discriminator Kevin Wolf
2013-07-11 14:16 ` Eric Blake
2013-07-09 9:53 ` [Qemu-devel] [RFC PATCH 07/11] qapi: Add consume argument to qmp_input_get_object() Kevin Wolf
2013-07-11 19:17 ` Eric Blake
2013-07-09 9:53 ` [Qemu-devel] [RFC PATCH 08/11] qapi: Anonymous unions Kevin Wolf
2013-07-11 19:47 ` Eric Blake
2013-07-12 8:55 ` Kevin Wolf
2013-07-12 14:15 ` Eric Blake
2013-07-09 9:53 ` Kevin Wolf [this message]
2013-07-11 20:25 ` [Qemu-devel] [RFC PATCH 09/11] Implement qdict_flatten() Eric Blake
2013-07-16 8:59 ` Kevin Wolf
2013-07-09 9:53 ` [Qemu-devel] [RFC PATCH 10/11] block: Allow "driver" option on the top level Kevin Wolf
2013-07-11 22:30 ` Eric Blake
2013-07-09 9:53 ` [Qemu-devel] [RFC PATCH 11/11] [WIP] block: Implement 'blockdev-add' QMP command Kevin Wolf
2013-07-11 22:45 ` Eric Blake
2013-07-12 9:40 ` Kevin Wolf
2013-07-12 14:27 ` Eric Blake
2013-07-12 9:55 ` [Qemu-devel] [RFC PATCH 00/11] qapi changes in preparation for blockdev-add Laszlo Ersek
2013-07-12 10:53 ` Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1373363617-4723-10-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).