TreeExplorer: rename and refactor for readability

...while this implementation works now, it is still very complex and intricate.
I am still doubtful this is a good approach, but well, we need to try that route....
This commit is contained in:
Fischlurch 2017-11-25 02:43:53 +01:00
parent bb948bff34
commit 76a11b3730
2 changed files with 54 additions and 47 deletions

View file

@ -92,6 +92,7 @@ namespace lib {
using std::move;
using std::forward;
using std::function;
using util::isnil;
namespace iter_explorer {
@ -235,7 +236,6 @@ namespace lib {
using meta::_Fun;
using std::__and_;
using std::__not_;
using std::is_constructible;
using meta::can_IterForEach;
using meta::can_STL_ForEach;
@ -287,37 +287,7 @@ namespace lib {
};
template<class SIG, class ARG, class SEL =void>
struct ArgAccessor
{
using FunArg = typename std::remove_reference<
typename _Fun<SIG>::Args::List::Head>::type;
static_assert (std::is_convertible<ARG, FunArg>::value,
"the expansion functor must accept the source iterator or state core as parameter");
static auto accessor() { return [](ARG& arg) -> ARG& { return arg; }; }
};
template<class SIG, class IT>
struct ArgAccessor<SIG, IT, enable_if<std::is_convertible<typename IT::value_type, typename _Fun<SIG>::Args::List::Head>>>
{
static auto accessor() { return [](auto iter) { return *iter; }; }
};
template<class SIG>
struct ExpaFunc
{
function<SIG> expandFun;
template<typename ARG>
auto
operator() (ARG& arg)
{
auto accessArg = ArgAccessor<SIG,ARG>::accessor();
return expandFun (accessArg (arg));
}
};
template<class FUN, typename SRC>
struct _ExpansionTraits
@ -337,17 +307,43 @@ namespace lib {
};
using Sig = typename FunDetector<FUN>::Sig;
using Arg = typename _Fun<Sig>::Args::List::Head;
using Res = typename _Fun<Sig>::Ret;
using ExpandedChildren = typename _Fun<Sig>::Ret;
using ResultIter = typename _TreeExplorerTraits<Res>::SrcIter;
using Core = typename _TreeExplorerTraits<ExpandedChildren>::SrcIter;
static_assert (std::is_convertible<typename Core::value_type, typename SRC::value_type>::value,
static_assert (std::is_convertible<typename ResultIter::value_type, typename SRC::value_type>::value,
"the iterator from the expansion must yield compatible values");
// using Arg = typename _Fun<Sig>::Args::List::Head;
template<class ARG, class SEL =void>
struct ArgAccessor
{
using FunArgType = typename std::remove_reference<Arg>::type;
static_assert (std::is_convertible<ARG, FunArgType>::value,
"the expansion functor must accept the source iterator or state core as parameter");
using Functor = ExpaFunc<Sig>;
static auto build() { return [](ARG& arg) -> ARG& { return arg; }; }
};
template<class IT>
struct ArgAccessor<IT, enable_if<std::is_convertible<typename IT::value_type, Arg>>>
{
static auto build() { return [](auto iter) { return *iter; }; }
};
struct Functor
{
function<Sig> expandFun;
template<typename ARG>
auto
operator() (ARG& arg)
{
auto accessArg = ArgAccessor<ARG>::build();
return expandFun (accessArg (arg));
}
};
};
}//(End) TreeExplorer traits
@ -361,12 +357,12 @@ namespace lib {
: public SRC
{
using SrcIter = typename SRC::SrcIter;
using _Config = _ExpansionTraits<FUN,SrcIter>;
using Core = typename _Config::Core;
using ExpandFunctor = typename _Config::Functor;
using _Traits = _ExpansionTraits<FUN,SrcIter>;
using ResIter = typename _Traits::ResultIter;
using ExpandFunctor = typename _Traits::Functor;
ExpandFunctor expandChildren_;
IterStack<Core> expansions_;
IterStack<ResIter> expansions_;
public:
Expander() =default;
@ -385,10 +381,10 @@ namespace lib {
{
REQUIRE (checkPoint(*this), "attempt to expand an empty explorer");
Core expanded = 0 < depth()? expandChildren_(*expansions_)
: expandChildren_(*this);
ResIter expanded = 0 < depth()? expandChildren_(*expansions_)
: expandChildren_(*this);
iterNext (*this); // consume current head element
if (expanded.isValid())
if (not isnil(expanded))
expansions_.push (move(expanded));
return *this;
@ -443,8 +439,7 @@ namespace lib {
*
* @todo WIP -- preliminary draft as of 11/2017
*/
template<class SRC
>
template<class SRC>
class TreeExplorer
: public SRC
{
@ -488,6 +483,7 @@ namespace lib {
return ExpandableExplorer{move(*this), forward<FUN>(expandFunctor)};
}
private:
};

View file

@ -5348,6 +5348,16 @@
<font ITALIC="true" NAME="SansSerif" SIZE="12"/>
<icon BUILTIN="clanbomber"/>
</node>
<node COLOR="#338800" CREATED="1511578305427" ID="ID_1738957205" MODIFIED="1511578318339" TEXT="alle technischen Details in die Traits">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1511578319810" ID="ID_1918720180" MODIFIED="1511578346703" TEXT="unterst&#xfc;tzte Varianten dokumentieren">
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1511578330448" ID="ID_1808038526" MODIFIED="1511578396263" TEXT="alle unterst&#xfc;tzten Varianten im Test abdecken">
<arrowlink COLOR="#b65d79" DESTINATION="ID_1298407683" ENDARROW="Default" ENDINCLINATION="-33;-51;" ID="Arrow_ID_1214344498" STARTARROW="None" STARTINCLINATION="-292;0;"/>
<icon BUILTIN="flag-yellow"/>
</node>
</node>
</node>
</node>
@ -5374,7 +5384,8 @@
<icon BUILTIN="button_ok"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1510969031379" ID="ID_1298407683" MODIFIED="1510969041717" TEXT="verify_expandOperation();">
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1510969031379" ID="ID_1298407683" MODIFIED="1511578384759" TEXT="verify_expandOperation();">
<linktarget COLOR="#b65d79" DESTINATION="ID_1298407683" ENDARROW="Default" ENDINCLINATION="-33;-51;" ID="Arrow_ID_1214344498" SOURCE="ID_1808038526" STARTARROW="None" STARTINCLINATION="-292;0;"/>
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1511227813712" ID="ID_942570698" MODIFIED="1511228177906" TEXT="Fall-1">
<icon BUILTIN="button_ok"/>