Some cppcheck fixes

master
Tomasz Golinski 2023-08-30 22:43:49 +02:00
rodzic 868b62bb2e
commit 2a2a77caf3
7 zmienionych plików z 21 dodań i 21 usunięć

Wyświetl plik

@ -172,11 +172,11 @@ void show_nested_histogram(const pCaches& fcc, std::string Cache::*ptr, std::str
if (own.first.empty()) own.first = "[unknown]"; if (own.first.empty()) own.first = "[unknown]";
if (i < HIST_MAX) { if (i < HIST_MAX) {
std::map<std::string, int> subhistogram; std::map<std::string, int> subhistogram;
std::vector<std::pair<std::string, int>> subpairs;
for (auto el : fcc) for (auto el : fcc)
if (el->*ptr == own.first && !(el->*ptr2).empty()) //TODO problem with [unknown] if (el->*ptr == own.first && !(el->*ptr2).empty()) //TODO problem with [unknown]
subhistogram[el->*ptr2]++; subhistogram[el->*ptr2]++;
if (!subhistogram.empty()) { if (!subhistogram.empty()) {
std::vector<std::pair<std::string, int>> subpairs;
std::cout << "<details class=\"nested\"><summary class=\"bar\" style=\"--percent: " << 100 * own.second / max << "%;\"><span class=\"text\">" << own.first << ": " << own.second << "</span></summary>\n"; std::cout << "<details class=\"nested\"><summary class=\"bar\" style=\"--percent: " << 100 * own.second / max << "%;\"><span class=\"text\">" << own.first << ": " << own.second << "</span></summary>\n";
std::copy(subhistogram.begin(), subhistogram.end(), std::back_inserter(subpairs)); std::copy(subhistogram.begin(), subhistogram.end(), std::back_inserter(subpairs));
if (sort_by_val) if (sort_by_val)

Wyświetl plik

@ -12,7 +12,7 @@ using json = nlohmann::json;
// using namespace std::literals::string_literals; // using namespace std::literals::string_literals;
OCdb::OCdb(const Service service) { OCdb::OCdb(const Service service) {
int res = 0; int res;
switch (service) { switch (service) {
case ocpl: case ocpl:
@ -271,19 +271,19 @@ bool OCdb::update_log(const json& j) {
return 1; return 1;
sql = "INSERT INTO logs (uuid,"; sql = "INSERT INTO logs (uuid,";
for (auto& i : fields) for (const auto& i : fields)
sql += i.first + ','; sql += i.first + ',';
for (auto& i : fields2) for (const auto& i : fields2)
sql += i.first + ','; sql += i.first + ',';
sql.pop_back(); sql.pop_back();
sql += ") VALUES ('" + uuid + "',"; sql += ") VALUES ('" + uuid + "',";
for (__attribute__((unused)) auto& i : fields) for (__attribute__((unused)) const auto& i : fields)
sql += "?,"; sql += "?,";
for (__attribute__((unused)) auto& i : fields2) for (__attribute__((unused)) const auto& i : fields2)
sql += "?,"; sql += "?,";
sql.pop_back(); sql.pop_back();
sql += ") ON CONFLICT(uuid) DO UPDATE SET "; sql += ") ON CONFLICT(uuid) DO UPDATE SET ";
for (auto& i : fields) for (const auto& i : fields)
sql += i.first + "=excluded." + i.first + ','; sql += i.first + "=excluded." + i.first + ',';
sql.pop_back(); sql.pop_back();
sql += ';'; sql += ';';
@ -295,10 +295,10 @@ bool OCdb::update_log(const json& j) {
return 0; return 0;
} }
int n = 1; int n = 1;
for (auto& i : fields) { for (const auto& i : fields) {
sqlite3_bind_text(stmt, n++, i.second.c_str(), -1, nullptr); sqlite3_bind_text(stmt, n++, i.second.c_str(), -1, nullptr);
} }
for (auto& i : fields2) { for (const auto& i : fields2) {
sqlite3_bind_int(stmt, n++, i.second); sqlite3_bind_int(stmt, n++, i.second);
} }
res = sqlite3_step(stmt); res = sqlite3_step(stmt);

Wyświetl plik

@ -108,11 +108,11 @@ void Okapi::get_caches_json(const std::string& codes) const {
curl_post(api_service, query); curl_post(api_service, query);
} }
void Okapi::get_caches_ratings_json(const std::string& codes) const { // void Okapi::get_caches_ratings_json(const std::string& codes) const {
std::string api_service = url + OKAPI_caches; // std::string api_service = url + OKAPI_caches;
std::string query = "consumer_key=" + key + "&cache_codes=" + codes + "&fields=code|recommendations|rating|status"; // std::string query = "consumer_key=" + key + "&cache_codes=" + codes + "&fields=code|recommendations|rating|status";
curl_post(api_service, query); // curl_post(api_service, query);
} // }
// Cache Okapi::get_cache(std::string code) { // Cache Okapi::get_cache(std::string code) {
// std::string output = get_cache_json(code); // std::string output = get_cache_json(code);
@ -355,10 +355,10 @@ std::string Okapi::get_changelog_json(int revision) const {
} }
void Okapi::get_ftf(uint uid, Caches& cc) const { void Okapi::get_ftf(uint uid, Caches& cc) const {
std::string url = "https://opencaching.pl/UserProfile/getUserFtfsAjax/" + std::to_string(uid); std::string ftf_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, ftf_url.c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, ""); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "");
curl_output.clear(); curl_output.clear();

Wyświetl plik

@ -23,7 +23,7 @@ private:
void get_user_caches_json(const std::string& uuid, int count = 0, int offset = 0) const; void get_user_caches_json(const std::string& uuid, int count = 0, int offset = 0) const;
// std::string get_cache_json(std::string code) const; // std::string get_cache_json(std::string code) const;
void get_caches_json(const std::string& codes) const; void get_caches_json(const std::string& codes) const;
void get_caches_ratings_json(const std::string& codes) const; // void get_caches_ratings_json(const std::string& codes) const;
const static int MAX_LOGS = 1000; const static int MAX_LOGS = 1000;
const static int MAX_CACHES = 500; const static int MAX_CACHES = 500;
@ -43,7 +43,7 @@ private:
constexpr static auto ocuk_url = "https://opencache.uk/okapi/"; constexpr static auto ocuk_url = "https://opencache.uk/okapi/";
public: public:
Okapi(const Service serv); explicit Okapi(const Service serv);
~Okapi(); ~Okapi();
// Cache get_cache(std::string code); // Cache get_cache(std::string code);

Wyświetl plik

@ -69,7 +69,7 @@ class Caches_in_Powertrails {
public: public:
std::unordered_map<std::string, int> data; std::unordered_map<std::string, int> data;
Caches_in_Powertrails(const PowertrailDB& db); explicit Caches_in_Powertrails(const PowertrailDB& db);
Caches_in_Powertrails(){}; Caches_in_Powertrails(){};
void read_from_json(std::string file); void read_from_json(std::string file);

Wyświetl plik

@ -198,7 +198,7 @@ void User::prepare_lists_of_caches() {
} }
} }
void User::header() { void User::header() const {
if (!ocpl_user.empty()) if (!ocpl_user.empty())
std::cout << "<img alt=\"OCpl\" src=\"" << flag_pl << "\"> <a href=\"" << ocpl_user_profile << "\">" << ocpl_user << "</a><br>\n"; std::cout << "<img alt=\"OCpl\" src=\"" << flag_pl << "\"> <a href=\"" << ocpl_user_profile << "\">" << ocpl_user << "</a><br>\n";
if (!ocde_user.empty()) if (!ocde_user.empty())

2
user.h
Wyświetl plik

@ -64,5 +64,5 @@ public:
void get_caches(); void get_caches();
void prepare_lists_of_caches(); // Prepare sorted list of caches, excluding moving caches void prepare_lists_of_caches(); // Prepare sorted list of caches, excluding moving caches
void header(); void header() const;
}; };