From 1b4c37b9c500d5a0424b2e75dfc364578a820ac5 Mon Sep 17 00:00:00 2001 From: Vasily Davydov Date: Fri, 14 Oct 2022 13:58:30 +0300 Subject: [PATCH] state-handler: counter: modify limits --- StateHandler/inc/Counter.h | 20 ++++++------- StateHandler/src/Counter.cpp | 54 +++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/StateHandler/inc/Counter.h b/StateHandler/inc/Counter.h index b402f32..8e38df4 100644 --- a/StateHandler/inc/Counter.h +++ b/StateHandler/inc/Counter.h @@ -8,19 +8,19 @@ #ifndef COUNTER_H_ #define COUNTER_H_ -class Counter { +class Counter +{ public: - Counter(int i, int up); - void inc(); - void dec(); - int getCurrent(); - void setInit(int i); - ~Counter() = default; + Counter (int i, int up); + void inc (); + void dec (); + int getCurrent (); + void setInit (int i); + ~Counter () = default; private: - int init; - int up_lim; - + int init; + int up_lim; }; #endif /* COUNTER_H_ */ diff --git a/StateHandler/src/Counter.cpp b/StateHandler/src/Counter.cpp index 0b53145..ff60011 100644 --- a/StateHandler/src/Counter.cpp +++ b/StateHandler/src/Counter.cpp @@ -7,39 +7,49 @@ #include "Counter.h" -void Counter::inc() { - if(init >= up_lim){ - init = 0; - } else{ - ++init; +void +Counter::inc () +{ + if (init < up_lim) + { + ++init; } } -void Counter::dec() { - if(init <= 0){ - init = up_lim; - } else{ - --init; +void +Counter::dec () +{ + if (init - 1 > 0) + { + --init; } } - -int Counter::getCurrent(){ +int +Counter::getCurrent () +{ return this->init; } -Counter::Counter(int i, int up) { - up_lim = up; - if(i > up){ - init = up; - }else if(i < 0){ - init = 0; - }else{ - init = i; +Counter::Counter (int i, int up) +{ + up_lim = up; + if (i > up) + { + init = up; + } + else if (i < 0) + { + init = 0; + } + else + { + init = i; } - } -void Counter::setInit(int i){ +void +Counter::setInit (int i) +{ init = i; }