lib/dbus/ReadIter: add ForEachProperty()
This commit is contained in:
@@ -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 */
|
||||
|
Reference in New Issue
Block a user