diff options
Diffstat (limited to 'src/lib/dbus/ReadIter.hxx')
-rw-r--r-- | src/lib/dbus/ReadIter.hxx | 22 |
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 */ |