kopia lustrzana https://gitlab.com/tomaszg/geostat
Templates for common functions like average or sum
rodzic
d673bdd7b9
commit
6de198b9c6
66
common.cpp
66
common.cpp
|
@ -264,63 +264,43 @@ uint get_num(char c, char* opt) {
|
|||
}
|
||||
}
|
||||
|
||||
void average_html(const Caches& cc, float Cache::*ptr, const std::string& caption) {
|
||||
template void average_html(const Caches& cc, float Cache::*ptr, const std::string& caption);
|
||||
template void average_html(const Caches& cc, uint Cache::*ptr, const std::string& caption);
|
||||
template void average_html(const Caches& cc, int Cache::*ptr, const std::string& caption);
|
||||
|
||||
template <typename T>
|
||||
void average_html(const Caches& cc, T Cache::*ptr, const std::string& caption) {
|
||||
std::cout << "<div class=\"basic_stats\">\n";
|
||||
std::cout << "Average " << caption << ": <span class=\"value\">" << average(cc, ptr) << "</span><br>\n";
|
||||
std::cout << "</div>\n";
|
||||
}
|
||||
|
||||
void average_html(const Caches& cc, int Cache::*ptr, const std::string& caption) {
|
||||
std::cout << "<div class=\"basic_stats\">\n";
|
||||
std::cout << "Average " << caption << ": <span class=\"value\">" << average(cc, ptr) << "</span><br>\n";
|
||||
std::cout << "</div>\n";
|
||||
template float average(const Caches& cc, float Cache::*ptr);
|
||||
template float average(const Caches& cc, int Cache::*ptr);
|
||||
template float average(const Caches& cc, uint Cache::*ptr);
|
||||
|
||||
template <typename T>
|
||||
float average(const Caches& cc, T Cache::*ptr) {
|
||||
return 1.0 * std::accumulate(cc.begin(), cc.end(), 0., [&](const float& a, const Cache& b) { return std::move(a) + b.*ptr; }) / cc.size();
|
||||
}
|
||||
|
||||
void average_html(const Caches& cc, uint Cache::*ptr, const std::string& caption) {
|
||||
std::cout << "<div class=\"basic_stats\">\n";
|
||||
std::cout << "Average " << caption << ": <span class=\"value\">" << average(cc, ptr) << "</span><br>\n";
|
||||
std::cout << "</div>\n";
|
||||
}
|
||||
template void sum_html(const Caches& cc, float Cache::*ptr, const std::string& caption);
|
||||
template void sum_html(const Caches& cc, int Cache::*ptr, const std::string& caption);
|
||||
template void sum_html(const Caches& cc, uint Cache::*ptr, const std::string& caption);
|
||||
|
||||
float average(const Caches& cc, float Cache::*ptr) {
|
||||
return std::accumulate(cc.begin(), cc.end(), 0., [&](const float& a, const Cache& b) { return std::move(a) + b.*ptr; }) / cc.size();
|
||||
}
|
||||
|
||||
float average(const Caches& cc, int Cache::*ptr) {
|
||||
return 1.0 * std::accumulate(cc.begin(), cc.end(), 0, [&](const float& a, const Cache& b) { return std::move(a) + b.*ptr; }) / cc.size();
|
||||
}
|
||||
|
||||
float average(const Caches& cc, uint Cache::*ptr) {
|
||||
return 1.0 * std::accumulate(cc.begin(), cc.end(), 0, [&](const float& a, const Cache& b) { return std::move(a) + b.*ptr; }) / cc.size();
|
||||
}
|
||||
|
||||
void sum_html(const Caches& cc, float Cache::*ptr, const std::string& caption) {
|
||||
template <typename T>
|
||||
void sum_html(const Caches& cc, T Cache::*ptr, const std::string& caption) {
|
||||
std::cout << "<div class=\"basic_stats\">\n";
|
||||
std::cout << "Total " << caption << ": <span class=\"value\">" << sum(cc, ptr) << "</span><br>\n";
|
||||
std::cout << "</div>\n";
|
||||
}
|
||||
|
||||
void sum_html(const Caches& cc, int Cache::*ptr, const std::string& caption) {
|
||||
std::cout << "<div class=\"basic_stats\">\n";
|
||||
std::cout << "Total " << caption << ": <span class=\"value\">" << sum(cc, ptr) << "</span><br>\n";
|
||||
std::cout << "</div>\n";
|
||||
}
|
||||
template float sum(const Caches& cc, float Cache::*ptr);
|
||||
template int sum(const Caches& cc, int Cache::*ptr);
|
||||
template uint sum(const Caches& cc, uint Cache::*ptr);
|
||||
|
||||
void sum_html(const Caches& cc, uint Cache::*ptr, const std::string& caption) {
|
||||
std::cout << "<div class=\"basic_stats\">\n";
|
||||
std::cout << "Total " << caption << ": <span class=\"value\">" << sum(cc, ptr) << "</span><br>\n";
|
||||
std::cout << "</div>\n";
|
||||
}
|
||||
|
||||
float sum(const Caches& cc, float Cache::*ptr) {
|
||||
return std::accumulate(cc.begin(), cc.end(), 0., [&](const float& a, const Cache& b) { return std::move(a) + b.*ptr; });
|
||||
}
|
||||
|
||||
int sum(const Caches& cc, int Cache::*ptr) {
|
||||
return std::accumulate(cc.begin(), cc.end(), 0, [&](const int& a, const Cache& b) { return std::move(a) + b.*ptr; });
|
||||
}
|
||||
|
||||
int sum(const Caches& cc, uint Cache::*ptr) {
|
||||
template <typename T>
|
||||
T sum(const Caches& cc, T Cache::*ptr) {
|
||||
return std::accumulate(cc.begin(), cc.end(), 0, [&](const int& a, const Cache& b) { return std::move(a) + b.*ptr; });
|
||||
}
|
||||
|
||||
|
|
16
common.h
16
common.h
|
@ -17,19 +17,11 @@ uint find_streak(const Date_Caches& cc, std::time_t& start);
|
|||
|
||||
uint get_num(char c, char* opt);
|
||||
|
||||
void average_html(const Caches& cc, float Cache::*ptr, const std::string& caption);
|
||||
void average_html(const Caches& cc, int Cache::*ptr, const std::string& caption);
|
||||
void average_html(const Caches& cc, uint Cache::*ptr, const std::string& caption);
|
||||
float average(const Caches& cc, float Cache::*ptr);
|
||||
float average(const Caches& cc, int Cache::*ptr);
|
||||
float average(const Caches& cc, uint Cache::*ptr);
|
||||
template <typename T> void average_html(const Caches& cc, T Cache::*ptr, const std::string& caption);
|
||||
template <typename T> float average(const Caches& cc, T Cache::*ptr);
|
||||
|
||||
void sum_html(const Caches& cc, float Cache::*ptr, const std::string& caption);
|
||||
void sum_html(const Caches& cc, int Cache::*ptr, const std::string& caption);
|
||||
void sum_html(const Caches& cc, uint Cache::*ptr, const std::string& caption);
|
||||
float sum(const Caches& cc, float Cache::*ptr);
|
||||
int sum(const Caches& cc, int Cache::*ptr);
|
||||
int sum(const Caches& cc, uint Cache::*ptr);
|
||||
template <typename T> void sum_html(const Caches& cc, T Cache::*ptr, const std::string& caption);
|
||||
template <typename T> T sum(const Caches& cc, T Cache::*ptr);
|
||||
|
||||
int count_caches(const Caches& cc, std::string& codes, std::function<bool(const Cache& c)> test);
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue