From fbfbc5682acb882843fd7377222de522cfec5b39 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 3 Jun 2018 20:18:08 +0200 Subject: [PATCH] lib/dbus/ReadIter: add ForEachRecurse() --- src/lib/dbus/ObjectManager.hxx | 4 ++-- src/lib/dbus/ReadIter.hxx | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib/dbus/ObjectManager.hxx b/src/lib/dbus/ObjectManager.hxx index 5a8cbf9d5..e37ee28e8 100644 --- a/src/lib/dbus/ObjectManager.hxx +++ b/src/lib/dbus/ObjectManager.hxx @@ -70,8 +70,8 @@ template inline void ForEachInterface(ReadMessageIter &&i, F &&f) { - i.ForEach(DBUS_TYPE_DICT_ENTRY, [&f](auto &&j){ - RecurseInterfaceDictEntry(j.Recurse(), f); + i.ForEachRecurse(DBUS_TYPE_DICT_ENTRY, [&f](auto &&j){ + RecurseInterfaceDictEntry(std::move(j), f); }); } diff --git a/src/lib/dbus/ReadIter.hxx b/src/lib/dbus/ReadIter.hxx index d51dd371c..60312a33c 100644 --- a/src/lib/dbus/ReadIter.hxx +++ b/src/lib/dbus/ReadIter.hxx @@ -91,6 +91,17 @@ public: for (; GetArgType() == arg_type; Next()) f(*this); } + + /** + * Wrapper for ForEach() which passes a recursed iterator for + * each element. + */ + template + void ForEachRecurse(int arg_type, F &&f) { + ForEach(arg_type, [&f](auto &&i){ + f(i.Recurse()); + }); + } }; } /* namespace ODBus */