#include "report.h" #include "helper.h" #include #include bool Report::load() { // loading content of files std::ifstream ifsb(bootstrap_f); if (!ifsb.is_open()) { // load from the pre generated file #include "data_bootstrap_css.h" bootstrap_content = std::string(bootstrap_data); } else { bootstrap_content.assign((std::istreambuf_iterator(ifsb)), (std::istreambuf_iterator())); } std::ifstream ifsr(report_f); if (!ifsr.is_open()) { #include "data_report_html.h" report = std::string(report_data); } else { report.assign((std::istreambuf_iterator(ifsr)), (std::istreambuf_iterator())); } // find bootstrap expression return string_replace_substring(report, bootstrap_s, bootstrap_content); } bool Report::dump(const std::string &fname) const { std::ofstream ofs(fname); if (!ofs.is_open()) return false; std::string freport = report; if (!string_replace_substring(freport, module_s, "")) return false; ofs << freport; ofs.close(); return true; } bool Report::add_entry(const std::vector &columns) { if (columns.size() != column_names.size() && columns.size() > 3) return false; std::stringstream table_entry; // FIXME: make entries instead of numbers if (columns[3] == "YES") table_entry << ""; else if (columns[3] == "NO") table_entry << ""; else return false; // generate table report entry for (auto &c : columns) { table_entry << "\n" << c << "\n"; } table_entry << "\n"; table_entries.push_back(table_entry.str()); return true; } bool Report::flush(const std::string &header_name) { std::stringstream s; // generate report for specific module s << "

" << header_name << "

\n"; s << "\n"; s << "\n\n"; for (auto &cn : column_names) s << "\n"; s << "\n\n"; s << "\n"; for (auto &te : table_entries) s << te << "\n"; s << "\n
" << cn << "
\n"; table_entries = {}; // add to current report data return string_replace_substring(report, module_s, s.str() + module_s); }