summaryrefslogtreecommitdiff
path: root/src/lib/dbus
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-06-03 20:06:37 +0200
committerMax Kellermann <max@musicpd.org>2018-06-03 20:18:46 +0200
commite560f6bc63f2c51e48e4670910cb7c62698d115d (patch)
tree909f90d8563a552d23e7ec13445e70b7b05bd972 /src/lib/dbus
parentfbfbc5682acb882843fd7377222de522cfec5b39 (diff)
lib/dbus/ReadIter: add ForEachProperty()
Diffstat (limited to 'src/lib/dbus')
-rw-r--r--src/lib/dbus/ReadIter.hxx22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/dbus/ReadIter.hxx b/src/lib/dbus/ReadIter.hxx
index 60312a33c..a8ea9d7d4 100644
--- a/src/lib/dbus/ReadIter.hxx
+++ b/src/lib/dbus/ReadIter.hxx
@@ -102,6 +102,28 @@ public:
f(i.Recurse());
});
}
+
+ /**
+ * Invoke a function for each name/value pair (string/variant)
+ * in a dictionary (array containing #DBUS_TYPE_DICT_ENTRY).
+ * The function gets two parameters: the property name (as C
+ * string) and the variant value (as #ReadMessageIter).
+ */
+ template<typename F>
+ void ForEachProperty(F &&f) {
+ ForEachRecurse(DBUS_TYPE_DICT_ENTRY, [&f](auto &&i){
+ if (i.GetArgType() != DBUS_TYPE_STRING)
+ return;
+
+ const char *name = i.GetString();
+ i.Next();
+
+ if (i.GetArgType() != DBUS_TYPE_VARIANT)
+ return;
+
+ f(name, i.Recurse());
+ });
+ }
};
} /* namespace ODBus */