roll_value.h 2.6 KB

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