Invocation: Prototyping how to setup invocation wiring

...still fighting to find a suitable API to define
how inputs and outputs are connected and mapped to function parameters.

The solution drafted here uses the reshaped `DataBuilder` (≙`lib::SeveralBuilder`)
to add up connections for each »slot«, disregarding the possibility of permutations.
Similar to `NodeBuilder`, a policy template is used to pass down the setup
for an actual custom allocator.
This commit is contained in:
Fischlurch 2024-07-23 03:52:44 +02:00
parent 352ef31ab0
commit 42f8f8d5af
4 changed files with 200 additions and 89 deletions

View file

@ -91,6 +91,7 @@
#define ENGINE_NODE_BUILDER_H
#include "steam/engine/weaving-pattern-builder.hpp"
#include "steam/engine/proc-node.hpp"
#include "steam/engine/turnout.hpp"
#include "lib/several-builder.hpp"
@ -107,10 +108,7 @@ namespace engine {
using std::forward;
namespace { // policy configuration for allocator
template<template<typename> class ALO =std::void_t, typename...INIT>
using AlloPolicySelector = lib::allo::SetupSeveral<ALO,INIT...>;
namespace { // default policy configuration to use heap allocator
struct UseHeapAlloc
{
@ -118,23 +116,13 @@ namespace engine {
using Policy = lib::allo::HeapOwn<I,E>;
};
//
}//(End) internal policy configuration
}//(End) policy
/**
* Convenience builder to collect working data.
* A builder to collect working data.
* Implemented through a suitable configuration of lib::SeveralBuilder,
* such as to embed and connect to the configured custom allocator, which
* serves the goal to package all generated node configuration data together
* into a compact memory block, which can be discarded in bulk, once a given
* segment of the low-level-Model has been superseded.
* @tparam POL policy configuration pick the desired allocator
* @tparam I interface type for lib::Several<I>
* @remark in essence, this wrapper class creates the following setup
* \code
* makeSeveral<I>()
* .withAllocator<ALO> (args...);
* \endcode
* with a policy configuration parameter to define the allocator to use.
*/
template<class POL, class I, class E=I>
using DataBuilder = lib::SeveralBuilder<I,E, POL::template Policy>;
@ -193,7 +181,7 @@ namespace engine {
auto
withAllocator (INIT&& ...alloInit)
{
using AllocatorPolicy = AlloPolicySelector<ALO,INIT...>;
using AllocatorPolicy = lib::allo::SetupSeveral<ALO,INIT...>;
return NodeBuilder<AllocatorPolicy>{forward<INIT>(alloInit)...};
}

View file

@ -71,7 +71,6 @@
//#include "lib/time/timevalue.hpp"
//#include "lib/linked-elements.hpp"
#include "lib/several.hpp"
#include "lib/several-builder.hpp"/////////////////TODO extract with a WeavingPattern builder
//#include "lib/util-foreach.hpp"
//#include "lib/iter-adapter.hpp"
#include "lib/meta/function.hpp"
@ -413,13 +412,16 @@ namespace engine {
static_assert (_verify_usable_as_InvocationAdapter<Feed>());
uint fanIn{0};
uint fanOut{0};
Several<PortRef> leadPort;
Several<BuffDescr> outDescr;
Several<BuffDescr> outTypes;
//////////////////////////////////////////OOO builder must set-up those descriptors
SimpleWeavingPattern(Several<PortRef>&& pr, Several<BuffDescr> dr)
: CONF{}
, leadPort{move(pr)}
, outTypes{move(dr)}
{ }
Feed
mount()
@ -430,7 +432,7 @@ namespace engine {
void
pull (Feed& feed, TurnoutSystem& turnoutSys)
{
for (uint i=0; i<fanIn; ++i)
for (uint i=0; i<leadPort.size(); ++i)
{
BuffHandle inputData = leadPort[i].get().weave (turnoutSys);
feed.inBuff.createAt(i, move(inputData));
@ -440,12 +442,12 @@ namespace engine {
void
shed (Feed& feed)
{
for (uint i=0; i<fanOut; ++i)
for (uint i=0; i<outTypes.size(); ++i)
{
BuffHandle resultData = outDescr[i].lockBuffer();
BuffHandle resultData = outTypes[i].lockBuffer();
feed.outBuff.createAt(i, move(resultData));
}
feed.connect (fanIn,fanOut);
feed.connect (leadPort.size(),outTypes.size());
}
void
@ -457,11 +459,11 @@ namespace engine {
void
fix (Feed& feed)
{
for (uint i=0; i<fanIn; ++i)
for (uint i=0; i<leadPort.size(); ++i)
{
feed.inBuff[i].release();
}
for (uint i=0; i<fanOut; ++i)
for (uint i=0; i<outTypes.size(); ++i)
{
feed.outBuff[i].emit();
if (i != feed.resultSlot)
@ -485,6 +487,8 @@ namespace engine {
//////////////////////////////OOO non-copyable? move-only??
{
using Feed = typename PAT::Feed;
using PAT::PAT;
public:
/**
@ -504,32 +508,6 @@ namespace engine {
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1367 : Prototyping: how to assemble a Turnout
template<uint N, class FUN>
using SimpleDirectInvoke = SimpleWeavingPattern<Conf_DirectFunctionInvocation<N,FUN>>;
template<uint N, class FUN>
struct SimpleWeavingBuilder
: Turnout<SimpleDirectInvoke<N,FUN>> /////////////////////////////////OOO can no longer directly inherit from the product(Turnout), due to SeveralBuilder!!!
{
SimpleWeavingBuilder
attachToLeadPort(ProcNode& lead, uint portNr)
{
ASSERT (this->fanIn < N);
PortRef leadPort; /////////////////////////////////////OOO TODO need Accessor on ProcNode!!!!!
this->leadPort.createAt(this->fanIn, leadPort)
++(this->fanIn);
return move(*this);
}
Turnout<SimpleDirectInvoke<N,FUN>>
build()
{
///////////////////////////////OOO need a way to prepare SeveralBuilder-instances for leadPort and outDescr --> see NodeBuilder
return move(*this);
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1367 : (End)Prototyping: how to assemble a Turnout

View file

@ -0,0 +1,105 @@
/*
WEAVING-PATTERN-BUILDER.hpp - build an invocation pattern for media calculations
Copyright (C) Lumiera.org
2024, Hermann Vosseler <Ichthyostega@web.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file weaving-pattern-builder.hpp
** Construction kit for establishing an invocation scheme for media calculations.
**
** @see turnout.hpp
** @see node-builder.hpp
** @see NodeLinkage_test
**
** @todo WIP-WIP-WIP as of 7/2024 prototyping how to build and invoke render nodes /////////////////////////TICKET #1367
**
*/
#ifndef STEAM_ENGINE_WEAVING_PATTERN_BUILDER_H
#define STEAM_ENGINE_WEAVING_PATTERN_BUILDER_H
//#include "steam/common.hpp"
//#include "steam/engine/channel-descriptor.hpp"
//#include "vault/gear/job.h"
#include "lib/several-builder.hpp"
#include "steam/engine/turnout.hpp"
//#include "lib/util-foreach.hpp"
//#include "lib/iter-adapter.hpp"
//#include "lib/meta/function.hpp"
//#include "lib/itertools.hpp"
//#include "lib/util.hpp"
//#include <utility>
//#include <array>
namespace steam {
namespace engine {
using std::forward;
using lib::Several;
template<class POL, class I, class E=I>
using DataBuilder = lib::SeveralBuilder<I,E, POL::template Policy>;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1367 : Prototyping: how to assemble a Turnout
template<uint N, class FUN>
using SimpleDirectInvoke = SimpleWeavingPattern<Conf_DirectFunctionInvocation<N,FUN>>;
template<class POL, uint N, class FUN>
struct SimpleWeavingBuilder
: util::MoveOnly
{
DataBuilder<POL, PortRef> leadPort;
DataBuilder<POL, BuffDescr> outTypes;
SimpleWeavingBuilder
attachToLeadPort(ProcNode& lead, uint portNr)
{
PortRef portRef; /////////////////////////////////////OOO TODO need Accessor on ProcNode!!!!!
leadPort.emplace (portRef);
ENSURE (leadPort.size() < N);
return move(*this);
}
SimpleWeavingBuilder
appendBufferTypes(size_t cnt, BuffDescr const& descriptor)
{
outTypes.fillElm (cnt, descriptor);
ENSURE (outTypes.size() < N);
return move(*this);
}
auto
build()
{
using Product = Turnout<SimpleDirectInvoke<N,FUN>>;
///////////////////////////////OOO need a way to prepare SeveralBuilder-instances for leadPort and outDescr --> see NodeBuilder
return Product{leadPort.build(), outTypes.build};
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1367 : (End)Prototyping: how to assemble a Turnout
}}// namespace steam::engine
#endif /*STEAM_ENGINE_WEAVING_PATTERN_BUILDER_H*/

View file

@ -3365,9 +3365,7 @@
</node>
<node CREATED="1538359397915" ID="ID_446614054" MODIFIED="1538359507892" TEXT="und wenn trotzdem eine Exception fliegt...">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<head/>
<body>
<p>
...dann sind wir sofort tot und das wird billigend in Kauf genommen.
@ -3814,9 +3812,7 @@
</node>
<node COLOR="#338800" CREATED="1484797684438" FOLDED="true" HGAP="21" ID="ID_932852399" MODIFIED="1576282358153" TEXT="GUI-Shutdown implementieren" VSHIFT="13">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<head/>
<body>
<p>
bisher k&#246;nnen wir das GUI nur <i>aktiv intern</i>&#160;schlie&#223;en,
@ -3884,9 +3880,7 @@
<node CREATED="1501792062904" ID="ID_181717876" MODIFIED="1518487921055" TEXT="Subsysteme sind autark"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1501792086244" ID="ID_233471026" MODIFIED="1576282358152" TEXT="wir wollen keine globale Ebene">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<head/>
<body>
<p>
...das war genau der Kern der &quot;Plugin-Debatte&quot;.
@ -3975,9 +3969,7 @@
<node CREATED="1485124129436" ID="ID_1540860407" MODIFIED="1518487921055" TEXT="laut Quellcode spricht nichts dagegen"/>
<node CREATED="1485124142178" ID="ID_1048261084" MODIFIED="1576282358151" TEXT="man sollte aber keine Methoden &#xfc;berschreiben">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<head/>
<body>
<p>
...nur eine <i>heuristische </i>Vermutung von mir
@ -4638,9 +4630,7 @@
</node>
<node CREATED="1483748175610" HGAP="31" ID="ID_73597248" MODIFIED="1518487921057" VSHIFT="16">
<richcontent TYPE="NODE"><html>
<head>
</head>
<head/>
<body>
<p>
Einfachen Aufruf
@ -6056,9 +6046,7 @@
</node>
<node CREATED="1538710407602" ID="ID_1860886507" MODIFIED="1576282358138" TEXT="Regel...">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<head/>
<body>
<p>
den Klassennamen ohne das Namespace-Pr&#228;fix &quot;GTK&quot;, und alles lower case.
@ -7706,9 +7694,7 @@
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1508020731399" HGAP="9" ID="ID_1043748115" MODIFIED="1518487921064" VSHIFT="49">
<richcontent TYPE="NODE"><html>
<head>
</head>
<head/>
<body>
<p>
verbleibende
@ -10255,9 +10241,7 @@
<node CREATED="1512706139167" FOLDED="true" ID="ID_1731306892" MODIFIED="1512926193416" TEXT="Basis-Copy-Konstruktoren werden nicht geerbt">
<node CREATED="1512706158004" ID="ID_958479010" MODIFIED="1512706289090" TEXT="nicht in C++14">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<head/>
<body>
<p>
...da gibt es eine explizite Ausnahme-Regel.
@ -81668,6 +81652,25 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1721782138095" ID="ID_1110509596" MODIFIED="1721782150334" TEXT="mit einem vereinfachten Mapping beginnen">
<icon BUILTIN="yes"/>
<node CREATED="1721782152173" ID="ID_300319891" MODIFIED="1721782173912" TEXT="zun&#xe4;chst davon au&#xdf;gehen da&#xdf; vollst&#xe4;ndig 1:1 verdrahtet wird">
<node CREATED="1721782183257" ID="ID_1206563643" MODIFIED="1721782251306" TEXT="jeder Eingangs-/Ausgangs- Slot wird verwendet"/>
<node CREATED="1721782197168" ID="ID_1419082615" MODIFIED="1721782223559" TEXT="jeder Eingangs-Slot it auf einen (Lead-#, port-#) aufgeschaltet"/>
<node CREATED="1721782257358" ID="ID_1166496456" MODIFIED="1721782368194" TEXT="eventuelle Permutationen werden damit auf den Invocation-Adapter abgew&#xe4;lzt"/>
</node>
<node CREATED="1721782369990" ID="ID_1222041233" MODIFIED="1721782381279" TEXT="das ist zwar vereinfacht, aber durchaus realistisch">
<node CREATED="1721782424103" ID="ID_855104812" MODIFIED="1721782442512" TEXT="in erster N&#xe4;herung tun wir so, als g&#xe4;be es keine Permutationen"/>
<node CREATED="1721782443436" ID="ID_641575909" MODIFIED="1721782461421" TEXT="tats&#xe4;chlich bleibt das Problem der Koordination"/>
<node CREATED="1721782464397" ID="ID_513239873" MODIFIED="1721782480866" TEXT="das liegt aber beim aufrufenden Code, innerhalb der Domain-Ontology"/>
</node>
<node CREATED="1721782492285" ID="ID_1774833221" MODIFIED="1721782510983" TEXT="dadurch wird das API wesentlich einfacher...">
<node CREATED="1721782512084" ID="ID_1590683559" MODIFIED="1721782523912" TEXT="verlangt aber ein strikteres Aufruf-Protokoll"/>
<node CREATED="1721782524709" ID="ID_1583773170" MODIFIED="1721782641163" TEXT="es werden n&#xe4;mlich einfach Slots der Reihe nach belegt">
<arrowlink COLOR="#5581a2" DESTINATION="ID_173220882" ENDARROW="Default" ENDINCLINATION="-314;-501;" ID="Arrow_ID_84112739" STARTARROW="None" STARTINCLINATION="540;29;"/>
</node>
</node>
</node>
<node CREATED="1720178543387" ID="ID_1839001807" MODIFIED="1720178576252" TEXT="adaptInvocation&lt;ADA&gt;">
<node CREATED="1720178577432" ID="ID_438090694" MODIFIED="1720178597453" TEXT="ADA &#x2261; Typ der Invocation-Adapter Klasse"/>
<node CREATED="1720178598060" ID="ID_1951506826" MODIFIED="1720999561682">
@ -87680,8 +87683,8 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<node CREATED="1721169663692" ID="ID_1013263349" MODIFIED="1721169683417" TEXT="weil so etwas in praktisch jedem Builder mit lib::Several auftreten wird"/>
<node CREATED="1721169684391" ID="ID_551192803" MODIFIED="1721169703440" TEXT="weil es effektiv nichts anderes ist, als der SeveralBuilder selber"/>
</node>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1721170586832" ID="ID_545202834" MODIFIED="1721175437912" TEXT="Definitionen geeignet arrangieren">
<icon BUILTIN="pencil"/>
<node COLOR="#338800" CREATED="1721170586832" ID="ID_545202834" MODIFIED="1721751354828" TEXT="Definitionen geeignet arrangieren">
<icon BUILTIN="button_ok"/>
<node BACKGROUND_COLOR="#e0ceaa" COLOR="#690f61" CREATED="1721171395677" ID="ID_1131511599" MODIFIED="1721174710231" STYLE="bubble" TEXT="&#xd83e;&#xdc32; es geht wirklich nur um eine kompakte und lesbare Schreibweise">
<edge COLOR="#d53232"/>
</node>
@ -87790,8 +87793,7 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
diese Policy ist ein <b>einfacher Typparameter</b>
</p>
</body>
</html>
</richcontent>
</html></richcontent>
<node CREATED="1721694029106" ID="ID_945915390" MODIFIED="1721694041669" TEXT="aber wir wollen hier den Umst&#xe4;nden entsprechend"/>
<node CREATED="1721694042489" ID="ID_1052228756" MODIFIED="1721694051165" TEXT="entweder ein HeapOwn einf&#xfc;gen">
<node COLOR="#554398" CREATED="1721694135380" HGAP="69" ID="ID_1608024811" MODIFIED="1721694181414" TEXT="also z.B. NodeBuilder&lt;UseHeapAlloc&gt;" VSHIFT="5">
@ -87810,8 +87812,7 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
using AllocatorPolicy = AlloPolicySelector&lt;<b><font color="#a12362">ALO</font></b>,<b><font color="#a12362">INIT</font></b>...&gt;;
</p>
</body>
</html>
</richcontent>
</html></richcontent>
<font NAME="SansSerif" SIZE="10"/>
</node>
<node COLOR="#554398" CREATED="1721694135380" HGAP="55" ID="ID_248020640" MODIFIED="1721694514913">
@ -87822,8 +87823,7 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
&#10230; withAllocator&lt;<b><font color="#a12362">ALO</font></b>&gt; (<b><font color="#a12362">INIT</font></b>&amp;&amp; ...)
</p>
</body>
</html>
</richcontent>
</html></richcontent>
<font NAME="SansSerif" SIZE="10"/>
</node>
</node>
@ -87831,6 +87831,33 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
</node>
</node>
</node>
<node CREATED="1721751363522" ID="ID_1292406768" MODIFIED="1721751375307" TEXT="letztlich bleiben zwei Definitionen &#xfc;brig">
<icon BUILTIN="info"/>
<node CREATED="1721751377760" ID="ID_1880105530" MODIFIED="1721751404893" TEXT="DataBuilder &#x2254; lib::SeveralBuilder&lt;I,E, POL::template Policy&gt;"/>
<node CREATED="1721751409483" ID="ID_638586531" MODIFIED="1721751463898">
<richcontent TYPE="NODE"><html>
<head/>
<body>
<p>
UseHeapAlloc <font color="#584d4d">&#10229; <i>default-Policy f&#252;r alle Builder</i></font>
</p>
</body>
</html>
</richcontent>
</node>
<node BACKGROUND_COLOR="#d2beaf" COLOR="#5c4d6e" CREATED="1721751472948" ID="ID_458575687" MODIFIED="1721751542135" TEXT="unklar wo diese l&#xe4;ngerfristig untergebracht werden">
<richcontent TYPE="NOTE"><html>
<head/>
<body>
<p>
<i>...vermutlich</i>&#160;wird es irgendwann so eine Art &#187;Builder-Framework&#171; geben, und dorthin geh&#246;ren dann solche Definitionen. Derzeit kann ich hierf&#252;r noch keine sinnvolle Code-Struktur festlegen
</p>
</body>
</html>
</richcontent>
<icon BUILTIN="hourglass"/>
</node>
</node>
</node>
</node>
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1720454107471" ID="ID_1238813567" MODIFIED="1720454187970" TEXT="Allocator im Test verifizieren">
@ -88364,8 +88391,16 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1721061520328" ID="ID_447898484" MODIFIED="1721061541850" TEXT="mu&#xdf; stattdessen das Produkt (Tunrout) explizit konstruieren">
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1721061543907" ID="ID_631078035" MODIFIED="1721061556523" TEXT="tempor&#xe4;re Arbeitsdaten im Builder einf&#xfc;hren">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1721061543907" ID="ID_631078035" MODIFIED="1721785476854" TEXT="tempor&#xe4;re Arbeitsdaten im Builder einf&#xfc;hren">
<icon BUILTIN="pencil"/>
<node BACKGROUND_COLOR="#f8f1cb" COLOR="#a50125" CREATED="1721782887971" ID="ID_388496633" MODIFIED="1721783207223" TEXT="erfordert Umstellung des Builder-Mechanismus">
<icon BUILTIN="messagebox_warning"/>
<node CREATED="1721783212761" ID="ID_688164724" MODIFIED="1721783264389" TEXT="Vorsicht: Produkt (&#x2259;Turnout) wird sofort vom dar&#xfc;berliegenden Builder verarbeitet"/>
<node CREATED="1721783265456" ID="ID_16528841" MODIFIED="1721783298976" TEXT="dieser schiebt das Produkt in das Several&lt;Port&gt;-Array">
<icon BUILTIN="info"/>
</node>
</node>
<node COLOR="#435e98" CREATED="1721782897853" ID="ID_271206866" MODIFIED="1721785456553" TEXT="Konsequenz &#x27f9; fanIn und fanOut werden &#xfc;berfl&#xfc;ssig"/>
</node>
</node>
</node>
@ -88411,6 +88446,11 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<icon BUILTIN="hourglass"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1721782550869" ID="ID_173220882" MODIFIED="1721782642416" TEXT="vereinfachtes Aufruf-API: Slots der Reihe nach belegen">
<linktarget COLOR="#5581a2" DESTINATION="ID_173220882" ENDARROW="Default" ENDINCLINATION="-314;-501;" ID="Arrow_ID_84112739" SOURCE="ID_1583773170" STARTARROW="None" STARTINCLINATION="540;29;"/>
<icon BUILTIN="flag-yellow"/>
<node CREATED="1721782666679" ID="ID_1453585170" MODIFIED="1721782669193" TEXT="attachToLeadPort(ProcNode&amp; lead, uint portNr)"/>
</node>
</node>
</node>
</node>