diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/eventCounter.cpp | 30 | ||||
-rw-r--r-- | lib/eventCounter.h | 22 |
2 files changed, 52 insertions, 0 deletions
diff --git a/lib/eventCounter.cpp b/lib/eventCounter.cpp new file mode 100644 index 0000000..92383c5 --- /dev/null +++ b/lib/eventCounter.cpp @@ -0,0 +1,30 @@ +#include "eventCounter.h" +#include <algorithm> + +namespace MyGrate { + void + EventCounter::tick(mariadb_rpl_event e) + { + counters[e]++; + } + const EventCounter::Counters & + EventCounter::getAll() const + { + return counters; + } + unsigned long + EventCounter::get(mariadb_rpl_event e) const + { + return counters[e]; + } + bool + EventCounter::operator>=(const EventCounter & target) const + { + for (size_t e {}; e < ENUM_END_EVENT; e++) { + if (counters[e] < target.counters[e]) { + return false; + } + } + return true; + } +} diff --git a/lib/eventCounter.h b/lib/eventCounter.h new file mode 100644 index 0000000..522310a --- /dev/null +++ b/lib/eventCounter.h @@ -0,0 +1,22 @@ +#ifndef MYGRATE_EVENTCOUNTER_H +#define MYGRATE_EVENTCOUNTER_H + +#include "mariadb_repl.h" +#include <array> + +namespace MyGrate { + class EventCounter { + public: + using Counters = std::array<unsigned long, ENUM_END_EVENT>; + + void tick(mariadb_rpl_event); + const Counters & getAll() const; + unsigned long get(mariadb_rpl_event) const; + bool operator>=(const EventCounter &) const; + + protected: + Counters counters {}; + }; +} + +#endif |