Cppcheck: remove get_lat_lon function in Api class and morph it into a constructor of Position class

sql-rework
Tomasz Golinski 2020-07-06 17:13:30 +02:00
rodzic 67d05f0742
commit de2beddbee
5 zmienionych plików z 10 dodań i 9 usunięć

6
api.h
Wyświetl plik

@ -12,10 +12,4 @@ public:
// virtual Cache get_cache(std::string code) = 0;
// virtual Caches get_caches(std::vector<std::string> codes) = 0;
virtual Caches get_user_caches(const std::string& uuid, int count = 0) const = 0;
protected:
Position get_lat_lon(std::string loc) const {
int pos = loc.find("|");
return { stof(loc.substr(0, pos)), stof(loc.substr(pos + 1)) };
}
};

Wyświetl plik

@ -6,6 +6,12 @@
Position Cache::home;
Position::Position(std::string loc) {
int pos = loc.find("|");
lat = stof(loc.substr(0, pos));
lon = stof(loc.substr(pos + 1));
}
static float degtorad(float x) {
return x * M_PI / 180;
}

Wyświetl plik

@ -48,6 +48,7 @@ public:
Position() = default;
Position(float y, float x) : lat(y), lon(x) {}
explicit Position(std::string loc);
};
class Cache {

Wyświetl plik

@ -329,7 +329,7 @@ Caches OCdb::get_user_caches_not_found(const std::string& uuid) const {
while (res == SQLITE_ROW) {
Cache c;
if (sqlite3_column_text(stmt, 0)) c.code = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
if (sqlite3_column_text(stmt, 1)) c.pos = get_lat_lon(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 1)));
if (sqlite3_column_text(stmt, 1)) c.pos = Position(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 1)));
if (sqlite3_column_text(stmt, 2)) c.name = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 2));
if (sqlite3_column_text(stmt, 3)) c.region = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 3));
c.status = ok;
@ -365,7 +365,7 @@ Caches OCdb::get_user_caches(const std::string& uuid, __attribute__((unused)) in
while (res == SQLITE_ROW) {
Cache c;
if (sqlite3_column_text(stmt, 0)) c.code = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
if (sqlite3_column_text(stmt, 1)) c.pos = get_lat_lon(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 1)));
if (sqlite3_column_text(stmt, 1)) c.pos = Position(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 1)));
if (sqlite3_column_text(stmt, 2)) c.type = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 2));
if (sqlite3_column_text(stmt, 3)) c.size = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 3));
c.diff = sqlite3_column_int(stmt, 4)/2.0;

Wyświetl plik

@ -152,7 +152,7 @@ Caches Okapi::get_caches(const std::set<std::string>& codes) const {
c.terr = el.value()["terrain"];
c.owner = el.value()["owner"]["username"];
c.owner_uuid = el.value()["owner"]["uuid"];
c.pos = get_lat_lon(el.value()["location"]);
c.pos = Position(el.value()["location"]);
c.origin = service;
c.fav = el.value()["recommendations"];
c.founds = el.value()["founds"];