You are here: Start » Function Reference » All Functions » Conditional Processing » ChooseByRange
This is Filter Equivalent. This function may be present in generated code, but should not be used in hand-written code.
Header: | STD.h |
---|---|
Namespace: | fil |
Module: | FoundationLite |
Returns one of the three input objects depending on whether the associated input value falls below, in or above the specified range.
Applications: E.g. to choose GREEN, YELLOW or RED color for visualization on the basis of three ranges of some value: OK, WARNING, NOK.
Syntax
void fil::ChooseByRange ( const Type& inObjectIfLower, const Type& inObjectIfInRange, const Type& inObjectIfHigher, float inValue, ftl::Optional<float> inMinimum, ftl::Optional<float> inMaximum, Type& outObject )
Parameters
Name | Type | Default | Description | |
---|---|---|---|---|
![]() |
inObjectIfLower | const Type& | Object to be chosen when the value is below the range | |
![]() |
inObjectIfInRange | const Type& | Object to be chosen when the value is in the range | |
![]() |
inObjectIfHigher | const Type& | Object to be chosen when the value is above the range | |
![]() |
inValue | float | Value which is compared against the range | |
![]() |
inMinimum | Optional<float> | NIL | Lower end of the range |
![]() |
inMaximum | Optional<float> | NIL | Upper end of the range |
![]() |
outObject | Type& | Chosen object |
Description
The filter accepts three objects of the T type (decided on filter creation), and passes exactly one of them onto outObject output. The object to pass is selected depending on whether the inValue fits the (inMin, inMax) range.
- If inValue is smaller than inMin, inObjectIfLower is selected.
- If inValue fits closed range (inMin, inMax), inObjectIfInRange is selected.
- If inValue is larger than inMax, inObjectIfHigher is selected.
In the special case of inMin being greater than inMax, first matching condition is applied, which means that if inValue is higher than inMax and lower than inMin, inObjectIfLower is selected.
Hints
- Also consider the ternary operator ?: in Formula Blocks.
- This filter creates a full copy of one of the input objects. Thus, if you need the highest possible speed, use this filter only with primitive types. An alternative is to use Variant Step macrofilters which are fast and elegant.
Examples
![]() |
![]() |
inObjectIfLower = "Mike" inObjectIfInRange = "Bill" inObjectIfHigher = "Alice" inValue = 10.0 inMin = 0.0 inMax = 10.0 |
outObject = "Bill" |
![]() |
![]() |
inObjectIfLower = "Mike" inObjectIfInRange = "Bill" inObjectIfHigher = "Alice" inValue = 10.1 inMin = 0.0 inMax = 10.0 |
outObject = "Alice" |
Errors
List of possible exceptions:
Error type | Description |
---|---|
DomainError | Incorrect (NaN) float value on inValue input in ChooseByRange. |
See Also
- ChooseByPredicate – Returns one of the two input objects depending on the specified condition.
- ChooseByCase – Returns one of the input objects depending on the specified case index.