From 0efa8e3c43b3bb65ef817b35fac5a9438c940cd5 Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Fri, 21 Jun 2019 19:18:25 +0300 Subject: [PATCH] [eye] Appending additional counters without any version increasing and migration is supported. --- metrics/eye_info.hpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/metrics/eye_info.hpp b/metrics/eye_info.hpp index 235b23f0df..6b09cc4269 100644 --- a/metrics/eye_info.hpp +++ b/metrics/eye_info.hpp @@ -37,13 +37,13 @@ using is_enum_with_count = decltype(impl::is_enum_with_count_checker(0)); } // namespace traits template -using EnableIfIsEnumWithCount = std::enable_if_t::value>; +using EnableIfEnumWithCount = std::enable_if_t::value>; template class Counters; template -class Counters> +class Counters> { public: void Increment(T const key) @@ -57,7 +57,24 @@ public: return m_counters[static_cast(key)]; } - DECLARE_VISITOR_AND_DEBUG_PRINT(Counters, visitor(m_counters, "counters")) + template + void Visit(Visitor & visitor) + { + // We need it to support appending additional counters + // without any version increasing and migration. + std::vector loader; + visitor(loader, "counters"); + CHECK_LESS_OR_EQUAL(loader.size(), m_counters.size(), ()); + std::copy_n(loader.cbegin(), m_counters.size(), m_counters.begin()); + } + + template + void Visit(Visitor & visitor) const + { + visitor(m_counters, "counters"); + } + + DECLARE_DEBUG_PRINT(Counters) private: std::array(T::Count)> m_counters = {}; @@ -98,6 +115,8 @@ struct Bookmarks struct Discovery { + // The order is important. + // New types must be added before Type::Count item. enum class Event { HotelsClicked, @@ -157,6 +176,8 @@ struct Tip Count }; + // The order is important. + // New types must be added before Type::Count item. enum class Event : uint8_t { ActionClicked,