diff --git a/logdoctor/CMakeLists.txt b/logdoctor/CMakeLists.txt index 091c21d1..0a82aff1 100644 --- a/logdoctor/CMakeLists.txt +++ b/logdoctor/CMakeLists.txt @@ -8,7 +8,7 @@ set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) -set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) if(MSVC) @@ -57,6 +57,7 @@ set(PROJECT_SOURCES customs/models/logfields_listmodel.h customs/models/logfields_listmodel.cpp + utilities/arrays.h utilities/bwlists.h utilities/bwutils.cpp utilities/chars.h diff --git a/logdoctor/modules/crapview/crapview.cpp b/logdoctor/modules/crapview/crapview.cpp index 90118449..db40e951 100644 --- a/logdoctor/modules/crapview/crapview.cpp +++ b/logdoctor/modules/crapview/crapview.cpp @@ -3,6 +3,7 @@ #include "globals/db_names.h" +#include "utilities/arrays.h" #include "utilities/printables.h" #include "utilities/strings.h" #include "utilities/vectors.h" @@ -14,8 +15,6 @@ #include "modules/crapview/modules/lib.h" -#include - #include #include @@ -932,11 +931,17 @@ bool Crapview::calcGlobals( std::vector>& recur_list { double max_c{ 0.0 }; size_t max_i{ traf.size() }; - std::ranges::for_each( std::views::enumerate(traf), + /*std::ranges::for_each( std::views::enumerate(traf), [&max_c,&max_i](const auto ic) - { if (auto& [i,c]{ic}; c>max_c){ max_c=c; max_i=i; } }); + { if (auto& [i,c]{ic}; c>max_c){ max_c=c; max_i=i; } });*/ + for( const auto [index,count] : ArrayOps::enumerate(traf) ) { + if ( count > max_c ) { + max_c = count; + max_i = index; + } + }; if ( max_i == traf.size() ) { - traffic_list.push_back( std::make_tuple( __dash, __zero ) ); + traffic_list.emplace_back( __dash, __zero ); } else { const size_t f{ static_cast(max_c) }; const size_t d{ max_c<10.0 ? static_cast(max_c*100.0)%100ul : static_cast(max_c*10.0)%10ul }; @@ -944,9 +949,9 @@ bool Crapview::calcGlobals( std::vector>& recur_list if ( d > 0 ) { count += QString::number( d ).prepend(QLatin1Char('.')); } - QString value{ op ? TR::tr(this->dbQuery.DAYS.at(max_i+1).c_str()) - : QStringLiteral("%1").arg(max_i, 2, 10, QChar('0')) }; - traffic_list.push_back( std::make_tuple( value, count ) ); + const QString value{ op ? TR::tr(this->dbQuery.DAYS.at(max_i+1).c_str()) + : QStringLiteral("%1").arg(max_i, 2, 10, QChar('0')) }; + traffic_list.emplace_back( value, count ); } } }; diff --git a/logdoctor/modules/crapview/modules/query.cpp b/logdoctor/modules/crapview/modules/query.cpp index 220b1685..32f5273b 100644 --- a/logdoctor/modules/crapview/modules/query.cpp +++ b/logdoctor/modules/crapview/modules/query.cpp @@ -6,6 +6,7 @@ #include "modules/dialogs.h" #include "modules/exceptions.h" +#include "utilities/arrays.h" #include "utilities/printables.h" #include "utilities/strings.h" @@ -13,7 +14,6 @@ #include #include -#include int toInt( const QString& str ) @@ -1338,7 +1338,9 @@ void DbQuery::getGlobalCounts( std::optional& result, QStringView w } // process the day of the week - for ( auto [total,count] : std::views::zip( data.traf.day, week_days_count ) ) { + /*std::ranges::for_each( std::views::zip( data.traf.day, week_days_count ), + [](auto tc){ if (auto& [t,c]{tc}; c>0.0){ t/=c; } });*/ + for ( auto [total,count] : ArrayOps::zip( data.traf.day, week_days_count ) ) { if ( count > 0.0 ) { total /= count; } diff --git a/logdoctor/utilities/arrays.h b/logdoctor/utilities/arrays.h new file mode 100644 index 00000000..d621ed43 --- /dev/null +++ b/logdoctor/utilities/arrays.h @@ -0,0 +1,142 @@ +#ifndef LOGDOCTOR__ARRAYOPS_H +#define LOGDOCTOR__ARRAYOPS_H + + +#include +#include + + +template +struct Zipperator +{ + using array_value = Array::value_type; + using array_iterator = Array::iterator; + + using iterator_category = std::forward_iterator_tag; + using difference_type = std::ptrdiff_t; + using value_type = std::tuple; + using pointer = std::tuple; + using reference = std::tuple; + + explicit Zipperator( array_iterator l, array_iterator r ) noexcept + : lit{l},rit{r} {} + + inline reference operator*() + { return std::tuple(*lit,*rit); } + + inline Zipperator& operator++() noexcept + { lit++; rit++; return *this; } + + friend bool operator!=( const Zipperator& lhs, const Zipperator& rhs ) noexcept + { return lhs.lit != rhs.lit and lhs.rit != rhs.rit; } + +private: + array_iterator lit; + array_iterator rit; +}; + + +template +struct Enumerator +{ + using array_size_t = Array::size_type; + using array_value = Array::value_type; + using array_iterator = Array::const_iterator; + + using iterator_category = std::forward_iterator_tag; + using difference_type = std::ptrdiff_t; + using value_type = std::tuple; + using pointer = std::tuple; + using reference = std::tuple; + + explicit Enumerator( array_iterator a ) noexcept + : idx{0},iter{a} {} + + inline reference operator*() + { return std::make_tuple(idx,*iter); } + + inline Enumerator& operator++() noexcept + { idx++; iter++; return *this; } + + friend bool operator!=( const Enumerator& lhs, const Enumerator& rhs ) noexcept + { return lhs.iter != rhs.iter; } + +private: + array_size_t idx; + array_iterator iter; +}; + + + +template +class ZippedArrays +{ + Array& larr; + Array& rarr; + +public: + explicit ZippedArrays( Array& l, Array& r ) + : larr{l},rarr{r} {} + + inline auto begin() noexcept + { return Zipperator(larr.begin(),rarr.begin()); } + + inline auto end() noexcept + { return Zipperator(larr.end(),rarr.end()); } +}; + + +template +class EnumeratdArray +{ + const Array& arr; + +public: + explicit EnumeratdArray( const Array& a ) + : arr{a} {} + + inline auto begin() noexcept + { return Enumerator(arr.cbegin()); } + + inline auto end() noexcept + { return Enumerator(arr.cend()); } +}; + + +//! ArrayOps +/*! + Utilities for the arrays +*/ +namespace ArrayOps +{ + +//! Zips two arrays +/*! + \param l_array The left-side array + \param r_array The right-side array + \return An iterator over the two arrays + \todo Replace with std::views::zip when clang will fully support it +*/ +template +inline auto zip( Array& l_array, Array& r_array ) +{ + return ZippedArrays( l_array, r_array ); +} + + +//! Enumerates an array +/*! + \param array The array + \return An iterator over the two array along with the index + \todo Replace with std::views::enumerate when clang will fully support it +*/ +template +inline auto enumerate( const Array& array ) +{ + return EnumeratdArray( array ); +} + +} // namespace ArrayOps + + +#endif // LOGDOCTOR__ARRAYOPS_H