From 26d3bc56d2eadc14bcacbb855eba535e8fb3d317 Mon Sep 17 00:00:00 2001 From: Tomasz Golinski Date: Sun, 24 Dec 2023 23:38:55 +0100 Subject: [PATCH] Trivial cppcheck fixes --- common.cpp | 4 ++-- common.h | 2 +- geostat.cpp | 10 +++++----- geostat_cli.cpp | 4 ++-- ocdb.cpp | 2 +- user.cpp | 7 +++++++ user.h | 2 ++ 7 files changed, 20 insertions(+), 11 deletions(-) diff --git a/common.cpp b/common.cpp index 8a02013..f0a6752 100644 --- a/common.cpp +++ b/common.cpp @@ -66,7 +66,7 @@ void show_histogram(const Caches& cc, std::string Cache::*ptr, const std::string std::map histogram; - for (auto el : cc) + for (const auto& el : cc) histogram[el.*ptr]++; show_histogram(histogram, caption, html, sort_by_val); @@ -346,7 +346,7 @@ void footer_html() { Position Cache::home; -Position::Position(std::string loc) { +Position::Position(const std::string& loc) { int pos = loc.find("|"); lat = stof(loc.substr(0, pos)); lon = stof(loc.substr(pos + 1)); diff --git a/common.h b/common.h index e734e98..ddba445 100644 --- a/common.h +++ b/common.h @@ -67,7 +67,7 @@ public: Position() = default; Position(float y, float x) : lat(y), lon(x) {} - explicit Position(std::string loc); + explicit Position(const std::string& loc); }; float cache_distance(const Cache& a, const Cache& b); diff --git a/geostat.cpp b/geostat.cpp index 21e98c6..e6b37ed 100644 --- a/geostat.cpp +++ b/geostat.cpp @@ -244,7 +244,7 @@ int main(int argc, char** argv) { long max = 0; // maximal value for histogram for (int i = y_min; i <= y_max; i++) for (int j = 1; j <= 12; j++) - max = std::max(max, std::count_if(user.cc.begin(), user.cc.end(), [i, j](Cache c) { return (c.date_tm.tm_year == i && c.date_tm.tm_mon == j - 1); })); + max = std::max(max, std::count_if(user.cc.begin(), user.cc.end(), [i, j](const Cache& c) { return (c.date_tm.tm_year == i && c.date_tm.tm_mon == j - 1); })); if (max > 0) { std::cout << "

Caching timeline

\n"; @@ -258,7 +258,7 @@ int main(int argc, char** argv) { for (int i = y_min; i <= y_max; i++) { // i -> years in rows std::cout << "" << i + 1900 << " "; for (int j = 1; j <= 12; j++) { // j -> months in cols - count = std::count_if(user.cc.begin(), user.cc.end(), [i, j](Cache c) { return (c.date_tm.tm_year == i && c.date_tm.tm_mon == j - 1); }); + count = std::count_if(user.cc.begin(), user.cc.end(), [i, j](const Cache& c) { return (c.date_tm.tm_year == i && c.date_tm.tm_mon == j - 1); }); std::cout << "" << count << ""; } std::cout << "\n"; @@ -280,7 +280,7 @@ int main(int argc, char** argv) { std::cout << "" << i + 1900 << " "; for (int j = 1; j <= 12; j++) { // j -> months in cols std::map days_count; - for (auto el : user.cc) { + for (const auto& el : user.cc) { if (el.date_tm.tm_mon == j - 1 && el.date_tm.tm_year == i) days_count[el.date_tm.tm_mday]++; } @@ -779,7 +779,7 @@ int main(int argc, char** argv) { long max = 0; // maximal value for histogram for (int i = y_min; i <= y_max; i++) for (int j = 1; j <= 12; j++) - max = std::max(max, std::count_if(user.cc.begin(), user.cc.end(), [i, j](Cache c) { return (c.date_hidden_tm.tm_year == i && c.date_hidden_tm.tm_mon == j - 1); })); + max = std::max(max, std::count_if(user.cc.begin(), user.cc.end(), [i, j](const Cache& c) { return (c.date_hidden_tm.tm_year == i && c.date_hidden_tm.tm_mon == j - 1); })); if (max > 0) { std::cout << "

Cache creation timeline

\n"; @@ -792,7 +792,7 @@ int main(int argc, char** argv) { for (int i = y_min; i <= y_max; i++) { // i -> years in rows std::cout << "" << i + 1900 << " "; for (int j = 1; j <= 12; j++) { // j -> months in cols - count = std::count_if(user.cc.begin(), user.cc.end(), [i, j](Cache c) { return (c.date_hidden_tm.tm_year == i && c.date_hidden_tm.tm_mon == j - 1); }); + count = std::count_if(user.cc.begin(), user.cc.end(), [i, j](const Cache& c) { return (c.date_hidden_tm.tm_year == i && c.date_hidden_tm.tm_mon == j - 1); }); std::cout << "" << count << ""; } std::cout << "\n"; diff --git a/geostat_cli.cpp b/geostat_cli.cpp index 8ba92a1..89e8c56 100644 --- a/geostat_cli.cpp +++ b/geostat_cli.cpp @@ -260,7 +260,7 @@ int main(int argc, char** argv) { for (int i = 2; i <= 10; i++) { // i -> diff in rows std::cout << std::setw(5) << i / 2.0; for (int j = 2; j <= 10; j++) { // j -> terr in cols - dt_table[i][j] = std::count_if(user.cc.begin(), user.cc.end(), [i, j](Cache c) { return (c.diff == i / 2.0 && c.terr == j / 2.0); }); + dt_table[i][j] = std::count_if(user.cc.begin(), user.cc.end(), [i, j](const Cache& c) { return (c.diff == i / 2.0 && c.terr == j / 2.0); }); std::cout << std::setw(5) << dt_table[i][j]; } std::cout << '\n'; @@ -268,7 +268,7 @@ int main(int argc, char** argv) { } } else { if (show_list) { - for (auto el : user.cc) + for (const auto& el : user.cc) el.show(); } } diff --git a/ocdb.cpp b/ocdb.cpp index 32c1d95..66e1344 100644 --- a/ocdb.cpp +++ b/ocdb.cpp @@ -485,7 +485,7 @@ std::map OCdb::get_region_stats() { throw 0; } - for (auto reg : regions) { + for (const auto& reg : regions) { sqlite3_bind_text(stmt, 1, reg.c_str(), -1, nullptr); res = sqlite3_step(stmt); if (res != SQLITE_ROW) { diff --git a/user.cpp b/user.cpp index c558997..b27c8e4 100644 --- a/user.cpp +++ b/user.cpp @@ -212,3 +212,10 @@ void User::header() const { if (!ocuk_user.empty()) std::cout << "\"OCuk\" " << ocuk_user << "
\n"; } + +std::string User::user_link(std::string name) const { + if (!ocpl_user_uuid.empty()) + return "" + name + ""; + else + return name; +} diff --git a/user.h b/user.h index 92e8cec..00f3d10 100644 --- a/user.h +++ b/user.h @@ -65,4 +65,6 @@ public: void prepare_lists_of_caches(); // Prepare sorted list of caches, excluding moving caches void header() const; + + std::string user_link(std::string name) const; };