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.

27 lines
415B

  1. #pragma once
  2. namespace DHE {
  3. class Trigger {
  4. public:
  5. void step() {
  6. auto old_state = state;
  7. state = state_in();
  8. if (state != old_state)
  9. on_state_change(state);
  10. }
  11. protected:
  12. virtual auto state_in() const -> bool = 0;
  13. virtual void on_rise() = 0;
  14. virtual void on_state_change(bool state) {
  15. if (state) {
  16. on_rise();
  17. }
  18. }
  19. private:
  20. bool state = false;
  21. };
  22. } // namespace DHE