kopia lustrzana https://gitlab.com/tomaszg/geostat
CPPCHECK: Change arguments to references, add some consts
rodzic
74efb8fa89
commit
2ab560f172
4
api.h
4
api.h
|
@ -11,10 +11,10 @@ public:
|
|||
|
||||
// virtual Cache get_cache(std::string code) = 0;
|
||||
// virtual Caches get_caches(std::vector<std::string> codes) = 0;
|
||||
virtual Caches get_user_caches(std::string uuid, int count = 0) = 0;
|
||||
virtual Caches get_user_caches(const std::string& uuid, int count = 0) const = 0;
|
||||
|
||||
protected:
|
||||
Position get_lat_lon(std::string loc) {
|
||||
Position get_lat_lon(std::string loc) const {
|
||||
int pos = loc.find("|");
|
||||
return { stof(loc.substr(0, pos)), stof(loc.substr(pos + 1)) };
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ void htmlencode(std::string& data) {
|
|||
data.swap(tmp);
|
||||
}
|
||||
|
||||
void show_histogram(const Caches& cc, std::string Cache::*ptr, std::string caption, bool html, bool sort_by_val) {
|
||||
void show_histogram(const Caches& cc, std::string Cache::*ptr, const std::string& caption, bool html, bool sort_by_val) {
|
||||
std::map<std::string, int> histogram;
|
||||
std::vector<std::pair<std::string, int>> pairs;
|
||||
|
||||
|
|
2
common.h
2
common.h
|
@ -4,6 +4,6 @@
|
|||
|
||||
void htmlencode(std::string& data);
|
||||
|
||||
void show_histogram(const Caches& cc, std::string Cache::*ptr, std::string caption, bool html = 0, bool sort_by_val = 1);
|
||||
void show_histogram(const Caches& cc, std::string Cache::*ptr, const std::string& caption, bool html = 0, bool sort_by_val = 1);
|
||||
|
||||
int find_streak(const std::multimap<std::time_t, const Cache*>& cc, std::tm& start);
|
||||
|
|
4
gpx.cpp
4
gpx.cpp
|
@ -30,7 +30,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
GPX::GPX(std::string path) {
|
||||
GPX::GPX(const std::string& path) {
|
||||
std::ifstream stream(path);
|
||||
if (stream.is_open()) {
|
||||
ReportDebug report;
|
||||
|
@ -49,7 +49,7 @@ GPX::~GPX() {
|
|||
delete root;
|
||||
}
|
||||
|
||||
Caches GPX::get_user_caches(__attribute__((unused)) std::string uuid, __attribute__((unused)) int count) {
|
||||
Caches GPX::get_user_caches(__attribute__((unused)) const std::string& uuid, __attribute__((unused)) int count) const {
|
||||
Caches list;
|
||||
|
||||
for (auto& el : items) {
|
||||
|
|
6
gpx.h
6
gpx.h
|
@ -16,9 +16,9 @@ private:
|
|||
gpx::GPX* root;
|
||||
|
||||
public:
|
||||
explicit GPX(std::string path);
|
||||
explicit GPX(const std::string& path);
|
||||
~GPX();
|
||||
|
||||
Cache get_cache(std::string code);
|
||||
Caches get_user_caches(std::string uuid = "", int count = 0);
|
||||
Cache get_cache(const std::string& code) const;
|
||||
Caches get_user_caches(const std::string& uuid = "", int count = 0) const;
|
||||
};
|
||||
|
|
4
heat.cpp
4
heat.cpp
|
@ -18,7 +18,7 @@ Heat::Heat(const Map* m) : mp(m) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void Heat::generate(std::string filename, Caches& points, int stamp_size, std::string theme) {
|
||||
void Heat::generate(const std::string& filename, const Caches& points, int stamp_size, const std::string& theme) {
|
||||
heatmap_t* hm = heatmap_new(mp->size_x, mp->size_y);
|
||||
heatmap_stamp_t* stamp = heatmap_stamp_gen(stamp_size);
|
||||
std::vector<unsigned char> image(mp->size_x * mp->size_y * 4);
|
||||
|
@ -46,7 +46,7 @@ void Heat::generate(std::string filename, Caches& points, int stamp_size, std::s
|
|||
// heatmap.write("geostat_heat.png");
|
||||
}
|
||||
|
||||
void Heat::generate_path(std::string filename, const Date_Caches& sorted) {
|
||||
void Heat::generate_path(const std::string& filename, const Date_Caches& sorted) {
|
||||
Magick::Image contour(mp->map_file);
|
||||
|
||||
contour.strokeColor("black");
|
||||
|
|
4
heat.h
4
heat.h
|
@ -13,6 +13,6 @@ private:
|
|||
public:
|
||||
explicit Heat(const Map* m);
|
||||
|
||||
void generate(std::string filename, Caches& points, int stamp_size, std::string theme = "soft");
|
||||
void generate_path(std::string filename, const Date_Caches& sorted);
|
||||
void generate(const std::string& filename, const Caches& points, int stamp_size, const std::string& theme = "soft");
|
||||
void generate_path(const std::string& filename, const Date_Caches& sorted);
|
||||
};
|
||||
|
|
2
maps.h
2
maps.h
|
@ -13,7 +13,7 @@ public:
|
|||
|
||||
const std::string map_file;
|
||||
|
||||
Map(int sx, int sy, float lat_mi, float lat_ma, float lon_mi, float lon_ma, std::string file) : size_x(sx), size_y(sy), lat_max(lat_ma), lat_min(lat_mi), lon_max(lon_ma), lon_min(lon_mi), map_file(file){};
|
||||
Map(int sx, int sy, float lat_mi, float lat_ma, float lon_mi, float lon_ma, const std::string& file) : size_x(sx), size_y(sy), lat_max(lat_ma), lat_min(lat_mi), lon_max(lon_ma), lon_min(lon_mi), map_file(file){};
|
||||
|
||||
bool contains(Position pos) const {
|
||||
return (pos.lon >= lon_min && pos.lon <= lon_max && pos.lat >= lat_min && pos.lat <= lat_max);
|
||||
|
|
22
ocdb.cpp
22
ocdb.cpp
|
@ -11,7 +11,7 @@
|
|||
using json = nlohmann::json;
|
||||
// using namespace std::literals::string_literals;
|
||||
|
||||
OCdb::OCdb(std::string db_file) {
|
||||
OCdb::OCdb(const std::string& db_file) {
|
||||
int res = 0;
|
||||
|
||||
res = sqlite3_open(db_file.c_str(), &db);
|
||||
|
@ -32,7 +32,7 @@ OCdb::~OCdb() {
|
|||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
bool OCdb::request(std::string req) {
|
||||
bool OCdb::request(const std::string& req) const {
|
||||
int res;
|
||||
|
||||
res = sqlite3_prepare_v2(db, req.c_str(), req.length() + 1, &stmt, NULL);
|
||||
|
@ -51,7 +51,7 @@ bool OCdb::request(std::string req) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
bool OCdb::init(std::string dump_path) {
|
||||
bool OCdb::init(const std::string& dump_path) {
|
||||
request("DELETE FROM caches;");
|
||||
request("DELETE FROM logs;");
|
||||
request("DELETE FROM revision;");
|
||||
|
@ -70,7 +70,7 @@ bool OCdb::init(std::string dump_path) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
bool OCdb::init_part(std::string json_file) {
|
||||
bool OCdb::init_part(const std::string& json_file) {
|
||||
Debug(2) << "Processing file: " << json_file << '\n';
|
||||
|
||||
std::ifstream file(json_file);
|
||||
|
@ -84,7 +84,7 @@ bool OCdb::init_part(std::string json_file) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
bool OCdb::update(Okapi& oc) {
|
||||
bool OCdb::update(const Okapi& oc) {
|
||||
if (revision == 0) {
|
||||
Debug(1) << "Cannot update database, you need to init it first with a full dump.\n";
|
||||
throw 1;
|
||||
|
@ -104,7 +104,7 @@ bool OCdb::update(Okapi& oc) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
bool OCdb::parse_item(json j) {
|
||||
bool OCdb::parse_item(const json& j) {
|
||||
if (j.count("object_type") > 0 && j["object_type"] == "geocache") {
|
||||
if (j.count("change_type") > 0 && j["change_type"] == "replace") {
|
||||
Debug(5) << "Inserting/updating cache " << j["object_key"]["code"].get<std::string>() << ".\n";
|
||||
|
@ -136,7 +136,7 @@ bool OCdb::parse_item(json j) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
bool OCdb::update_cache(json j) {
|
||||
bool OCdb::update_cache(const json& j) {
|
||||
// (code TEXT PRIMARY KEY, name TEXT, location TEXT, type TEXT, status TEXT, size TEXT, difficulty REAL, terrain REAL, country TEXT, region TEXT, owner TEXT)
|
||||
std::map<std::string, std::string> fields;
|
||||
std::map<std::string, float> fields2;
|
||||
|
@ -214,7 +214,7 @@ bool OCdb::update_cache(json j) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
bool OCdb::update_log(json j) {
|
||||
bool OCdb::update_log(const json& j) {
|
||||
// logs (uuid TEXT PRIMARY KEY, cache_code TEXT, date TEXT, user TEXT, type TEXT);"))
|
||||
std::map<std::string, std::string> fields;
|
||||
int res;
|
||||
|
@ -289,7 +289,7 @@ bool OCdb::read_revision() {
|
|||
return 1;
|
||||
}
|
||||
|
||||
Caches OCdb::get_user_caches_not_found(std::string uuid) {
|
||||
Caches OCdb::get_user_caches_not_found(const std::string& uuid) const {
|
||||
int res;
|
||||
Caches cc;
|
||||
Cache c;
|
||||
|
@ -321,7 +321,7 @@ Caches OCdb::get_user_caches_not_found(std::string uuid) {
|
|||
return cc;
|
||||
}
|
||||
|
||||
Caches OCdb::get_user_caches(std::string uuid, __attribute__((unused)) int count) {
|
||||
Caches OCdb::get_user_caches(const std::string& uuid, __attribute__((unused)) int count) const {
|
||||
int res;
|
||||
Caches cc;
|
||||
Cache c;
|
||||
|
@ -360,7 +360,7 @@ Caches OCdb::get_user_caches(std::string uuid, __attribute__((unused)) int count
|
|||
return cc;
|
||||
}
|
||||
|
||||
int OCdb::get_revision() {
|
||||
int OCdb::get_revision() const {
|
||||
return revision;
|
||||
}
|
||||
|
||||
|
|
24
ocdb.h
24
ocdb.h
|
@ -15,25 +15,25 @@ using json = nlohmann::json;
|
|||
class OCdb : public Api {
|
||||
private:
|
||||
sqlite3* db;
|
||||
sqlite3_stmt* stmt;
|
||||
mutable sqlite3_stmt* stmt;
|
||||
int revision;
|
||||
|
||||
bool request(std::string req);
|
||||
bool init_part(std::string json_file); // read db dump
|
||||
bool parse_item(json j);
|
||||
bool update_cache(json j);
|
||||
bool update_log(json j);
|
||||
bool request(const std::string& req) const;
|
||||
bool init_part(const std::string& json_file); // read db dump
|
||||
bool parse_item(const json& j);
|
||||
bool update_cache(const json& j);
|
||||
bool update_log(const json& j);
|
||||
bool read_revision();
|
||||
|
||||
public:
|
||||
explicit OCdb(std::string db_file);
|
||||
explicit OCdb(const std::string& db_file);
|
||||
~OCdb();
|
||||
|
||||
bool init(std::string json_file); // read db dump
|
||||
bool update(Okapi& oc); // apply changelog
|
||||
int get_revision();
|
||||
bool init(const std::string& json_file); // read db dump
|
||||
bool update(const Okapi& oc); // apply changelog
|
||||
int get_revision() const;
|
||||
void set_revision(int rev);
|
||||
|
||||
Caches get_user_caches_not_found(std::string uuid);
|
||||
Caches get_user_caches(std::string uuid, int count = 0);
|
||||
Caches get_user_caches_not_found(const std::string& uuid) const;
|
||||
Caches get_user_caches(const std::string& uuid, int count = 0) const;
|
||||
};
|
||||
|
|
20
okapi.cpp
20
okapi.cpp
|
@ -17,7 +17,7 @@ static const std::string OKAPI_username = "services/users/by_username";
|
|||
static const std::string OKAPI_user = "services/users/user";
|
||||
static const std::string OKAPI_changelog = "services/replicate/changelog";
|
||||
|
||||
Okapi::Okapi(std::string server_url, std::string consumer_key) : url(server_url), key(consumer_key) {
|
||||
Okapi::Okapi(const std::string& server_url, const std::string& consumer_key) : url(server_url), key(consumer_key) {
|
||||
if (url.find(".pl/") != std::string::npos)
|
||||
service = "OC.pl";
|
||||
if (url.find(".de/") != std::string::npos)
|
||||
|
@ -40,7 +40,7 @@ size_t Okapi::write_cb(char* ptr, __attribute__((unused)) size_t size, size_t nm
|
|||
return nmemb;
|
||||
}
|
||||
|
||||
std::string Okapi::curl_post(std::string url, std::string post) {
|
||||
std::string Okapi::curl_post(const std::string& url, const std::string& post) const {
|
||||
CURL* curl;
|
||||
CURLcode res;
|
||||
|
||||
|
@ -76,7 +76,7 @@ std::string Okapi::curl_post(std::string url, std::string post) {
|
|||
return output;
|
||||
}
|
||||
|
||||
std::string Okapi::get_user_caches_json(std::string uuid, int count, int offset) {
|
||||
std::string Okapi::get_user_caches_json(const std::string& uuid, int count, int offset) const {
|
||||
std::string service = url + OKAPI_logs;
|
||||
std::string query = "consumer_key=" + key + "&user_uuid=" + uuid + "&fields=cache_code|type|date&limit=" + std::to_string(count) + "&offset=" + std::to_string(offset);
|
||||
return curl_post(service, query);
|
||||
|
@ -88,7 +88,7 @@ std::string Okapi::get_user_caches_json(std::string uuid, int count, int offset)
|
|||
// return curl_post(service, query);
|
||||
// }
|
||||
|
||||
std::string Okapi::get_caches_json(std::string codes) {
|
||||
std::string Okapi::get_caches_json(const std::string& codes) const {
|
||||
std::string service = url + OKAPI_caches;
|
||||
std::string query = "consumer_key=" + key + "&cache_codes=" + codes + "&fields=code|name|location|type|status|difficulty|terrain|owner|region|size2|date_hidden|recommendations|founds";
|
||||
return curl_post(service, query);
|
||||
|
@ -117,11 +117,11 @@ std::string Okapi::get_caches_json(std::string codes) {
|
|||
// return c;
|
||||
// }
|
||||
|
||||
Caches Okapi::get_caches(std::map<std::string, std::tm> codes) {
|
||||
Caches Okapi::get_caches(const std::map<std::string, std::tm>& codes) const {
|
||||
Cache c;
|
||||
Caches cc;
|
||||
|
||||
uint k = 0;
|
||||
uint k;
|
||||
std::string codes_list;
|
||||
codes_list.reserve(500 * 7); // maximum of 500 codes, 6 chars per code plus a separator
|
||||
|
||||
|
@ -174,7 +174,7 @@ Caches Okapi::get_caches(std::map<std::string, std::tm> codes) {
|
|||
return cc;
|
||||
}
|
||||
|
||||
Caches Okapi::get_user_caches(std::string uuid, int count) {
|
||||
Caches Okapi::get_user_caches(const std::string& uuid, int count) const {
|
||||
Caches cc;
|
||||
std::map<std::string, std::tm> codes;
|
||||
json j;
|
||||
|
@ -219,21 +219,21 @@ Caches Okapi::get_user_caches(std::string uuid, int count) {
|
|||
return cc;
|
||||
}
|
||||
|
||||
std::string Okapi::get_uuid(std::string username) {
|
||||
std::string Okapi::get_uuid(const std::string& username) const {
|
||||
std::string service = url + OKAPI_username;
|
||||
std::string query = "consumer_key=" + key + "&username=" + username + "&fields=uuid";
|
||||
json j = json::parse(curl_post(service, query));
|
||||
return j["uuid"];
|
||||
}
|
||||
|
||||
std::string Okapi::get_profile_url(std::string uuid) {
|
||||
std::string Okapi::get_profile_url(const std::string& uuid) const {
|
||||
std::string service = url + OKAPI_user;
|
||||
std::string query = "consumer_key=" + key + "&user_uuid=" + uuid + "&fields=profile_url";
|
||||
json j = json::parse(curl_post(service, query));
|
||||
return j["profile_url"];
|
||||
}
|
||||
|
||||
std::string Okapi::get_changelog_json(int revision) {
|
||||
std::string Okapi::get_changelog_json(int revision) const {
|
||||
std::string service = url + OKAPI_changelog;
|
||||
std::string query = "consumer_key=" + key + "&since=" + std::to_string(revision);
|
||||
return curl_post(service, query);
|
||||
|
|
20
okapi.h
20
okapi.h
|
@ -14,19 +14,19 @@ private:
|
|||
std::string service;
|
||||
|
||||
static size_t write_cb(char* ptr, size_t size, size_t nmemb, void* userdata);
|
||||
std::string curl_post(std::string url, std::string post);
|
||||
std::string get_user_caches_json(std::string uuid, int count = 0, int offset = 0);
|
||||
// std::string get_cache_json(std::string code);
|
||||
std::string get_caches_json(std::string codes);
|
||||
std::string curl_post(const std::string& url, const std::string& post) const;
|
||||
std::string 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_caches_json(const std::string& codes) const;
|
||||
|
||||
public:
|
||||
Okapi(std::string server_url, std::string consumer_key);
|
||||
Okapi(const std::string& server_url, const std::string& consumer_key);
|
||||
|
||||
// Cache get_cache(std::string code);
|
||||
Caches get_caches(std::map<std::string, std::tm> codes);
|
||||
Caches get_user_caches(std::string uuid, int count = 0);
|
||||
std::string get_changelog_json(int revision);
|
||||
Caches get_caches(const std::map<std::string, std::tm>& codes) const;
|
||||
Caches get_user_caches(const std::string& uuid, int count = 0) const;
|
||||
std::string get_changelog_json(int revision) const;
|
||||
|
||||
std::string get_uuid(std::string username);
|
||||
std::string get_profile_url(std::string uuid);
|
||||
std::string get_uuid(const std::string& username) const;
|
||||
std::string get_profile_url(const std::string& uuid) const;
|
||||
};
|
||||
|
|
Ładowanie…
Reference in New Issue