TreeExplorer: now able to pick up and wrap an IterSource
This commit is contained in:
parent
147aeb4049
commit
64ba7bf372
4 changed files with 67 additions and 20 deletions
|
|
@ -178,6 +178,10 @@ namespace lib {
|
|||
|
||||
static iterator EMPTY_SOURCE;
|
||||
|
||||
using value_type = TY;
|
||||
using reference = TY&;
|
||||
using pointer = TY*;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -271,6 +271,40 @@ namespace lib {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Adapt an IterSource to make it iterable. As such, lib::IterSource is meant
|
||||
* to be iterable, while only exposing a conventional VTable-based _iteration interface_.
|
||||
* To support this usage, the library offers some builders to attach an iterator adapter.
|
||||
* Two flavours need to be distinguished:
|
||||
* - we get a _reference_ to something living elsewhere; all we know is it's iterable.
|
||||
* - we get a pointer, indicating that we must take ownership and manage the lifetime.
|
||||
* The iterable entity in this case can be assumed heap allocated, featuring a virtual
|
||||
* destructor.
|
||||
* The generated front-end has identical type in both cases; it is based on a shared_ptr,
|
||||
* just a different deleter function is used in both cases. This design makes sense,
|
||||
* since the protocol requires us to invoke virtual function IterSource::disconnect()
|
||||
* when use count goes to zero.
|
||||
*/
|
||||
template<class ISO>
|
||||
class IterSourceIter
|
||||
: public ISO::iterator
|
||||
{
|
||||
public:
|
||||
IterSourceIter() =default;
|
||||
// standard copy operations
|
||||
|
||||
/** link to existing IterSource (without memory management) */
|
||||
IterSourceIter (ISO& externalSource)
|
||||
: ISO::iterator{ISO::build (externalSource)}
|
||||
{ }
|
||||
|
||||
/** own and manage a heap allocated IterSource */
|
||||
IterSourceIter (ISO* heap_allocated_IterSource)
|
||||
: ISO::iterator{ISO::build (heap_allocated_IterSource)}
|
||||
{ }
|
||||
};
|
||||
|
||||
}//(End) namespace iter_explorer : basic iterator wrappers
|
||||
|
||||
|
||||
|
|
@ -366,6 +400,20 @@ namespace lib {
|
|||
using SrcVal = typename SrcIter::value_type;
|
||||
};
|
||||
|
||||
template<class ISO>
|
||||
struct _DecoratorTraits<ISO*, enable_if<std::is_base_of<IterSource<typename ISO::value_type>, ISO>>>
|
||||
{
|
||||
using SrcIter = iter_explorer::IterSourceIter<ISO>;
|
||||
using SrcVal = typename ISO::value_type;
|
||||
};
|
||||
|
||||
template<class ISO>
|
||||
struct _DecoratorTraits<ISO&, enable_if<std::is_base_of<IterSource<typename ISO::value_type>, ISO>>>
|
||||
{
|
||||
using SrcIter = iter_explorer::IterSourceIter<ISO>;
|
||||
using SrcVal = typename ISO::value_type;
|
||||
};
|
||||
|
||||
}//(End) TreeExplorer traits
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -885,31 +885,26 @@ namespace test{
|
|||
};
|
||||
|
||||
|
||||
VerySpecivicIter vsit{5};
|
||||
// simple standard case: create a new heap allocated IterSource implementation.
|
||||
// TreeExplorer will take ownership (by smart-ptr) and build a Lumiera Iterator front-End
|
||||
CHECK ("7-6-5-4-3-2-1" == materialise (
|
||||
treeExplore(new VerySpecivicIter{7})));
|
||||
|
||||
|
||||
|
||||
VerySpecivicIter vsit{4};
|
||||
|
||||
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #888
|
||||
// attach to an IterSource living here in local scope...
|
||||
auto ii = treeExplore(vsit);
|
||||
|
||||
CHECK (not isnil (ii));
|
||||
CHECK (5 == *ii);
|
||||
++ii;
|
||||
CHECK (4 == *ii);
|
||||
CHECK (4 == vsit.currentVal());
|
||||
|
||||
VerySpecivicIter* clone = new VerySpecivicIter(vsit);
|
||||
|
||||
CHECK (4 == clone->currentVal());
|
||||
|
||||
cout << materialise(
|
||||
treeExplore(clone)
|
||||
|
||||
) <<endl;
|
||||
|
||||
CHECK (4 == vsit.currentVal());
|
||||
CHECK (4 == *ii);
|
||||
++ii;
|
||||
CHECK (3 == *ii);
|
||||
CHECK (3 == vsit.currentVal());
|
||||
|
||||
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #888
|
||||
auto jj = ii.explore([](PrivateSource& source){ return source.expandChildren(); });
|
||||
|
||||
CHECK (3 == *jj);
|
||||
|
|
|
|||
|
|
@ -6367,8 +6367,8 @@
|
|||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1513990803915" ID="ID_292438102" MODIFIED="1513990973201" TEXT="IterSource-Integration">
|
||||
<linktarget COLOR="#659fa4" DESTINATION="ID_292438102" ENDARROW="Default" ENDINCLINATION="853;414;" ID="Arrow_ID_1802135668" SOURCE="ID_1529167083" STARTARROW="None" STARTINCLINATION="674;0;"/>
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1513990840253" ID="ID_923982542" MODIFIED="1513990864970" TEXT="wrapper analog zu WrappedLumieraIter">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1513990840253" ID="ID_923982542" MODIFIED="1514050246345" TEXT="wrapper und Iterator bauen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1513990851580" ID="ID_1445466432" MODIFIED="1513990865914" TEXT="Traits erweitern">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
|
|
@ -7067,8 +7067,8 @@
|
|||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1513990814361" ID="ID_306902168" MODIFIED="1513990821537" TEXT="verify_IterSource()">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1513990873545" ID="ID_1789456983" MODIFIED="1513990887336" TEXT="einfache Iteration">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1513990873545" ID="ID_1789456983" MODIFIED="1514050256867" TEXT="einfache Iteration">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1513990880600" ID="ID_1730629901" MODIFIED="1513990886456" TEXT="Iteration + Expansion">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue