Change some int to uint and thus silence warnings

master
Tomasz Golinski 2022-07-13 18:30:26 +02:00
rodzic 87b35c5594
commit 89e9b4d8c6
7 zmienionych plików z 44 dodań i 20 usunięć

12
cache.h
Wyświetl plik

@ -38,8 +38,8 @@ enum Status {
unknown unknown
}; };
const int Earth_radius = 6378; const uint Earth_radius = 6378;
const int Moon_dist = 384400; const uint Moon_dist = 384400;
class Position { class Position {
public: public:
@ -54,15 +54,15 @@ public:
class Cache { class Cache {
public: public:
std::string code; std::string code;
int internal_id; uint internal_id;
Position pos; Position pos;
std::string name; std::string name;
Status status; Status status;
std::string size; std::string size;
float diff = 0; float diff = 0;
float terr = 0; float terr = 0;
int fav = 0; uint fav = 0;
int founds = 0; uint founds = 0;
float rating = 0; float rating = 0;
bool recommended = 0; // was the cache recommended by that user? bool recommended = 0; // was the cache recommended by that user?
std::string type; std::string type;
@ -86,7 +86,7 @@ public:
std::string date_hidden; std::string date_hidden;
int age_when_found = -1; int age_when_found = -1;
int age_now = -1; int age_now = -1;
int trail = 0; uint trail = 0;
bool ftf = 0; bool ftf = 0;
void set_date(const std::tm& t); void set_date(const std::tm& t);

Wyświetl plik

@ -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 max_str = 0;
int cur_str = 0; int cur_str = 0;
@ -249,7 +249,7 @@ int find_streak(const Date_Caches& cc, std::time_t& start) {
return max_str; return max_str;
} }
long int get_num(char c, char* opt) { uint get_num(char c, char* opt) {
try { try {
if (std::stoi(opt) > 0) { if (std::stoi(opt) > 0) {
return std::stoi(opt); return std::stoi(opt);
@ -276,6 +276,12 @@ void average_html(const Caches& cc, int Cache::*ptr, const std::string& caption)
std::cout << "</div>\n"; std::cout << "</div>\n";
} }
void average_html(const Caches& cc, uint Cache::*ptr, const std::string& caption) {
std::cout << "<div class=\"basic_stats\">\n";
std::cout << "Average " << caption << ": <span class=\"value\">" << average(cc, ptr) << "</span><br>\n";
std::cout << "</div>\n";
}
float average(const Caches& cc, float Cache::*ptr) { 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(); 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(); 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) { void sum_html(const Caches& cc, float Cache::*ptr, const std::string& caption) {
std::cout << "<div class=\"basic_stats\">\n"; std::cout << "<div class=\"basic_stats\">\n";
std::cout << "Total " << caption << ": <span class=\"value\">" << sum(cc, ptr) << "</span><br>\n"; std::cout << "Total " << caption << ": <span class=\"value\">" << sum(cc, ptr) << "</span><br>\n";
@ -296,6 +306,12 @@ void sum_html(const Caches& cc, int Cache::*ptr, const std::string& caption) {
std::cout << "</div>\n"; std::cout << "</div>\n";
} }
void sum_html(const Caches& cc, uint Cache::*ptr, const std::string& caption) {
std::cout << "<div class=\"basic_stats\">\n";
std::cout << "Total " << caption << ": <span class=\"value\">" << sum(cc, ptr) << "</span><br>\n";
std::cout << "</div>\n";
}
float sum(const Caches& cc, float Cache::*ptr) { 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; }); 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; }); 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<bool(const Cache& c)> test) { int count_caches(const Caches& cc, std::string& codes, std::function<bool(const Cache& c)> test) {
int count = 0; int count = 0;
codes.clear(); codes.clear();

Wyświetl plik

@ -13,19 +13,23 @@ void show_histogram(const std::map<std::string, int>& 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_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); 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, 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, 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, float Cache::*ptr);
float average(const Caches& cc, int 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, 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, 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); float sum(const Caches& cc, float Cache::*ptr);
int sum(const Caches& cc, int 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<bool(const Cache& c)> test); int count_caches(const Caches& cc, std::string& codes, std::function<bool(const Cache& c)> test);

Wyświetl plik

@ -201,7 +201,7 @@ int main(int argc, char** argv) {
if (use_oc) { if (use_oc) {
if (!ocpl_user_uuid.empty() || !ocpl_user.empty()) { if (!ocpl_user_uuid.empty() || !ocpl_user.empty()) {
Okapi OCpl(ocpl_url, ocpl_key); Okapi OCpl(ocpl_url, ocpl_key);
int uid; uint uid;
if (!ocpl_user.empty()) ocpl_user_uuid = OCpl.get_uuid(ocpl_user, &uid); if (!ocpl_user.empty()) ocpl_user_uuid = OCpl.get_uuid(ocpl_user, &uid);
Caches tmp = OCpl.get_user_caches(ocpl_user_uuid, 0); Caches tmp = OCpl.get_user_caches(ocpl_user_uuid, 0);

Wyświetl plik

@ -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; std::string service = url + OKAPI_username;
char* user_esc = curl_easy_escape(curl, username.c_str(), username.size()); 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"; 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; return curl_output;
} }
void Okapi::get_ftf(int id, Caches& cc) const { void Okapi::get_ftf(uint uid, Caches& cc) const {
std::string url = "https://opencaching.pl/UserProfile/getUserFtfsAjax/" + std::to_string(id); std::string url = "https://opencaching.pl/UserProfile/getUserFtfsAjax/" + std::to_string(uid);
CURLcode res; CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); 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); json j = json::parse(curl_output);
for (auto& el : j.items()) { for (auto& el : j.items()) {
if (el.value().is_null()) continue; if (el.value().is_null()) continue;
int id = std::stoi(el.value()["cache_id"].get<std::string>()); uint id = std::stoi(el.value()["cache_id"].get<std::string>());
auto res = std::find_if(cc.begin(), cc.end(), [&](const auto& a) { return a.internal_id == id; }); auto res = std::find_if(cc.begin(), cc.end(), [&](const auto& a) { return a.internal_id == id; });
if (res != std::end(cc)) if (res != std::end(cc))
res->ftf = 1; res->ftf = 1;

Wyświetl plik

@ -40,7 +40,7 @@ public:
void update_caches(Caches& cc) const; void update_caches(Caches& cc) const;
void update_caches_ratings(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; 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;
}; };

Wyświetl plik

@ -12,14 +12,14 @@ class Caches_in_Powertrails;
class Powertrail { class Powertrail {
public: public:
int number; uint number;
std::string name; std::string name;
std::tm date; std::tm date;
std::string date_str; std::string date_str;
int treshold_perc; uint treshold_perc;
std::unordered_set<std::string> caches; std::unordered_set<std::string> caches;
int found = 0; uint found = 0;
bool completed = 0; bool completed = 0;
}; };