Back to Aurora Vision Library website

You are here: Start » Function Reference » All Functions » Conditional Processing » ChooseByRange

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: avl
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 avl::ChooseByRange
(
	const Type& inObjectIfLower,
	const Type& inObjectIfInRange,
	const Type& inObjectIfHigher,
	float inValue,
	atl::Optional<float> inMinimum,
	atl::Optional<float> inMaximum,
	Type& outObject
)

Parameters

Name Type Default Description
Input value inObjectIfLower const Type& Object to be chosen when the value is below the range
Input value inObjectIfInRange const Type& Object to be chosen when the value is in the range
Input value inObjectIfHigher const Type& Object to be chosen when the value is above the range
Input value inValue float Value which is compared against the range
Input value inMinimum Optional<float> NIL Lower end of the range
Input value inMaximum Optional<float> NIL Upper end of the range
Output value 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.