Line data Source code
1 : #include <algorithm> 2 : #include <cassert> 3 : #include <cmath> 4 : #include <iomanip> 5 : #include <ios> 6 : 7 : #include "Tools/Display/Terminal/Dump/Terminal_dump.hpp" 8 : #include "Tools/Display/rang_format/rang_format.h" 9 : #include "Tools/Exception/exception.hpp" 10 : 11 : using namespace spu; 12 : using namespace spu::tools; 13 : 14 16 : Terminal_dump::Terminal_dump(const std::vector<tools::Reporter*>& reporters) 15 16 : : Terminal_std(reporters) 16 : { 17 16 : } 18 : 19 0 : Terminal_dump::Terminal_dump(const std::vector<std::unique_ptr<tools::Reporter>>& reporters) 20 0 : : Terminal_std(reporters) 21 : { 22 0 : } 23 : 24 : void 25 122 : Terminal_dump::report(std::ostream& stream, bool final) 26 : { 27 122 : std::ios::fmtflags f(stream.flags()); 28 : 29 122 : std::vector<Reporter::report_t> report_list; 30 610 : for (unsigned r = 0; r < this->reporters.size(); r++) 31 488 : report_list.push_back(this->reporters[r]->report(final)); 32 : 33 122 : bool is_not_over = true; 34 294 : while (is_not_over) 35 : { 36 172 : stream << data_tag; 37 : 38 172 : is_not_over = false; 39 860 : for (unsigned r = 0; r < this->reporters.size(); r++) 40 688 : if (this->reporters[r] != nullptr) 41 : { 42 688 : auto& report = report_list[r]; 43 688 : auto& groups = this->reporters[r]->get_groups(); 44 : 45 688 : assert(report.size() == groups.size()); 46 : 47 1376 : for (unsigned g = 0; g < groups.size(); g++) 48 : { 49 688 : if (report[g].size()) assert(report[g].size() % groups[g].second.size() == 0); 50 : 51 688 : stream << report_style << std::string(extra_spaces(groups[g]), ' ') << rang::style::reset; 52 : 53 2924 : for (unsigned c = 0; c < groups[g].second.size(); c++) 54 : { 55 2236 : auto text = report[g].size() ? report[g][c] : "-"; 56 : 57 : size_t column_with = 58 2236 : std::get<2>(groups[g].second[c]) ? std::get<2>(groups[g].second[c]) : def_column_width; 59 2236 : if (text.size() < (size_t)column_with) 60 : { 61 2190 : text += " "; 62 2190 : text.insert(0, column_with - text.size(), ' '); 63 : } 64 : 65 2236 : stream << text; 66 : 67 2236 : if (c != (groups[g].second.size() - 1)) 68 1548 : stream << report_style << col_separator << rang::style::reset; 69 2236 : } 70 688 : if (report[g].size()) 71 624 : report[g].erase(report[g].begin(), report[g].begin() + groups[g].second.size()); 72 688 : is_not_over = is_not_over ? is_not_over : report[g].size() > 0; 73 : 74 688 : if (g != (groups.size() - 1)) stream << report_style << group_separator << rang::style::reset; 75 : } 76 : 77 688 : if (r != (this->reporters.size() - 1)) stream << report_style << group_separator << rang::style::reset; 78 : } 79 : else 80 0 : throw tools::runtime_error(__FILE__, __LINE__, __func__, "'this->reporters' contains null pointer."); 81 : 82 172 : stream << std::endl; 83 : } 84 : 85 122 : stream.flags(f); 86 122 : stream.flush(); 87 272 : }