Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
param-weaving-pattern.hpp
Go to the documentation of this file.
1/*
2 PARAM-WEAVING-PATTERN.hpp - Pattern to carry out special parameter computations
3
4 Copyright (C)
5 2024, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12*/
13
14
102#ifndef STEAM_ENGINE_PARAM_WEAVING_PATTERN_H
103#define STEAM_ENGINE_PARAM_WEAVING_PATTERN_H
104
105#include "steam/common.hpp"
111#include "lib/meta/function.hpp"
112
113#include <tuple>
114#include <utility>
115
116
117namespace steam {
118namespace engine {
119
120 using std::move;
121 using std::forward;
122 using std::function;
123 using std::make_tuple;
124 using std::tuple;
125 using lib::meta::Tuple;
127
128
139 template<class ANCH, typename...FUNZ>
141 {
142 using Functors = tuple<FUNZ...>;
143
144 using ResTypes = ElmTypes<Functors>::template Apply<lib::meta::_FunRet>;
145 using ParamTup = Tuple<ResTypes>;
146
148
150 : functors_{move (funz)}
151 { }
152
154 ParamBuildSpec clone() { return *this; }
155
156
157 template<typename FUN>
158 auto
159 addSlot (FUN&& paramFun)
160 {
161 using FunN = std::decay_t<FUN>;
162 return ParamBuildSpec<ANCH,FUNZ...,FunN>{std::tuple_cat (move(functors_)
163 ,make_tuple (forward<FUN>(paramFun)))};
164 }
165
166 template<typename PAR>
167 auto
168 addValSlot (PAR paramVal)
169 {
170 return addSlot ([paramVal](TurnoutSystem&){ return paramVal; });
171 }
172
173
175 template<size_t slot>
176 auto
178 {
179 return std::get<slot> (functors_) (turnoutSys);
180 }
181
189
190
193 template<size_t slot>
194 struct Accessor
195 {
196 static auto&
198 {
199 using StorageAccessor = ChainCons::template Accessor<slot>;
200 return turnoutSys.retrieveData (StorageAccessor());
201 }
202 };
203
204 template<size_t idx>
205 Accessor<idx>
207 {
208 return Accessor<idx>{};
209 }
210
219 {
221
222 public:
224 ChainCons::NewFrame
226 {
227 return std::apply ([&](auto&&... paramFun)
228 { // invoke parameter-functors and build NewFrame from results
229 return ChainCons::build (paramFun (turnoutSys) ...);
230 }
231 ,functors_);
232 }
233
235 void
236 emplaceParamDataBlock (void* storage, TurnoutSystem& turnoutSys)
237 {
238 std::apply ([&](auto&&... paramFun)
239 { // invoke parameter-functors and build NewFrame from results
240 ChainCons::emplace (storage, paramFun (turnoutSys) ...);
241 }
242 ,functors_);
243 }
244
245 private:
247 : functors_{move (funz)}
248 { }
249
250 friend class ParamBuildSpec;
251 };
252
260 {
261 return BlockBuilder (move (functors_));
262 }
263 };
264
265 inline auto
267 {
269 }
270
271
272
273
274
283 template<class SPEC>
286 {
287 using Functors = SPEC::Functors;
288 using DataBlock = SPEC::ChainCons::NewFrame;
289 using BlockBuilder = SPEC::BlockBuilder;
290 using PostProcessor = function<void(TurnoutSystem&)>;
291
295
297 struct Feed
299 {
302
303 DataBlock& block() { return buffer[0]; }
304
305 void
307 {
308 builder.emplaceParamDataBlock (&block(), turnoutSys);
309 }
310 };
311
312
314 ParamWeavingPattern (BlockBuilder builder, PostProcessor postProc, Port& delegate)
315 : blockBuilder_{move (builder)}
316 , postProcess_{move (postProc)}
317 , delegatePort_{delegate}
318 { }
319
320
322 Feed
324 {
325 return Feed();
326 }
327
329 void
330 pull (Feed& feed, TurnoutSystem& turnoutSys)
331 {
332 feed.emplaceParamDataBlock (blockBuilder_, turnoutSys);
333 }
334
339 void
340 shed (Feed& feed, TurnoutSystem& turnoutSys, OptionalBuff outBuff)
341 {
342 turnoutSys.attachChainBlock(feed.block());
343 feed.outBuff = outBuff;
344 if (postProcess_)
345 postProcess_(turnoutSys);
346 }
347
351 void
352 weft (Feed& feed, TurnoutSystem& turnoutSys)
353 {
354 feed.outBuff = delegatePort_.weave (turnoutSys, feed.outBuff);
355 ENSURE (feed.outBuff);
356 }
357
362 fix (Feed& feed, TurnoutSystem& turnoutSys)
363 {
364 turnoutSys.detachChainBlock(feed.block());
365 return *feed.outBuff;
366 }
367
368
370 friend auto
372 {
373 return std::tie (patt.delegatePort_);
374 }
375 };
376
377
378}}// namespace steam::engine
379#endif /*STEAM_ENGINE_PARAM_WEAVING_PATTERN_H*/
Block of raw uninitialised storage with array like access.
Handle for a buffer for processing data, abstracting away the actual implementation.
void emplaceParamDataBlock(void *storage, TurnoutSystem &turnoutSys)
invoke all parameter-functors and package all results by placement-new into a »chain-block«
ChainCons::NewFrame buildParamDataBlock(TurnoutSystem &turnoutSys)
invoke all parameter-functors and drop off the result into a »chain-block« (non-copyable)
virtual BuffHandle weave(TurnoutSystem &, OptionalBuff=std::nullopt)=0
Communication hub to coordinate and activate the »Render Node Network« performance.
auto & retrieveData(ACC const &getter)
void attachChainBlock(CHAIN &chainBlock)
attach an extension block with further parameters as HeteroData-chain to the embedded FrontBlock
void detachChainBlock(CHAIN &chainBlock)
Types marked with this mix-in may be moved but not copied.
Definition nocopy.hpp:50
Any copy and copy construction prohibited.
Definition nocopy.hpp:38
Metaprogramming tools for detecting and transforming function types.
BuildTupleType< TYPES >::Type Tuple
Build a std::tuple from types given as type sequence.
std::optional< BuffHandle > OptionalBuff
Steam-Layer implementation namespace root.
Basic set of definitions and includes commonly used together.
Variadic type sequence builder.
a (static) getter functor able to work on the full extended HeteroData-Chain
static auto & getParamVal(TurnoutSystem &turnoutSys)
Specification record for the setup of a »Param Agent Node«.
auto invokeParamFun(TurnoutSystem &turnoutSys)
intended for unit-testing: invoke one of the embedded param-functors
ElmTypes< Functors >::template Apply< lib::meta::_FunRet > ResTypes
BlockBuilder makeBlockBuilder()
Terminal Builder: (destructively) transform this ParamBuildSpec into a BlockBuilder,...
ParamBuildSpec clone()
can be copied if all functors are copyable...
lib::meta::RebindVariadic< ANCH::template Chain, ParamTup >::Type ChainCons
Storage data frame placed on the call stack.
void emplaceParamDataBlock(BlockBuilder &builder, TurnoutSystem &turnoutSys)
lib::UninitialisedStorage< DataBlock > buffer
Implementation for a Weaving Pattern to conduct extended parameter evaluation.
BuffHandle fix(Feed &feed, TurnoutSystem &turnoutSys)
clean-up: detach the parameter-data-block.
void weft(Feed &feed, TurnoutSystem &turnoutSys)
recursively invoke the delegate port, while the generated parameter-data is indirectly reachable thro...
void shed(Feed &feed, TurnoutSystem &turnoutSys, OptionalBuff outBuff)
Link the param-data-block into the current TurnoutSystem, possibly post-process the param data.
ParamWeavingPattern(BlockBuilder builder, PostProcessor postProc, Port &delegate)
forwarding-ctor to used from within Turnout, to provide actual setup.
function< void(TurnoutSystem &)> PostProcessor
Feed mount(TurnoutSystem &)
Preparation: create a Feed data frame to use as local scope.
friend auto _accessInternal(ParamWeavingPattern &patt)
void pull(Feed &feed, TurnoutSystem &turnoutSys)
Invoke the parameter-functors to create the basic parameter data.
Metaprogramming with tuples-of-types and the std::tuple record.
A actual state of a rendering evaluation parametrised for a single job.
Fixed standard setup used in each Port of the Render Node to generate data.
A raw memory block with proper alignment and array access.
Metaprogramming support to rebuild and rebind variadic templates.