RIT VEXU Core API
Loading...
Searching...
No Matches
Selector Namespace Reference

Typedefs

using selector_t = size_t()
 The type of an Initializer's Selector function.

Functions

std::function< selector_tselect (size_t n)
std::function< selector_trandom (size_t a, size_t b)
std::function< selector_trandom (size_t n)
template<size_t FLAG = NO_SELECTION_INDEX>
std::function< selector_tskippable (std::function< selector_t > selector)
std::function< selector_ttimeout (std::function< selector_t > selector, uint64_t microsec, unsigned int fallback=NO_SELECTION_INDEX, std::function< void(size_t)> cancel=nullptr)
std::function< selector_tdelayed (std::function< selector_t > selector, unsigned int ms)
std::function< selector_tpotentiometer (vex::pot &potentiometer, const size_t &initializations)
std::function< selector_tweighted_potentiometer (vex::pot &potentiometer, std::vector< Initialization > &initializations)

Variables

constexpr size_t NO_SELECTION_INDEX = SIZE_MAX
 A constant index that is used in selector functions to represent when a selection has not yet been made.

Detailed Description

A namespace containing predefined selector functions and wrappers that can be passed to an Initializer.

Function Documentation

◆ delayed()

std::function< selector_t > Selector::delayed ( std::function< selector_t > selector,
unsigned int ms )
inline

A selector function wrapper that delays the program for a set amount of time before selecting the Initialization.

Parameters
selectorThe selector function to execute
msThe amount of time to delay for, in milliseconds
Returns
The return value of selector

◆ potentiometer()

std::function< selector_t > Selector::potentiometer ( vex::pot & potentiometer,
const size_t & initializations )
inline

A selector function that utilizes a potentiometer to select the Initialization Each initialization is corresponds to an equal percentage of the potentiometer's range.

Parameters
potentiometerThe potentiometer to select inputs based on
initializationsThe number of initializations
Returns
A selector function that selects its Initialization based utilizing a potentiometer

◆ random() [1/2]

std::function< selector_t > Selector::random ( size_t a,
size_t b )
inline

Returns a selector function that selects a random Initialization

Precondition
Call srand() in pre-initialization using the VEX Brain's high-resolution timer
Parameters
aThe inclusive beginning of the random range
bThe exclusive end of the random range
Returns
A random size_t value in the range [A,B). If the range is invalid (B

◆ random() [2/2]

std::function< selector_t > Selector::random ( size_t n)
inline

Returns a selector function that selects a random Initialization

Precondition
Call srand() in pre-initialization using the VEX Brain's high-resolution timer
Parameters
nThe exclusive end of the random range
Returns
A random size_t value in the range [0,N).

◆ select()

std::function< selector_t > Selector::select ( size_t n)
inline

Returns a selector function that selects the Initialization corresponding to N

Parameters
nThe Initialization to select
Returns
The value of N

◆ skippable()

template<size_t FLAG = NO_SELECTION_INDEX>
std::function< selector_t > Selector::skippable ( std::function< selector_t > selector)
inline

Returns a selector function wrapper that allows selection to be skipped based on a compile-time flag. This should only be used for debugging, as it would otherwise defeat the purpose of the Initializer.

Template Parameters
FLAGThe Initialization to select if compile-time selection is wanted, or nothing to select Initializations based on the provided selector.
Parameters
selectorThe selector function for runtime selection
Returns
The compile selector function if flag is defined, and the selector argument if flag is not defined

◆ timeout()

std::function< selector_t > Selector::timeout ( std::function< selector_t > selector,
uint64_t microsec,
unsigned int fallback = NO_SELECTION_INDEX,
std::function< void(size_t)> cancel = nullptr )
inline

A selector function wrapper that allows a selection to timeout, returning the fallback if it does.

Precondition
The selector function must be thread-safe
Parameters
selectorThe thread-safe selector function to execute
microsecThe amount of time until a timeout occurs, in microseconds
fallbackThe return value if a timeout occurs
cancelThe callback used to notify the rest of the program if a timeout occured. It will always be passed the fallback value as its argument.
Returns
The return value of selector, or fallback if a timeout occurs

◆ weighted_potentiometer()

std::function< selector_t > Selector::weighted_potentiometer ( vex::pot & potentiometer,
std::vector< Initialization > & initializations )
inline

A selector function that utilizes a potentiometer to select the Initialization. This function uses the metadata of the Initializations to determine their representation on the potentiometer.

Parameters
potentiometerThe potentiometer to select inputs based on
initializationsA vector of initializations
Returns
A selector function that selects its Initialization based utilizing a potentiometer