diff --git a/api.h b/api.h index ecd7d8e..4ffff67 100644 --- a/api.h +++ b/api.h @@ -12,10 +12,4 @@ public: // virtual Cache get_cache(std::string code) = 0; // virtual Caches get_caches(std::vector 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)) }; - } }; diff --git a/cache.cpp b/cache.cpp index 59e5f94..45488ba 100644 --- a/cache.cpp +++ b/cache.cpp @@ -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; } diff --git a/cache.h b/cache.h index 3104b8b..f6735e7 100644 --- a/cache.h +++ b/cache.h @@ -48,6 +48,7 @@ public: Position() = default; Position(float y, float x) : lat(y), lon(x) {} + explicit Position(std::string loc); }; class Cache { diff --git a/ocdb.cpp b/ocdb.cpp index f3557a4..cafb76f 100644 --- a/ocdb.cpp +++ b/ocdb.cpp @@ -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(sqlite3_column_text(stmt, 0)); - if (sqlite3_column_text(stmt, 1)) c.pos = get_lat_lon(reinterpret_cast(sqlite3_column_text(stmt, 1))); + if (sqlite3_column_text(stmt, 1)) c.pos = Position(reinterpret_cast(sqlite3_column_text(stmt, 1))); if (sqlite3_column_text(stmt, 2)) c.name = reinterpret_cast(sqlite3_column_text(stmt, 2)); if (sqlite3_column_text(stmt, 3)) c.region = reinterpret_cast(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(sqlite3_column_text(stmt, 0)); - if (sqlite3_column_text(stmt, 1)) c.pos = get_lat_lon(reinterpret_cast(sqlite3_column_text(stmt, 1))); + if (sqlite3_column_text(stmt, 1)) c.pos = Position(reinterpret_cast(sqlite3_column_text(stmt, 1))); if (sqlite3_column_text(stmt, 2)) c.type = reinterpret_cast(sqlite3_column_text(stmt, 2)); if (sqlite3_column_text(stmt, 3)) c.size = reinterpret_cast(sqlite3_column_text(stmt, 3)); c.diff = sqlite3_column_int(stmt, 4)/2.0; diff --git a/okapi.cpp b/okapi.cpp index 5ba3cf3..974f0c7 100644 --- a/okapi.cpp +++ b/okapi.cpp @@ -152,7 +152,7 @@ Caches Okapi::get_caches(const std::set& 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"];