|
CPP-TOOLBOX
|
A binary switch that tracks temporal transitions between on and off states. More...
#include <temporal_binary_switch.hpp>
Public Member Functions | |
| TemporalBinarySwitch () | |
| Default constructor. Initializes the switch to an off state. | |
| void | set_true () |
| Sets the switch state to true (on). | |
| void | set_false () |
| Sets the switch state to false (off). | |
| bool | just_switched_on () const |
| Checks if the switch has just switched on (non-temporal). | |
| bool | just_switched_off () const |
| Checks if the switch has just switched off (non-temporal). | |
| bool | just_switched_on_temporal () |
| Checks if the switch has just switched on (temporal). | |
| bool | just_switched_off_temporal () |
| Checks if the switch has just switched off (temporal). | |
A binary switch that tracks temporal transitions between on and off states.
Note that throughout these docs ^ will refer to an on signal and v is an off signal.
This class manages a boolean state and provides functionality to detect transitions from false → true (just switched on) and true → false (just switched off). It also provides temporal query methods that reset their respective transition flags after being checked.
This example demonstrates detecting “just happened” transitions in a simulated update loop.
just_switched_on_temporal and just_switched_off_temporal) consume their respective flags when called. This makes them ideal for polling within update loops or event-driven systems where you only need to react once per transition.
|
inline |
Default constructor. Initializes the switch to an off state.
|
inline |
Checks if the switch has just switched off (non-temporal).
This function does not modify internal state.
|
inline |
Checks if the switch has just switched off (temporal).
This function returns true once per transition from on to off. If called in succession, only the first call will return true
|
inline |
Checks if the switch has just switched on (non-temporal).
This function does not modify internal state.
|
inline |
Checks if the switch has just switched on (temporal).
This function returns true once per transition from off to on. If called in succession, only the first call will return true
|
inline |
Sets the switch state to false (off).
If the previous state was true, this marks the switch as having just switched off. If it was already false, no transition flags are modified.
|
inline |
Sets the switch state to true (on).
If the previous state was false, this marks the switch as having just switched on. If it was already true, no transition flags are modified.