en:toolworks:docs:apparatus:operating

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:toolworks:docs:apparatus:operating [2023/01/14 12:47] – [Argument Delivery] vladiusen:toolworks:docs:apparatus:operating [2023/01/14 13:13] (current) vladius
Line 7: Line 7:
 ==== Using a Lambda ==== ==== Using a Lambda ====
  
-You can easily operate on your chain via a C++ lambda and this is how you do it:+You can easily operate on your chain via a [[cpp>language/lambda|C++ lambda]] and this is how you do it:
 <code cpp> <code cpp>
 Chain->Operate([](FMyTrait Trait) Chain->Operate([](FMyTrait Trait)
Line 95: Line 95:
     Counter += Trait.Value;     Counter += Trait.Value;
 }); });
 +</code>
 +
 +==== Direct Mechanism Operating ====
 +
 +The Operating simplification goes as far as actually Operating on a Mechanism directly, like so:<code cpp>
 +Mechanism->Operate([](FGlowing Glowing, FHelmet Helmet)
 +{
 +    ...
 +});
 +</code>
 +
 +This way the [[en:toolworks:docs:apparatus:filter|Filtering]] and the [[en:toolworks:docs:apparatus:enchaining|Enchaining]] is done automatically under the hood, deriving the necessary Components from the lambda arguments.
 +
 +You can of course supply the Filter specification explicitly, overriding it.
 +
 +So for example, if you want to specify an additional [[en:toolworks:docs:apparatus:trait|Trait]] and a [[en:toolworks:docs:apparatus:flag|Flagmark]] condition, do it like so:<code cpp>
 +Mechanism->Operate(FFilter::Make<FGlowing, FHelmet, FHero>(FM_Z), [](FGlowing Glowing, FHelmet Helmet)
 +{
 +    ...
 +});
 +</code>
 +
 +The direct Operating mode is smart enough to deduce the type of the Chain used within the Operating process, so if you specify a reference to a Trait and/or a Solid Subject handle in your arguments list, the technique will essentially produce a [[en:toolworks:docs:apparatus:solidity|Solid]] iterating:<code cpp>
 +Mechanism->Operate([](FSolidSubjectHandle Subject, FGlowing& Glowing, FHelmet& Helmet)
 +{
 +    ...
 +});
 +</code>
 +
 +You can still specify the Chain type explicitly as a first template argument to a method:<code cpp>
 +Mechanism->Operate<FSolidChain>([](FGlowing Glowing, FHelmet Helmet)
 +{
 +    // You logic within Solid semantics:
 +    ...
 +});
 +</code>
 +
 +Concurrency variants are also provided by the direct interface:<code cpp>
 +Mechanism->OperateConcurrently([](FSolidSubjectHandle Subject, FGlowing& Glowing, FHelmet& Helmet)
 +{
 +    ...
 +}, /*Maximum number of threads=*/4, /*Minimum number of Subjects=*/16);
 </code> </code>
  • en/toolworks/docs/apparatus/operating.1673689649.txt.gz
  • Last modified: 2023/01/14 12:47
  • by vladius