lib/dbus/ReadIter: add ForEachProperty()

This commit is contained in:
Max Kellermann
2018-06-03 20:06:37 +02:00
parent fbfbc5682a
commit e560f6bc63
2 changed files with 33 additions and 31 deletions

View File

@@ -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 */