diff options
Diffstat (limited to 'src/models/counter.hpp')
-rw-r--r-- | src/models/counter.hpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/models/counter.hpp b/src/models/counter.hpp new file mode 100644 index 0000000..d1b68fc --- /dev/null +++ b/src/models/counter.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include <inttypes.h> +#include <string> +#include "models/timer.hpp" + +class FreqCounter { + + public: + + FreqCounter(FreqTimer const & timer) + : _timer(&timer) + {} + + void reset() { _cnt = _overtime_cnt = 0; } + + void inc(); + + uint32_t cnt() const { return _cnt; } + + [[nodiscard]] double rate() const; + + [[nodiscard]] double overtime_rate() const; + + [[nodiscard]] std::string display_value() const; + + + private: + + uint32_t _cnt; + uint32_t _overtime_cnt; + FreqTimer const * _timer; +}; |