Sygaldry
Loading...
Searching...
No Matches
sygaldry::Runtime< ComponentContainer > Struct Template Reference

Wrapper for a component assemblage that calls init and main of all subcomponents that aren't parts. More...

Public Member Functions

constexpr Runtime (ComponentContainer &c)
 The constructor, e.g. constexpr auto runtime = Runtime{container};
 
void init () const
 Initialize all components in the container.
 
void external_sources () const
 Clear input flags, then run the external sources subroutine of all components in the container that have one.
 
void main () const
 Run the main subroutine of all components in the container.
 
void external_destinations () const
 Run the external destinations subroutine of all components in the container that have one, then clear output flags.
 
void tick () const
 Run external sources, main, and external destinations, clearing flags appropriately.
 
int app_main () const
 A wrapper for init and tick that loops indefinitely, intended for instruments with simple requirements.
 

Public Attributes

ComponentContainer & container
 
decltype(component_to_runtime_tuple(std::declval< ComponentContainer & >())) component_runtimes
 A tuple of component-level runtimes.
 

Detailed Description

template<typename ComponentContainer>
struct sygaldry::Runtime< ComponentContainer >

Wrapper for a component assemblage that calls init and main of all subcomponents that aren't parts.

The Sygaldry runtime implements the two-state model of sygaldry components given a component container (i.e. a simple aggregate containing only components), first initializing all components in the container, then running their main subroutines. Furthermore, if the initialization or main subroutines of any component depends on endpoints or endpoint containers of another component (i.e. throughpoints), or another component itself (i.e. plugins), the Runtime is able to automatically extract these dependencies from the component tree represented by the container and forward them to the component that requires them when its subroutine is invoked. This makes it reasonably trivial to define a Sygaldry instrument as a mere assemblage of components. For a simple example, see the implementation of the One Bit Bongo.

Warning
It is important that this class should be declared constexpr when it is instantiated in order to avoid traversing the component tree at compile time, e.g. constexpr auto runtime = Runtime{container};.
Template Parameters
ComponentContainerThe type signature of the component container; this can usually be deduced from the constructor, and so doesn't need to be explicitly identified, e.g. constexpr auto runtime = Runtime{container};.

Constructor & Destructor Documentation

◆ Runtime()

template<typename ComponentContainer >
constexpr sygaldry::Runtime< ComponentContainer >::Runtime ( ComponentContainer &  c)
inlineconstexpr

The constructor, e.g. constexpr auto runtime = Runtime{container};

\detail The constructor permits the template type parameter to be deduced by the compiler. It's important for the runtime to be constexpr for the best performance; see the warning in the detailed description of the class.

Parameters
[in,out]cThe component container managed by the Runtime. See container.

Member Data Documentation

◆ component_runtimes

template<typename ComponentContainer >
decltype(component_to_runtime_tuple(std::declval<ComponentContainer&>())) sygaldry::Runtime< ComponentContainer >::component_runtimes

A tuple of component-level runtimes.

\detail Each component runtime contains a reference to a component and forwarded argument tuples extracted from the main component tree needed to invoke that component's initialization and main subroutines. Users of the runtime should not need to be concerned with this member, except insofar as its initialization is potentially costly, and is moved to compile time by declaring the Runtime as constexpr.

◆ container

template<typename ComponentContainer >
ComponentContainer& sygaldry::Runtime< ComponentContainer >::container

A reference to the component container managed by the Runtime.

This is intended to refer to the top level component container that implements an instrument. In principle, it could also be a lower-level subcomponent used as a part in a subassembly.


The documentation for this struct was generated from the following file: