From 30a90166fbf30fde04414c020aceaf1a02a8ad23 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 24 Dec 2017 23:26:22 +0100 Subject: [PATCH] X-mas: switch demo-Child-Iterator to the new framework ...passes all the existing unit tests! --- src/gui/interact/gen-node-location-query.hpp | 35 ++++++++++++++------ src/gui/interact/ui-coord-resolver.hpp | 19 +++-------- src/lib/iter-source.hpp | 2 +- wiki/thinkPad.ichthyo.mm | 28 ++++++++++++---- 4 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/gui/interact/gen-node-location-query.hpp b/src/gui/interact/gen-node-location-query.hpp index af1e0ace1..e42b2cc26 100644 --- a/src/gui/interact/gen-node-location-query.hpp +++ b/src/gui/interact/gen-node-location-query.hpp @@ -61,10 +61,12 @@ #define GUI_INTERACT_GEN_NODE_LOCATION_QUERY_H #include "lib/error.hpp" -//#include "lib/symbol.hpp" +#include "lib/symbol.hpp" #include "gui/interact/ui-coord-resolver.hpp" #include "lib/diff/gen-node.hpp" #include "lib/format-string.hpp" +#include "lib/iter-tree-explorer.hpp" +#include "lib/iter-source.hpp" #include "lib/itertools.hpp" #include "lib/util.hpp" @@ -82,10 +84,11 @@ namespace interact { // using std::unique_ptr; // using std::string; -// using lib::Literal; -// using lib::Symbol; + using lib::Literal; + using lib::Symbol; using lib::diff::Rec; using util::_Fmt; + using std::forward; // using util::unConst; // using util::isnil; // using util::min; @@ -214,24 +217,34 @@ namespace interact { } - struct TreePos + class GenNodeNavigator + : public TreeStructureNavigator { - Rec const& node; - size_t depth; - - ////////////TODO wtf to return as iterator type? it is not uniform! + virtual TreeStructureNavigator* + expandChildren() const override + { + UNIMPLEMENTED ("build an iterator to yield the children. This requires to remember who we are ourselves."); + } }; + template + static auto + expandableIterSource(IT && rawIterator) + { + return TreeStructureNavigator::buildIterator( + new lib::WrappedLumieraIter {forward (rawIterator)}); + } + static ChildIter childSequence (Rec const& node, size_t& depth) { + //////////////////////////////////////////////////////////////////////////TICKET #1113 : capturing the string into the global Symbol table becomes obsolete, once GenNode exposes Literal as ID auto internedString = [](string const& id) -> Literal { return Symbol{id}; }; - return depth==UIC_PERSP? lib::iter_source::singleVal (internedString (node.getType())) - : lib::iter_source::transform (node.keys(), internedString); - /////////////////////////////////////////////////////////////////////TICKET #1113 : could just use lib::wrapIter when GenNode exposes Literal as ID + return depth==UIC_PERSP? expandableIterSource(singleValIterator (internedString (node.getType()))) + : expandableIterSource(transformIterator (node.keys(), internedString)); } }; diff --git a/src/gui/interact/ui-coord-resolver.hpp b/src/gui/interact/ui-coord-resolver.hpp index 78a0c1527..2762724f4 100644 --- a/src/gui/interact/ui-coord-resolver.hpp +++ b/src/gui/interact/ui-coord-resolver.hpp @@ -101,23 +101,13 @@ namespace interact { virtual TreeStructureNavigator* expandChildren() const =0; - /** build a Lumiera Forward Iterator as front-end for `*this`. + /** build a Lumiera Forward Iterator as front-end and managing Handle for a TreeStructureNavigator + * or subclass. The provided pointer is assumed to point to heap allocated storage. * @return copyable iterator front-end handle, which allows to retrieve once all values - * yielded by this IterSource. The front-end does _not take ownership_ of this object. + * yielded by this IterSource. The front-end _takes ownership_ of the given object. * @note the generated iterator is preconfigured to allow for _"child expansion"_, thereby * calling through the virtual API function expandChildren() */ - auto - buildIterator () - { - return lib::treeExplore (*this) - .expand([](TreeStructureNavigator& parent){ return parent.expandChildren(); }); - } - - /** build a Lumiera Forward Iterator as front-end and managing Handle for a heap allocated - * TreeStructureNavigator or subclass. The provided pointer is assumed to point to heap allocated - * storage, which will be owned by the generated iterator. - */ static auto buildIterator (TreeStructureNavigator* source) { @@ -142,8 +132,7 @@ namespace interact { public: virtual ~LocationQuery(); ///< this is an interface - using iteratorZ = decltype (TreeStructureNavigator::buildIterator(std::declval())); - using ChildIter = lib::IterSource::iterator; + using ChildIter = decltype (TreeStructureNavigator::buildIterator(0)); /** make the real anchor point explicit. diff --git a/src/lib/iter-source.hpp b/src/lib/iter-source.hpp index 810a50553..a916ac32d 100644 --- a/src/lib/iter-source.hpp +++ b/src/lib/iter-source.hpp @@ -379,7 +379,7 @@ namespace lib { /** an IterSource frontend to return just a single value once. * @warning behind the scenes, a heap allocation is managed by shared_ptr, * to maintain a copy of the wrapped element. When passing a reference, - * only a reference will be wrapped, but a heap allocation happens nontheless + * only a reference will be wrapped, but a heap allocation happens nonetheless */ template auto diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 07e410c16..92f0feeb9 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -977,7 +977,7 @@ - + @@ -8156,6 +8156,16 @@ + + + + + + + + + + @@ -8173,10 +8183,14 @@ - - + + - + + + + + @@ -8191,8 +8205,8 @@ - - + + @@ -17015,7 +17029,7 @@ - +