From 2eacde7f2cc224cc554f27b56956165229017f27 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 6 Dec 2017 02:33:32 +0100 Subject: [PATCH] TreeExplorer: draft the filter operation should be low hanging fruit now.... --- src/lib/iter-tree-explorer.hpp | 88 +++++++++++++++++++++++ tests/library/iter-tree-explorer-test.cpp | 7 +- wiki/thinkPad.ichthyo.mm | 32 +++++++-- 3 files changed, 121 insertions(+), 6 deletions(-) diff --git a/src/lib/iter-tree-explorer.hpp b/src/lib/iter-tree-explorer.hpp index 41174c927..3cfaf7a30 100644 --- a/src/lib/iter-tree-explorer.hpp +++ b/src/lib/iter-tree-explorer.hpp @@ -644,6 +644,80 @@ namespace lib { return *treated_; } }; + + + + /** + * @internal Decorator for TreeExplorer to filter elements based on a predicate. + * + * @todo WIP 12/17 implement filter + */ + template + class Filter + : public SRC + { + static_assert(can_IterForEach::value, "Lumiera Iterator required as source"); + using _Traits = _BoundFunctorTraits; + using Res = typename _Traits::Res; + static_assert(std::is_constructible::value, "Functor must be a predicate"); + + using FilterPredicate = typename _Traits::Functor; + + FilterPredicate trafo_; + + public: + + Filter() =default; + // inherited default copy operations + + Filter (SRC&& dataSrc, FUN&& filterFun) + : SRC{move (dataSrc)} + , trafo_{forward (filterFun)} + { } + + + /** refresh state when other layers manipulate the source sequence */ + void + expandChildren() + { + //////////////////////TODO trigger re-evaluation here... + SRC::expandChildren(); + } + + public: /* === Iteration control API for IterableDecorator === */ + + bool + checkPoint() const + { + return false; //////////////TODO filter and pull here... + } + + typename SRC::reference + yield() const + { + return *(*this); + } + + void + iterNext() + { + ++ srcIter(); + } + + private: + SRC& + srcIter() const + { + return unConst(*this); + } + + bool + pullFilter () + { + ////////////////////////TODO while-not-filter iter + return false; //////////TODO return true if any result?? + } + }; } @@ -742,6 +816,20 @@ namespace lib { return TreeExplorer (ResCore {move(*this), forward(transformFunctor)}); } + + /** @todo implement filter + */ + template + auto + filter (FUN&& filterPredicate) + { + using ResCore = iter_explorer::Filter; + using ResIter = typename _DecoratorTraits::SrcIter; + + return TreeExplorer (ResCore {move(*this), forward(filterPredicate)}); + } + + private: }; diff --git a/tests/library/iter-tree-explorer-test.cpp b/tests/library/iter-tree-explorer-test.cpp index 76b67620b..e237a5316 100644 --- a/tests/library/iter-tree-explorer-test.cpp +++ b/tests/library/iter-tree-explorer-test.cpp @@ -625,7 +625,10 @@ namespace test{ void verify_FilterIterator() { - UNIMPLEMENTED("preconfigured repeated depth-first expansion"); + cout << materialise ( + treeExplore(CountDown{10}) + .filter([](uint j){ return j % 2; }) + ) << endl; } @@ -635,7 +638,7 @@ namespace test{ void verify_asIterSource() { - UNIMPLEMENTED("preconfigured repeated depth-first expansion"); + UNIMPLEMENTED("package as IterSource"); } diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 9437241a6..1daa0c387 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -5691,8 +5691,8 @@ - - + + @@ -5700,10 +5700,19 @@ - + + + + + + + + + + @@ -6276,9 +6285,24 @@ - + + + + + + + + + + + + + + + +