6#ifndef CHEBYSHEV_OUTPUT_H
7#define CHEBYSHEV_OUTPUT_H
16#include "../prec/prec_structures.h"
17#include "../benchmark/benchmark_structures.h"
18#include "../err/err_structures.h"
32 using FieldInterpreter = std::function<std::string(
const std::string&)>;
56 using OutputFormat_t = std::function<
58 const std::vector<std::vector<std::string>>&,
59 const std::vector<std::string>&,
132 const std::vector<std::vector<std::string>>&
table,
133 const std::vector<std::string>&
fields,
141 for (
size_t i = 0;
i <
table.size(); ++
i) {
145 "Number of columns and fields argument must have "
146 "the same size in output::format::barebone");
149 for (
size_t j = 0;
j <
table[
i].size(); ++
j) {
151 auto it = settings.fieldOptions.find(
fields[
j]);
153 if(
it != settings.fieldOptions.end() &&
i)
154 result << std::setw(
it->second.columnWidth)
155 << std::left <<
it->second.fieldInterpreter(
table[
i][
j]);
156 else if(
it != settings.fieldOptions.end())
157 result << std::setw(
it->second.columnWidth)
160 result << std::setw(settings.defaultColumnWidth)
180 const std::vector<std::vector<std::string>>&
table,
181 const std::vector<std::string>&
fields,
192 for (
size_t i = 0;
i <
table[0].size(); ++
i) {
194 auto it = settings.fieldOptions.find(
fields[
i]);
196 if(
it != settings.fieldOptions.end())
199 header_str << std::setw(settings.defaultColumnWidth) <<
table[0][
i] <<
" | ";
204 for (
size_t i = 4;
i <
header.size(); ++
i)
208 for (
size_t i = 1;
i <
table.size(); ++
i) {
212 "Number of columns and <fields> argument must have "
213 "the same size in output::format::simple");
218 for (
size_t j = 0;
j <
table[
i].size(); ++
j) {
220 auto it = settings.fieldOptions.find(
fields[
j]);
222 if(
it != settings.fieldOptions.end())
223 result << std::setw(
it->second.columnWidth)
224 <<
it->second.fieldInterpreter(
table[
i][
j]) <<
" | ";
226 result << std::setw(settings.defaultColumnWidth)
251 const std::vector<std::vector<std::string>>&
table,
252 const std::vector<std::string>&
fields,
272 auto it = settings.fieldOptions.find(
fields[
i]);
274 if (
it == settings.fieldOptions.end())
299 for (
size_t i = 0;
i <
table[0].size(); ++
i) {
301 auto it = settings.fieldOptions.find(
fields[
i]);
303 unsigned int width = 0;
306 width =
it->second.columnWidth;
310 width = settings.defaultColumnWidth;
316 std::string
header =
" ┌";
337 "Number of columns and <fields> argument must have "
338 "the same size in output::format::fancy");
345 auto it = settings.fieldOptions.find(
fields[
j]);
348 result << std::setw(
it->second.columnWidth)
354 result << std::setw(settings.defaultColumnWidth)
380 const std::vector<std::vector<std::string>>&
table,
381 const std::vector<std::string>&
fields,
386 for (
size_t i = 0;
i <
table.size(); ++
i) {
389 throw std::runtime_error(
390 "Number of columns and <fields> argument must have "
391 "the same size in output::format::csv");
395 for (
size_t j = 0;
j <
table[
i].size(); ++
j) {
397 auto it = settings.fieldOptions.find(
fields[
j]);
399 if(
it != settings.fieldOptions.end() &&
i)
400 s <<
"\"" <<
it->second.fieldInterpreter(
table[
i][
j]) <<
"\"";
402 s <<
"\"" <<
table[
i][
j] <<
"\"";
421 const std::vector<std::vector<std::string>>&
table,
422 const std::vector<std::string>&
fields,
433 for (
size_t i = 0;
i <
table[0].size(); ++
i) {
435 auto it = settings.fieldOptions.find(
fields[
i]);
437 if(
it != settings.fieldOptions.end())
439 << std::left <<
table[0][
i];
441 header_str << std::setw(settings.defaultColumnWidth)
442 << std::left <<
table[0][
i];
449 for (
size_t i = 1;
i <
header.size() - 1; ++
i)
453 for (
size_t i = 1;
i <
table.size(); ++
i) {
457 "Number of columns and <fields> argument must have "
458 "the same size in output::format::markdown");
463 for (
size_t j = 0;
j <
table[
i].size(); ++
j) {
465 auto it = settings.fieldOptions.find(
fields[
j]);
467 if(
it != settings.fieldOptions.end())
468 result << std::setw(
it->second.columnWidth)
469 << std::left <<
it->second.fieldInterpreter(
table[
i][
j]);
471 result << std::setw(settings.defaultColumnWidth)
490 const std::vector<std::vector<std::string>>&
table,
491 const std::vector<std::string>&
fields,
498 result <<
"\\begin{tabular}{";
503 for (
unsigned int i = 0;
i <
fields.size(); ++
i)
508 for (
size_t i = 0;
i <
table[0].size(); ++
i) {
515 result <<
" \\\\\n\\hline\n";
517 for (
size_t i = 1;
i <
table.size(); ++
i) {
521 "Number of columns and <fields> argument must have "
522 "the same size in output::format::latex");
525 for (
size_t j = 0;
j <
table[
i].size(); ++
j) {
527 auto it = settings.fieldOptions.find(
fields[
j]);
529 if(
it != settings.fieldOptions.end())
541 result <<
"\\hline\n\\end{tabular}\n";
604 if(s ==
"0")
return "PASS";
605 else if(s ==
"1")
return "FAIL";
606 else return "UNKNOWN";
648 std::stringstream
value;
653 value << std::scientific
657 value << std::scientific
661 value << std::scientific
665 value << std::scientific
669 value << std::scientific
673 value << std::scientific
680 if(
r.additionalFields.find(
fieldName) ==
r.additionalFields.end())
698 std::stringstream
value;
707 value << std::scientific
711 value << std::scientific
718 if(
r.additionalFields.find(
fieldName) ==
r.additionalFields.end())
733 std::stringstream
value;
742 value << std::scientific
745 }
else if(
fieldName ==
"averageRuntime") {
746 value << std::scientific
750 value << std::scientific
753 }
else if(
fieldName ==
"runsPerSecond") {
754 if(
r.runsPerSecond > 1000)
764 if(
r.additionalFields.find(
fieldName) ==
r.additionalFields.end())
782 std::stringstream
value;
808 std::stringstream
value;
814 }
else if(
fieldName ==
"expectedFlags") {
817 for (
int flag :
r.expectedFlags)
840 std::stringstream
value;
867 template<
typename ResultType>
869 const std::map<std::string, std::vector<ResultType>>&
results,
870 const std::vector<std::string>&
fields) {
872 std::vector<std::vector<std::string>>
table;
876 for (
size_t i = 0;
i <
fields.size(); ++
i) {
890 for (
const auto&
result :
p.second) {
896 std::vector<std::string>
row (
fields.size());
898 for (
size_t i = 0;
i <
fields.size(); ++
i)
939 template<
typename ResultType>
941 const std::map<std::string, std::vector<ResultType>>&
results,
942 const std::vector<std::string>&
fields,
943 const std::vector<std::string>&
filenames) {
1016 if (
level == LogLevel::ERROR) {
1017 std::cerr <<
"ERROR: " <<
message << std::endl;
module context.
Definition output.h:551
std::string resolve_field(const std::string &fieldName, benchmark::benchmark_result r)
Resolve the field of a benchmark result by name, returning the value as a string.
Definition output.h:730
void warn(const std::string &message)
Write a warning to standard output according to the set log level.
Definition output.h:1041
auto generate_table(const std::map< std::string, std::vector< ResultType > > &results, const std::vector< std::string > &fields)
Generate a table of results as a string matrix to pass to a specific formatter of OutputFormat type.
Definition output.h:868
void terminate()
Terminate the output module by closing all output files and resetting its settings.
Definition output.h:619
void error(const std::string &message)
Write an error message to standard error according to the set log level.
Definition output.h:1048
void setup()
Setup printing to the output stream with default options.
Definition output.h:559
output_context()
Default constructor for the output module.
Definition output.h:629
bool open_file(const std::string &filename)
Try to open a new output file, returning whether it was correctly opened.
Definition output.h:915
std::string resolve_field(const std::string &fieldName, err::errno_result r)
Resolve the field of an errno checking result by name, returning the value as a string.
Definition output.h:805
std::string resolve_field(const std::string &fieldName, err::exception_result r)
Resolve the field of an exception checking result by name, returning the value as a string.
Definition output.h:837
~output_context()
Destructor which automatically terminates the module.
Definition output.h:635
void info(const std::string &message)
Write runtime information to standard output according to the set log level.
Definition output.h:1034
void log(const std::string &message, LogLevel level)
Log a message to standard output according to the set log level.
Definition output.h:1011
std::string resolve_field(const std::string &fieldName, prec::estimate_result r)
Resolve the field of an estimate result by name, returning the value as a string.
Definition output.h:645
std::string resolve_field(const std::string &fieldName, err::assert_result r)
Resolve the field of an assertion result by name, returning the value as a string.
Definition output.h:779
std::string resolve_field(const std::string &fieldName, prec::equation_result r)
Resolve the field of an equation result by name, returning the value as a string.
Definition output.h:695
void print_results(const std::map< std::string, std::vector< ResultType > > &results, const std::vector< std::string > &fields, const std::vector< std::string > &filenames)
Print the test results to standard output and output files.
Definition output.h:940
void debug(const std::string &message)
Write debug information to standard output according to the set log level.
Definition output.h:1027
output_settings settings
Settings for the output module.
Definition output.h:555
#define CHEBYSHEV_OUTPUT_WIDTH
Default width of output columns.
Definition common.h:32
Logging system for the output module.
LogLevel
Log levels for the output module.
Definition log.h:16
output_settings::OutputFormat_t OutputFormat
A function which converts the table entries of a row to a string to print (e.g.
Definition output.h:109
std::string loglevel_to_string(LogLevel level)
Convert a log level to a string for printing.
Definition log.h:25
General namespace of the framework.
Definition benchmark.h:22
constexpr FloatType get_nan()
Get a quiet NaN of the specified floating point type.
Definition common.h:65
Structure holding the results of a benchmark.
Definition benchmark_structures.h:23
Result of assertion checking of a function.
Definition err_structures.h:21
Result of errno checking of a function.
Definition err_structures.h:42
Result of exception checking of a function.
Definition err_structures.h:63
Custom options for printing a certain field.
Definition output.h:30
std::map< std::string, prec_t > additionalFields
Additional custom options.
Definition output.h:42
unsigned int columnWidth
Width for the column associated with the field.
Definition output.h:35
FieldInterpreter fieldInterpreter
A function which gets as input the value of a field as a string and returns a new string (e....
Definition output.h:39
Global settings of printing results to standard output.
Definition output.h:54
bool quiet
Whether to output to standard output.
Definition output.h:92
std::map< std::string, OutputFormat_t > fileOutputFormat
The output format to use for a specific file, by filename.
Definition output.h:89
std::vector< std::string > outputFiles
A list of output files.
Definition output.h:70
bool outputToFile
Whether to print the results to file.
Definition output.h:95
OutputFormat_t defaultFileOutputFormat
The default output format to use for files, when no format has been set for a file.
Definition output.h:86
std::map< std::string, field_options > fieldOptions
Options for the different fields.
Definition output.h:67
OutputFormat_t outputFormat
The output format to use to print to standard output.
Definition output.h:82
LogLevel logLevel
Log level for standard output and error messages.
Definition output.h:101
unsigned int defaultColumnWidth
Default width for a field.
Definition output.h:76
std::map< std::string, std::string > fieldNames
Map of field name to output string (e.g.
Definition output.h:64
std::map< std::string, std::ofstream > openFiles
A map of open output files, by filename.
Definition output.h:73
unsigned int outputPrecision
The number of digits to show in scientific notation.
Definition output.h:79
bool wasSetup
Whether the output module was setup.
Definition output.h:98
A structure holding the result of an evaluation.
Definition prec_structures.h:167
A structure holding the result of precision estimation.
Definition prec_structures.h:25