From 89e9b4d8c6cdb1c6885b57dfcae7033fff126c74 Mon Sep 17 00:00:00 2001 From: Tomasz Golinski Date: Wed, 13 Jul 2022 18:30:26 +0200 Subject: [PATCH] Change some int to uint and thus silence warnings --- cache.h | 12 ++++++------ common.cpp | 24 ++++++++++++++++++++++-- common.h | 8 ++++++-- geostat.cpp | 2 +- okapi.cpp | 8 ++++---- okapi.h | 4 ++-- powertrail.h | 6 +++--- 7 files changed, 44 insertions(+), 20 deletions(-) diff --git a/cache.h b/cache.h index fece0b9..b3bbfbc 100644 --- a/cache.h +++ b/cache.h @@ -38,8 +38,8 @@ enum Status { unknown }; -const int Earth_radius = 6378; -const int Moon_dist = 384400; +const uint Earth_radius = 6378; +const uint Moon_dist = 384400; class Position { public: @@ -54,15 +54,15 @@ public: class Cache { public: std::string code; - int internal_id; + uint internal_id; Position pos; std::string name; Status status; std::string size; float diff = 0; float terr = 0; - int fav = 0; - int founds = 0; + uint fav = 0; + uint founds = 0; float rating = 0; bool recommended = 0; // was the cache recommended by that user? std::string type; @@ -86,7 +86,7 @@ public: std::string date_hidden; int age_when_found = -1; int age_now = -1; - int trail = 0; + uint trail = 0; bool ftf = 0; void set_date(const std::tm& t); diff --git a/common.cpp b/common.cpp index 5172e50..32efeaa 100644 --- a/common.cpp +++ b/common.cpp @@ -209,7 +209,7 @@ void show_nested_histogram(const pCaches& fcc, std::string Cache::*ptr, std::str } } -int find_streak(const Date_Caches& cc, std::time_t& start) { +uint find_streak(const Date_Caches& cc, std::time_t& start) { int max_str = 0; int cur_str = 0; @@ -249,7 +249,7 @@ int find_streak(const Date_Caches& cc, std::time_t& start) { return max_str; } -long int get_num(char c, char* opt) { +uint get_num(char c, char* opt) { try { if (std::stoi(opt) > 0) { return std::stoi(opt); @@ -276,6 +276,12 @@ void average_html(const Caches& cc, int Cache::*ptr, const std::string& caption) std::cout << "\n"; } +void average_html(const Caches& cc, uint Cache::*ptr, const std::string& caption) { + std::cout << "
\n"; + std::cout << "Average " << caption << ": " << average(cc, ptr) << "
\n"; + std::cout << "
\n"; +} + float average(const Caches& cc, float Cache::*ptr) { return std::accumulate(cc.begin(), cc.end(), 0., [&](const float& a, const Cache& b) { return std::move(a) + b.*ptr; }) / cc.size(); } @@ -284,6 +290,10 @@ float average(const Caches& cc, int Cache::*ptr) { return 1.0 * std::accumulate(cc.begin(), cc.end(), 0, [&](const float& a, const Cache& b) { return std::move(a) + b.*ptr; }) / cc.size(); } +float average(const Caches& cc, uint Cache::*ptr) { + return 1.0 * std::accumulate(cc.begin(), cc.end(), 0, [&](const float& a, const Cache& b) { return std::move(a) + b.*ptr; }) / cc.size(); +} + void sum_html(const Caches& cc, float Cache::*ptr, const std::string& caption) { std::cout << "
\n"; std::cout << "Total " << caption << ": " << sum(cc, ptr) << "
\n"; @@ -296,6 +306,12 @@ void sum_html(const Caches& cc, int Cache::*ptr, const std::string& caption) { std::cout << "
\n"; } +void sum_html(const Caches& cc, uint Cache::*ptr, const std::string& caption) { + std::cout << "
\n"; + std::cout << "Total " << caption << ": " << sum(cc, ptr) << "
\n"; + std::cout << "
\n"; +} + float sum(const Caches& cc, float Cache::*ptr) { return std::accumulate(cc.begin(), cc.end(), 0., [&](const float& a, const Cache& b) { return std::move(a) + b.*ptr; }); } @@ -304,6 +320,10 @@ int sum(const Caches& cc, int Cache::*ptr) { return std::accumulate(cc.begin(), cc.end(), 0, [&](const int& a, const Cache& b) { return std::move(a) + b.*ptr; }); } +int sum(const Caches& cc, uint Cache::*ptr) { + return std::accumulate(cc.begin(), cc.end(), 0, [&](const int& a, const Cache& b) { return std::move(a) + b.*ptr; }); +} + int count_caches(const Caches& cc, std::string& codes, std::function test) { int count = 0; codes.clear(); diff --git a/common.h b/common.h index a1cf3a1..9cbc98b 100644 --- a/common.h +++ b/common.h @@ -13,19 +13,23 @@ void show_histogram(const std::map& data, const std::string& c void show_histogram(const pPowertrails& tt, const std::string& caption, bool html = 0, bool sort_by_val = 1); void show_nested_histogram(const pCaches& fcc, std::string Cache::*ptr, std::string Cache::*ptr2, const std::string& caption, bool html = 0, bool sort_by_val = 1); -int find_streak(const Date_Caches& cc, std::time_t& start); +uint find_streak(const Date_Caches& cc, std::time_t& start); -long int get_num(char c, char* opt); +uint get_num(char c, char* opt); void average_html(const Caches& cc, float Cache::*ptr, const std::string& caption); void average_html(const Caches& cc, int Cache::*ptr, const std::string& caption); +void average_html(const Caches& cc, uint Cache::*ptr, const std::string& caption); float average(const Caches& cc, float Cache::*ptr); float average(const Caches& cc, int Cache::*ptr); +float average(const Caches& cc, uint Cache::*ptr); void sum_html(const Caches& cc, float Cache::*ptr, const std::string& caption); void sum_html(const Caches& cc, int Cache::*ptr, const std::string& caption); +void sum_html(const Caches& cc, uint Cache::*ptr, const std::string& caption); float sum(const Caches& cc, float Cache::*ptr); int sum(const Caches& cc, int Cache::*ptr); +int sum(const Caches& cc, uint Cache::*ptr); int count_caches(const Caches& cc, std::string& codes, std::function test); diff --git a/geostat.cpp b/geostat.cpp index 98b6889..d9d71b1 100644 --- a/geostat.cpp +++ b/geostat.cpp @@ -201,7 +201,7 @@ int main(int argc, char** argv) { if (use_oc) { if (!ocpl_user_uuid.empty() || !ocpl_user.empty()) { Okapi OCpl(ocpl_url, ocpl_key); - int uid; + uint uid; if (!ocpl_user.empty()) ocpl_user_uuid = OCpl.get_uuid(ocpl_user, &uid); Caches tmp = OCpl.get_user_caches(ocpl_user_uuid, 0); diff --git a/okapi.cpp b/okapi.cpp index fa6f7cb..66e496b 100644 --- a/okapi.cpp +++ b/okapi.cpp @@ -311,7 +311,7 @@ void Okapi::update_caches_ratings(Caches& cc) const { } } -std::string Okapi::get_uuid(const std::string& username, int* id) const { +std::string Okapi::get_uuid(const std::string& username, uint* id) const { std::string service = url + OKAPI_username; char* user_esc = curl_easy_escape(curl, username.c_str(), username.size()); std::string query = "consumer_key=" + key + "&username=" + user_esc + "&fields=uuid|internal_id"; @@ -337,8 +337,8 @@ std::string Okapi::get_changelog_json(int revision) const { return curl_output; } -void Okapi::get_ftf(int id, Caches& cc) const { - std::string url = "https://opencaching.pl/UserProfile/getUserFtfsAjax/" + std::to_string(id); +void Okapi::get_ftf(uint uid, Caches& cc) const { + std::string url = "https://opencaching.pl/UserProfile/getUserFtfsAjax/" + std::to_string(uid); CURLcode res; curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); @@ -356,7 +356,7 @@ void Okapi::get_ftf(int id, Caches& cc) const { json j = json::parse(curl_output); for (auto& el : j.items()) { if (el.value().is_null()) continue; - int id = std::stoi(el.value()["cache_id"].get()); + uint id = std::stoi(el.value()["cache_id"].get()); auto res = std::find_if(cc.begin(), cc.end(), [&](const auto& a) { return a.internal_id == id; }); if (res != std::end(cc)) res->ftf = 1; diff --git a/okapi.h b/okapi.h index c0db747..0b59455 100644 --- a/okapi.h +++ b/okapi.h @@ -40,7 +40,7 @@ public: void update_caches(Caches& cc) const; void update_caches_ratings(Caches& cc) const; - std::string get_uuid(const std::string& username, int* id = nullptr) const; + std::string get_uuid(const std::string& username, uint* id = nullptr) const; std::string get_profile_url(const std::string& uuid) const; - void get_ftf(int id, Caches& cc) const; + void get_ftf(uint uid, Caches& cc) const; }; diff --git a/powertrail.h b/powertrail.h index 8633eba..f88b7e8 100644 --- a/powertrail.h +++ b/powertrail.h @@ -12,14 +12,14 @@ class Caches_in_Powertrails; class Powertrail { public: - int number; + uint number; std::string name; std::tm date; std::string date_str; - int treshold_perc; + uint treshold_perc; std::unordered_set caches; - int found = 0; + uint found = 0; bool completed = 0; };