TreeExplorer: better package this very specific code as subclass

while this is basically just code code cosmetics,
at least it marks this as a very distinct special case,
and keeps the API for the standard Filter layer clean.
This commit is contained in:
Fischlurch 2018-09-02 20:40:49 +02:00
parent 8f70b4e902
commit e29d9ae19e
3 changed files with 38 additions and 8 deletions

View file

@ -863,6 +863,7 @@ namespace lib {
using Res = typename _Traits::Res;
static_assert(std::is_constructible<bool, Res>::value, "Functor must be a predicate");
protected:
using FilterPredicate = typename _Traits::Functor;
FilterPredicate predicate_;
@ -911,7 +912,7 @@ namespace lib {
}
private:
protected:
SRC&
srcIter() const
{
@ -927,7 +928,17 @@ namespace lib {
while (srcIter() and not predicate_(srcIter()))
++srcIter();
}
};
template<class SRC, class FUN>
class MutableFilter
: public Filter<SRC,FUN>
{
using _Base = Filter<SRC,FUN>;
public:
using _Base::Filter;
public: /* === API to Remould the Filter condition underway === */
@ -957,13 +968,14 @@ namespace lib {
using Res = typename _ChainTraits::Res;
static_assert(std::is_constructible<bool, Res>::value, "Chained Functor must be a predicate");
using FilterPredicate = typename _Base::FilterPredicate;
using ChainPredicate = typename _ChainTraits::Functor;
FilterPredicate& firstClause = this->predicate_;
FilterPredicate& firstClause = Filter<SRC,FUN>::predicate_;
ChainPredicate chainClause{forward<COND> (additionalClause)};
predicate_ = FilterPredicate{buildCombinedClause (firstClause, chainClause)};
pullFilter();
_Base::predicate_ = FilterPredicate{buildCombinedClause (firstClause, chainClause)};
_Base::pullFilter();
}
};
@ -1265,6 +1277,17 @@ namespace lib {
}
template<class FUN>
auto
mutableFilter (FUN&& filterPredicate)
{
using ResCore = iter_explorer::MutableFilter<SRC, FUN>;
using ResIter = typename _DecoratorTraits<ResCore>::SrcIter;
return TreeExplorer<ResIter> (ResCore {move(*this), forward<FUN>(filterPredicate)});
}
/** _terminal builder_ to package the processing pipeline as IterSource.
* Invoking this function moves the whole iterator compound, as assembled by the preceding
* builder calls, into heap allocated memory and returns a [iterator front-end](\ref IterExploreSource).

View file

@ -853,7 +853,7 @@ namespace test{
verify_FilterChanges()
{
auto seq = treeExplore(CountDown{20})
.filter([](uint){ return true; });
.mutableFilter([](uint){ return true; });
auto takeEve = [](uint i){ return i%2 == 0; };
auto takeTrd = [](uint i){ return i%3 == 0; };

View file

@ -30977,7 +30977,8 @@
</node>
<node COLOR="#338800" CREATED="1535906261464" ID="ID_1343076549" MODIFIED="1535909947735" TEXT="Auswege">
<icon BUILTIN="idea"/>
<node CREATED="1535906265911" ID="ID_442265155" MODIFIED="1535906279633" TEXT="speziellen Filter-Layer nur hierf&#xfc;r">
<node COLOR="#338800" CREATED="1535906265911" ID="ID_442265155" MODIFIED="1535913504313" TEXT="speziellen Filter-Layer nur hierf&#xfc;r">
<icon BUILTIN="button_ok"/>
<node CREATED="1535906327782" ID="ID_1903350743" MODIFIED="1535906334769" TEXT="letztlich nur Code-Kosmetik"/>
<node CREATED="1535909106704" ID="ID_1756811057" MODIFIED="1535909115714" TEXT="w&#xfc;rde aber sehr speziellen Fall markieren"/>
<node CREATED="1535909145091" ID="ID_23855152" MODIFIED="1535909185418">
@ -31051,10 +31052,16 @@
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1535899873112" ID="ID_1460874987" MODIFIED="1535899882165" TEXT="Unit-Test (replizieren)">
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1535899873112" ID="ID_1460874987" MODIFIED="1535913524436" TEXT="Unit-Test (replizieren)">
<icon BUILTIN="pencil"/>
<node COLOR="#338800" CREATED="1535913527837" ID="ID_1506533000" MODIFIED="1535913542932" TEXT="anlegen">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1535913531701" ID="ID_1093929821" MODIFIED="1535913541204" TEXT="andere F&#xe4;ll auch covern">
<icon BUILTIN="flag-yellow"/>
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1535899922873" ID="ID_1971708144" MODIFIED="1535899950863" TEXT="bestehende Aufrufe konsolidieren">
<richcontent TYPE="NOTE"><html>
<head>