cppcheck partial cleanup

master
Tomasz Golinski 2022-07-13 18:31:01 +02:00
rodzic 89e9b4d8c6
commit d673bdd7b9
5 zmienionych plików z 68 dodań i 68 usunięć

Wyświetl plik

@ -309,7 +309,7 @@ int main(int argc, char** argv) {
"zachodniopomorskie" }); "zachodniopomorskie" });
// Prepare sorted list of caches, excluding moving caches // Prepare sorted list of caches, excluding moving caches
std::map<std::string, int> dates; // std::map<std::string, int> dates;
Date_Caches sorted_caches; Date_Caches sorted_caches;
pCaches fcc; pCaches fcc;
@ -317,7 +317,7 @@ int main(int argc, char** argv) {
for (auto& i : cc) { for (auto& i : cc) {
poland.locate(i); poland.locate(i);
dates[i.date]++; // dates[i.date]++;
if (i.type != "Moving" && i.type != "Own") { if (i.type != "Moving" && i.type != "Own") {
sorted_caches.insert({ i.date_t, &i }); sorted_caches.insert({ i.date_t, &i });
fcc.push_back(&i); fcc.push_back(&i);

116
okapi.cpp
Wyświetl plik

@ -80,9 +80,9 @@ void Okapi::curl_post(const std::string& url, const std::string& post) const {
} }
void Okapi::get_user_caches_json(const std::string& uuid, int count, int offset) const { void Okapi::get_user_caches_json(const std::string& uuid, int count, int offset) const {
std::string service = url + OKAPI_logs; std::string api_service = url + OKAPI_logs;
std::string query = "consumer_key=" + key + "&user_uuid=" + uuid + "&fields=cache_code|type|date|was_recommended&limit=" + std::to_string(count) + "&offset=" + std::to_string(offset); std::string query = "consumer_key=" + key + "&user_uuid=" + uuid + "&fields=cache_code|type|date|was_recommended&limit=" + std::to_string(count) + "&offset=" + std::to_string(offset);
curl_post(service, query); curl_post(api_service, query);
} }
// std::string Okapi::get_cache_json(std::string code) { // std::string Okapi::get_cache_json(std::string code) {
@ -92,15 +92,15 @@ void Okapi::get_user_caches_json(const std::string& uuid, int count, int offset)
// } // }
void Okapi::get_caches_json(const std::string& codes) const { void Okapi::get_caches_json(const std::string& codes) const {
std::string service = url + OKAPI_caches; std::string api_service = url + OKAPI_caches;
std::string query = "consumer_key=" + key + "&cache_codes=" + codes + "&fields=code|name|location|type|status|difficulty|terrain|owner|region|country2|size2|date_created|recommendations|rating|founds|status|internal_id"; std::string query = "consumer_key=" + key + "&cache_codes=" + codes + "&fields=code|name|location|type|status|difficulty|terrain|owner|region|country2|size2|date_created|recommendations|rating|founds|status|internal_id";
curl_post(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 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(service, query); curl_post(api_service, query);
} }
// Cache Okapi::get_cache(std::string code) { // Cache Okapi::get_cache(std::string code) {
@ -255,9 +255,9 @@ Caches Okapi::get_user_caches(const std::string& uuid, int count) const {
} }
int Okapi::get_user_caches_no(const std::string& uuid) const { int Okapi::get_user_caches_no(const std::string& uuid) const {
std::string service = url + OKAPI_user; std::string api_service = url + OKAPI_user;
std::string query = "consumer_key=" + key + "&user_uuid=" + uuid + "&fields=caches_hidden"; std::string query = "consumer_key=" + key + "&user_uuid=" + uuid + "&fields=caches_hidden";
curl_post(service, query); curl_post(api_service, query);
json j = json::parse(curl_output); json j = json::parse(curl_output);
return j["caches_hidden"]; return j["caches_hidden"];
} }
@ -269,71 +269,71 @@ void Okapi::update_caches(Caches& cc) const {
cc = get_caches(codes); cc = get_caches(codes);
} }
void Okapi::update_caches_ratings(Caches& cc) const { // void Okapi::update_caches_ratings(Caches& cc) const {
std::map<std::string, Cache*> pcc; // std::map<std::string, Cache*> pcc;
std::string code; // std::string code;
//
uint k; // uint k;
std::string codes_list; // std::string codes_list;
codes_list.reserve(MAX_CACHES * 8); // maximum of MAX_CACHES codes, 7 chars per code plus a separator // codes_list.reserve(MAX_CACHES * 8); // maximum of MAX_CACHES codes, 7 chars per code plus a separator
//
auto it = cc.begin(); // auto it = cc.begin();
while (it != cc.end()) { // while (it != cc.end()) {
k = 0; // k = 0;
//
while (it != cc.end() && k < MAX_CACHES) { // while (it != cc.end() && k < MAX_CACHES) {
codes_list += it->code; // codes_list += it->code;
codes_list += '|'; // codes_list += '|';
pcc[it->code] = &*it; // pcc[it->code] = &*it;
it++; // it++;
k++; // k++;
} // }
codes_list.pop_back(); // remove trailing '|' // codes_list.pop_back(); // remove trailing '|'
//
get_caches_ratings_json(codes_list); // get_caches_ratings_json(codes_list);
json j = json::parse(curl_output); // json j = json::parse(curl_output);
codes_list.clear(); // codes_list.clear();
//
for (auto& el : j.items()) { // for (auto& el : j.items()) {
code = el.value()["code"]; // code = el.value()["code"];
pcc[code]->fav = el.value()["recommendations"]; // pcc[code]->fav = el.value()["recommendations"];
if (!el.value()["rating"].is_null()) pcc[code]->rating = el.value()["rating"]; // if (!el.value()["rating"].is_null()) pcc[code]->rating = el.value()["rating"];
//
if (el.value()["status"] == "Available") // if (el.value()["status"] == "Available")
pcc[code]->status = ok; // pcc[code]->status = ok;
else if (el.value()["status"] == "Temporarily unavailable") // else if (el.value()["status"] == "Temporarily unavailable")
pcc[code]->status = disabled; // pcc[code]->status = disabled;
else if (el.value()["status"] == "Archived") // else if (el.value()["status"] == "Archived")
pcc[code]->status = archived; // pcc[code]->status = archived;
else // else
pcc[code]->status = unknown; // pcc[code]->status = unknown;
} // }
} // }
} // }
std::string Okapi::get_uuid(const std::string& username, uint* id) const { std::string Okapi::get_uuid(const std::string& username, uint* id) const {
std::string service = url + OKAPI_username; std::string api_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";
curl_free(user_esc); curl_free(user_esc);
curl_post(service, query); curl_post(api_service, query);
json j = json::parse(curl_output); json j = json::parse(curl_output);
if (id) *id = j["internal_id"]; if (id) *id = j["internal_id"];
return j["uuid"]; return j["uuid"];
} }
std::string Okapi::get_profile_url(const std::string& uuid) const { std::string Okapi::get_profile_url(const std::string& uuid) const {
std::string service = url + OKAPI_user; std::string api_service = url + OKAPI_user;
std::string query = "consumer_key=" + key + "&user_uuid=" + uuid + "&fields=profile_url"; std::string query = "consumer_key=" + key + "&user_uuid=" + uuid + "&fields=profile_url";
curl_post(service, query); curl_post(api_service, query);
json j = json::parse(curl_output); json j = json::parse(curl_output);
return j["profile_url"]; return j["profile_url"];
} }
std::string Okapi::get_changelog_json(int revision) const { std::string Okapi::get_changelog_json(int revision) const {
std::string service = url + OKAPI_changelog; std::string api_service = url + OKAPI_changelog;
std::string query = "consumer_key=" + key + "&since=" + std::to_string(revision); std::string query = "consumer_key=" + key + "&since=" + std::to_string(revision);
curl_post(service, query); curl_post(api_service, query);
return curl_output; return curl_output;
} }
@ -357,8 +357,8 @@ void Okapi::get_ftf(uint uid, Caches& cc) const {
for (auto& el : j.items()) { for (auto& el : j.items()) {
if (el.value().is_null()) continue; if (el.value().is_null()) continue;
uint 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 c = std::find_if(cc.begin(), cc.end(), [&](const auto& a) { return a.internal_id == id; });
if (res != std::end(cc)) if (c != std::end(cc))
res->ftf = 1; c->ftf = 1;
} }
} }

Wyświetl plik

@ -39,7 +39,7 @@ public:
std::string get_changelog_json(int revision) const; std::string get_changelog_json(int revision) const;
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, uint* 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(uint uid, Caches& cc) const; void get_ftf(uint uid, Caches& cc) const;

Wyświetl plik

@ -39,17 +39,17 @@ std::map<std::string, ContourData*> Region::parse_geojson(const std::string& jso
std::ifstream file(json_file); std::ifstream file(json_file);
json j; json j;
file >> j; file >> j;
std::string name; std::string reg_name;
std::map<std::string, ContourData*> rr; std::map<std::string, ContourData*> rr;
for (auto& el : j["features"].items()) { for (auto& el : j["features"].items()) {
if (el.value()["properties"]["alltags"].count("short_name") > 0) if (el.value()["properties"]["alltags"].count("short_name") > 0)
name = el.value()["properties"]["alltags"]["short_name"]; reg_name = el.value()["properties"]["alltags"]["short_name"];
else if (el.value()["properties"].count("localname") > 0) else if (el.value()["properties"].count("localname") > 0)
name = el.value()["properties"]["localname"]; reg_name = el.value()["properties"]["localname"];
else if (el.value()["properties"].count("name") > 0) else if (el.value()["properties"].count("name") > 0)
name = el.value()["properties"]["name"]; reg_name = el.value()["properties"]["name"];
else { else {
Debug(1) << "Unknown name for an object, skipping"; Debug(1) << "Unknown name for an object, skipping";
continue; continue;
@ -58,8 +58,8 @@ std::map<std::string, ContourData*> Region::parse_geojson(const std::string& jso
for (auto& el2 : el.value()["geometry"]["coordinates"][0][0].items()) { for (auto& el2 : el.value()["geometry"]["coordinates"][0][0].items()) {
cont->add_point(Position(el2.value()[1], el2.value()[0])); cont->add_point(Position(el2.value()[1], el2.value()[0]));
} }
Debug(3) << "Parsed region " << name; Debug(3) << "Parsed region " << reg_name;
rr[name] = cont; rr[reg_name] = cont;
} }
return rr; return rr;
} }

Wyświetl plik

@ -40,7 +40,7 @@ private:
std::string name; std::string name;
std::vector<Region*> subregions; std::vector<Region*> subregions;
std::map<std::string, ContourData*> parse_geojson(const std::string& json_file); static std::map<std::string, ContourData*> parse_geojson(const std::string& json_file);
public: public:
Region(ContourData* contour, const std::string& name) : contour(contour), name(name) {} Region(ContourData* contour, const std::string& name) : contour(contour), name(name) {}