kopia lustrzana https://gitlab.com/tomaszg/geostat
Split out simple function to check and convert a c-string to a number
rodzic
f4c861867a
commit
d1fa8363d5
15
common.cpp
15
common.cpp
|
@ -130,3 +130,18 @@ int find_streak(const std::multimap<std::time_t, const Cache*>& cc, std::tm& sta
|
|||
|
||||
return max_str;
|
||||
}
|
||||
|
||||
long int get_num(char c, char* opt) {
|
||||
try {
|
||||
if (std::stoi(opt) > 0) {
|
||||
return std::stoi(opt);
|
||||
} else {
|
||||
std::cout << "Option \"-" << c << "\" requires a valid number as an argument\n";
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "Option \"-" << c << "\" requires a valid number as an argument\n";
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
|
2
common.h
2
common.h
|
@ -7,3 +7,5 @@ void htmlencode(std::string& data);
|
|||
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);
|
||||
|
||||
long int get_num(char c, char* opt);
|
||||
|
|
23
geostat.cpp
23
geostat.cpp
|
@ -80,17 +80,8 @@ int main(int argc, char** argv) {
|
|||
while ((o = getopt(argc, argv, "qNQg:o::p:d:u:n:r:k:H:s:m:eth?")) != -1)
|
||||
switch (o) {
|
||||
// case 'd':
|
||||
// try {
|
||||
// if (std::stoi(optarg) > 0) {
|
||||
// // Debug(1) << "Setting debug level to " << optarg;
|
||||
// Debug::set_debug_level(std::stoi(optarg));
|
||||
// }
|
||||
// }
|
||||
// catch (...) {
|
||||
// std::cout << "Option \"-d\" requires a valid number as an argument\n";
|
||||
// std::exit(EXIT_FAILURE);
|
||||
// }
|
||||
// break;
|
||||
// Debug::set_debug_level(get_num('d',optarg));
|
||||
// break;
|
||||
case 'g':
|
||||
gpx_file = optarg;
|
||||
break;
|
||||
|
@ -136,15 +127,7 @@ int main(int argc, char** argv) {
|
|||
heat_file = optarg;
|
||||
break;
|
||||
case 's':
|
||||
try {
|
||||
if (std::stoi(optarg) > 0) {
|
||||
heat_stamp_size = std::stoi(optarg);
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "Option \"-s\" requires a valid number as an argument\n";
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
heat_stamp_size = get_num('s',optarg);
|
||||
break;
|
||||
case 'm':
|
||||
heat_map = optarg;
|
||||
|
|
|
@ -85,17 +85,8 @@ int main(int argc, char** argv) {
|
|||
while ((o = getopt(argc, argv, "qNg:o::p:d:u:n:r:k:MDCOH:s:m:etLTYh?")) != -1)
|
||||
switch (o) {
|
||||
// case 'd':
|
||||
// try {
|
||||
// if (std::stoi(optarg) > 0) {
|
||||
// // Debug(1) << "Setting debug level to " << optarg;
|
||||
// Debug::set_debug_level(std::stoi(optarg));
|
||||
// }
|
||||
// }
|
||||
// catch (...) {
|
||||
// std::cout << "Option \"-d\" requires a valid number as an argument\n";
|
||||
// std::exit(EXIT_FAILURE);
|
||||
// }
|
||||
// break;
|
||||
// Debug::set_debug_level(get_num('d',optarg));
|
||||
// break;
|
||||
case 'g':
|
||||
gpx_file = optarg;
|
||||
break;
|
||||
|
@ -153,15 +144,7 @@ int main(int argc, char** argv) {
|
|||
heat_file = optarg;
|
||||
break;
|
||||
case 's':
|
||||
try {
|
||||
if (std::stoi(optarg) > 0) {
|
||||
heat_stamp_size = std::stoi(optarg);
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << "Option \"-s\" requires a valid number as an argument\n";
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
heat_stamp_size = get_num('s',optarg);
|
||||
break;
|
||||
case 'm':
|
||||
heat_map = optarg;
|
||||
|
|
Ładowanie…
Reference in New Issue