Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
619 B

  1. /*
  2. Helper class to set the boolean exactly when setting multiple times in a row
  3. (as an alternative to checking input every time before setting)
  4. */
  5. #pragma once
  6. struct OnceFlag {
  7. OnceFlag() = default;
  8. OnceFlag(const OnceFlag&) = delete;
  9. OnceFlag(OnceFlag&&) = delete;
  10. explicit operator bool() const {
  11. return _value;
  12. }
  13. OnceFlag& operator=(bool value) {
  14. if (!_value) {
  15. _value = value;
  16. }
  17. return *this;
  18. }
  19. void set() {
  20. _value = true;
  21. }
  22. bool get() const {
  23. return _value;
  24. }
  25. private:
  26. bool _value { false };
  27. };