2024-07-23 03:52:44 +02:00
/*
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 0213 9 , 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"
2024-08-03 03:21:59 +02:00
# include "steam/engine/engine-ctx.hpp"
2024-07-24 20:29:37 +02:00
# include "steam/engine/buffer-provider.hpp"
2024-07-23 03:52:44 +02:00
//#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>
2024-07-24 20:29:37 +02:00
# include <functional>
2024-07-23 03:52:44 +02:00
//#include <array>
2024-07-24 20:29:37 +02:00
# include <vector>
2024-07-23 03:52:44 +02:00
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 ;
2024-07-24 20:29:37 +02:00
using TypeMarker = std : : function < BuffDescr ( BufferProvider & ) > ;
using ProviderRef = std : : reference_wrapper < BufferProvider > ;
std : : vector < TypeMarker > buffTypes ;
std : : vector < ProviderRef > providers ;
2024-07-30 23:44:55 +02:00
uint resultSlot { 0 } ;
2024-07-24 20:29:37 +02:00
struct ServiceCtx
{
ProviderRef mem ;
ProviderRef cache ;
ProviderRef output ;
} ;
ServiceCtx ctx ; //////////////////////////////////////////OOO need to wire that top-down through all builders!
2024-07-23 03:52:44 +02:00
SimpleWeavingBuilder
attachToLeadPort ( ProcNode & lead , uint portNr )
{
PortRef portRef ; /////////////////////////////////////OOO TODO need Accessor on ProcNode!!!!!
leadPort . emplace ( portRef ) ;
ENSURE ( leadPort . size ( ) < N ) ;
return move ( * this ) ;
}
2024-07-24 20:29:37 +02:00
template < class BU >
2024-07-23 03:52:44 +02:00
SimpleWeavingBuilder
2024-07-30 23:44:55 +02:00
appendBufferTypes ( uint cnt )
2024-07-23 03:52:44 +02:00
{
2024-07-24 20:29:37 +02:00
while ( cnt - - )
buffTypes . emplace_back ( [ ] ( BufferProvider & provider )
{ return provider . getDescriptor < BU > ( ) ; } ) ;
ENSURE ( buffTypes . size ( ) < N ) ;
2024-07-23 03:52:44 +02:00
return move ( * this ) ;
}
2024-07-24 20:29:37 +02:00
SimpleWeavingBuilder
2024-07-30 23:44:55 +02:00
selectResultSlot ( uint idx )
2024-07-24 20:29:37 +02:00
{
2024-07-30 23:44:55 +02:00
this - > resultSlot = idx ;
return move ( * this ) ;
}
2024-07-24 20:29:37 +02:00
2024-07-23 03:52:44 +02:00
auto
build ( )
{
2024-07-24 20:29:37 +02:00
maybeFillDefaultProviders ( buffTypes . size ( ) ) ;
uint i = 0 ;
2024-07-30 23:44:55 +02:00
for ( auto & typeConstructor : buffTypes )
outTypes . emplace (
typeConstructor ( providers [ i ] ) ) ;
2024-07-24 20:29:37 +02:00
ENSURE ( leadPort . size ( ) < N ) ;
ENSURE ( outTypes . size ( ) < N ) ;
2024-07-23 03:52:44 +02:00
using Product = Turnout < SimpleDirectInvoke < N , FUN > > ;
///////////////////////////////OOO need a way to prepare SeveralBuilder-instances for leadPort and outDescr --> see NodeBuilder
2024-07-30 23:44:55 +02:00
return Product { leadPort . build ( ) , outTypes . build ( ) } ;
2024-07-23 03:52:44 +02:00
}
2024-07-24 20:29:37 +02:00
private :
void
maybeFillDefaultProviders ( size_t maxSlots )
{
for ( uint i = providers . size ( ) ; i < maxSlots ; + + i )
providers . emplace_back ( ctx . mem ) ;
}
2024-07-23 03:52:44 +02:00
} ;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1367 : (End)Prototyping: how to assemble a Turnout
} } // namespace steam::engine
# endif /*STEAM_ENGINE_WEAVING_PATTERN_BUILDER_H*/