throttle.cpp 540 B

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // Created by logicp on 4/22/17.
  3. //
  4. #include <cassert>
  5. #include "throttle.h"
  6. namespace main_stronglogic {
  7. throttle::throttle() {
  8. top_position = 1;
  9. position = 0;
  10. }
  11. throttle::throttle(int size) {
  12. assert(size > 0);
  13. top_position = size;
  14. position = 0;
  15. }
  16. void throttle::shift(int amount) {
  17. position += amount;
  18. if (position < 0) {
  19. position = 0;
  20. } else if (position > top_position) {
  21. position = top_position;
  22. }
  23. }
  24. }