/** * @file countDown.hpp * @author Gustice * @brief Classes for typical index manipulation * * @copyright Copyright (c) 2020 */ #pragma once class CountDown { public: CountDown(unsigned max) : Max(max) {} void Tick() { _cnt++; if (_cnt >= Max) { _cnt = 0; _pFlag = true; } } bool GetVolatileFlag() { if (!_pFlag) return false; // Reset _pFlag in any case, so it only be consumed once // hence volatile _pFlag = false; return true; } private: const unsigned Max; unsigned _cnt; bool _pFlag; };