Generic Components
/* Merges streams by selecting the element of one of them at a time */
component Selector<T>(SelectionRule<T, T, Boolean> rule) {
port in T elementA,
in T elementB,
out T selectedElement;
// ...
}
component Foo<K, V> { /*...*/}
Instantiation
When instantiating a generic component, one has bind its type parameters with given types:
component HumanMachineInterface {
port out WindowButtonMoveEvent buttonBackLeftEvent;
// ...
Selector<WindowButtonMoveEvent> signalSelector(/*...*/);
signalSelector.selectedElement -> buttonBackLeftEvent;
// ...
}
component Oracle<T> {
port out T prediction;
Database<T> database; // Used for predicting values
// Other sub components ...
}
Extension
When extending from a generic component, all its type parameters must be bound. Using newly defined type parameters for this is also allowed.
component Selector<T>(/*...*/) extends StreamMerger<T> {
// ...
}
Upper bounds
component AgeFilter<T extends Person>(int minAge) {
port in T unfiltered;
port out T filtered;
compute {
// Using information of the upper bound to access the age of the incoming element.
if (unfiltered.age >= minAge) {
filtered = unfiltered;
}
}
}
&
s:
component Foo<K extends Worker & Student, V> { /*...*/ }