roll_value.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include <stdint.h>
  3. typedef enum {
  4. /**
  5. * @brief Do not change value if it reached constraint
  6. */
  7. RollOverflowBehaviorStop,
  8. /**
  9. * @brief Set value to opposite constraint value if it reached constraint
  10. */
  11. RollOverflowBehaviorRoll
  12. } TotpRollValueOverflowBehavior;
  13. #define TOTP_ROLL_VALUE_FN_HEADER(type, step_type) \
  14. void totp_roll_value_##type( \
  15. type* value, \
  16. step_type step, \
  17. type min, \
  18. type max, \
  19. TotpRollValueOverflowBehavior overflow_behavior)
  20. /**
  21. * @brief Rolls \c int8_t \p value using \p min and \p max as an value constraints with \p step step.
  22. * When value reaches constraint value \p overflow_behavior defines what to do next.
  23. * @param[in,out] value value to roll
  24. * @param step step to be used to change value
  25. * @param min minimal possible value
  26. * @param max maximum possible value
  27. * @param overflow_behavior defines what to do when value reaches constraint value
  28. */
  29. TOTP_ROLL_VALUE_FN_HEADER(int8_t, int8_t);
  30. /**
  31. * @brief Rolls \c uint8_t \p value using \p min and \p max as an value constraints with \p step step.
  32. * When value reaches constraint value \p overflow_behavior defines what to do next.
  33. * @param[in,out] value value to roll
  34. * @param step step to be used to change value
  35. * @param min minimal possible value
  36. * @param max maximum possible value
  37. * @param overflow_behavior defines what to do when value reaches constraint value
  38. */
  39. TOTP_ROLL_VALUE_FN_HEADER(uint8_t, int8_t);
  40. /**
  41. * @brief Rolls \c uint16_t \p value using \p min and \p max as an value constraints with \p step step.
  42. * When value reaches constraint value \p overflow_behavior defines what to do next.
  43. * @param[in,out] value value to roll
  44. * @param step step to be used to change value
  45. * @param min minimal possible value
  46. * @param max maximum possible value
  47. * @param overflow_behavior defines what to do when value reaches constraint value
  48. */
  49. TOTP_ROLL_VALUE_FN_HEADER(uint16_t, int16_t);