Skip to content

Commit

Permalink
libappfw|Data: Added method for iterating all items of a data model
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Oct 29, 2014
1 parent 66d5954 commit 682a599
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doomsday/libappfw/include/de/framework/data.h
Expand Up @@ -20,6 +20,7 @@
#define LIBAPPFW_UI_DATA_H

#include <de/Observers>
#include <functional>
#include "../GuiWidget"

namespace de {
Expand Down Expand Up @@ -128,6 +129,8 @@ class LIBAPPFW_PUBLIC Data
*/
virtual dsize size() const = 0;

LoopResult forAll(std::function<LoopResult (Item const &)> func) const;

private:
DENG2_PRIVATE(d)
};
Expand Down
10 changes: 10 additions & 0 deletions doomsday/libappfw/src/data.cpp
Expand Up @@ -65,5 +65,15 @@ void Data::sort(SortMethod method)
}
}

LoopResult Data::forAll(std::function<LoopResult (Item const &)> func) const
{
for(DataPos pos = 0; pos < size(); ++pos)
{
if(auto result = func(at(pos)))
return result;
}
return LoopContinue;
}

} // namespace ui
} // namespace de

0 comments on commit 682a599

Please sign in to comment.