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"
31 using FieldInterpreter = std::function<std::string(
const std::string&)>;
55 using OutputFormat_t = std::function<
57 const std::vector<std::vector<std::string>>&,
58 const std::vector<std::string>&,
128 const std::vector<std::vector<std::string>>&
table,
129 const std::vector<std::string>&
fields,
137 for (
size_t i = 0;
i <
table.size(); ++
i) {
141 "Number of columns and fields argument must have "
142 "the same size in output::format::barebone");
145 for (
size_t j = 0;
j <
table[
i].size(); ++
j) {
147 auto it = settings.fieldOptions.find(
fields[
j]);
149 if(
it != settings.fieldOptions.end() &&
i)
150 result << std::setw(
it->second.columnWidth)
151 << std::left <<
it->second.fieldInterpreter(
table[
i][
j]);
152 else if(
it != settings.fieldOptions.end())
153 result << std::setw(
it->second.columnWidth)
156 result << std::setw(settings.defaultColumnWidth)
176 const std::vector<std::vector<std::string>>&
table,
177 const std::vector<std::string>&
fields,
188 for (
size_t i = 0;
i <
table[0].size(); ++
i) {
190 auto it = settings.fieldOptions.find(
fields[
i]);
192 if(
it != settings.fieldOptions.end())
195 header_str << std::setw(settings.defaultColumnWidth) <<
table[0][
i] <<
" | ";
200 for (
size_t i = 4;
i <
header.size(); ++
i)
204 for (
size_t i = 1;
i <
table.size(); ++
i) {
208 "Number of columns and <fields> argument must have "
209 "the same size in output::format::simple");
214 for (
size_t j = 0;
j <
table[
i].size(); ++
j) {
216 auto it = settings.fieldOptions.find(
fields[
j]);
218 if(
it != settings.fieldOptions.end())
219 result << std::setw(
it->second.columnWidth)
220 <<
it->second.fieldInterpreter(
table[
i][
j]) <<
" | ";
222 result << std::setw(settings.defaultColumnWidth)
247 const std::vector<std::vector<std::string>>&
table,
248 const std::vector<std::string>&
fields,
268 auto it = settings.fieldOptions.find(
fields[
i]);
270 if (
it == settings.fieldOptions.end())
295 for (
size_t i = 0;
i <
table[0].size(); ++
i) {
297 auto it = settings.fieldOptions.find(
fields[
i]);
299 unsigned int width = 0;
302 width =
it->second.columnWidth;
306 width = settings.defaultColumnWidth;
312 std::string
header =
" ┌";
333 "Number of columns and <fields> argument must have "
334 "the same size in output::format::fancy");
341 auto it = settings.fieldOptions.find(
fields[
j]);
344 result << std::setw(
it->second.columnWidth)
350 result << std::setw(settings.defaultColumnWidth)
376 const std::vector<std::vector<std::string>>&
table,
377 const std::vector<std::string>&
fields,
382 for (
size_t i = 0;
i <
table.size(); ++
i) {
385 throw std::runtime_error(
386 "Number of columns and <fields> argument must have "
387 "the same size in output::format::csv");
391 for (
size_t j = 0;
j <
table[
i].size(); ++
j) {
393 auto it = settings.fieldOptions.find(
fields[
j]);
395 if(
it != settings.fieldOptions.end() &&
i)
396 s <<
"\"" <<
it->second.fieldInterpreter(
table[
i][
j]) <<
"\"";
398 s <<
"\"" <<
table[
i][
j] <<
"\"";
417 const std::vector<std::vector<std::string>>&
table,
418 const std::vector<std::string>&
fields,
429 for (
size_t i = 0;
i <
table[0].size(); ++
i) {
431 auto it = settings.fieldOptions.find(
fields[
i]);
433 if(
it != settings.fieldOptions.end())
435 << std::left <<
table[0][
i];
437 header_str << std::setw(settings.defaultColumnWidth)
438 << std::left <<
table[0][
i];
445 for (
size_t i = 1;
i <
header.size() - 1; ++
i)
449 for (
size_t i = 1;
i <
table.size(); ++
i) {
453 "Number of columns and <fields> argument must have "
454 "the same size in output::format::markdown");
459 for (
size_t j = 0;
j <
table[
i].size(); ++
j) {
461 auto it = settings.fieldOptions.find(
fields[
j]);
463 if(
it != settings.fieldOptions.end())
464 result << std::setw(
it->second.columnWidth)
465 << std::left <<
it->second.fieldInterpreter(
table[
i][
j]);
467 result << std::setw(settings.defaultColumnWidth)
486 const std::vector<std::vector<std::string>>&
table,
487 const std::vector<std::string>&
fields,
494 result <<
"\\begin{tabular}{";
499 for (
unsigned int i = 0;
i <
fields.size(); ++
i)
504 for (
size_t i = 0;
i <
table[0].size(); ++
i) {
511 result <<
" \\\\\n\\hline\n";
513 for (
size_t i = 1;
i <
table.size(); ++
i) {
517 "Number of columns and <fields> argument must have "
518 "the same size in output::format::latex");
521 for (
size_t j = 0;
j <
table[
i].size(); ++
j) {
523 auto it = settings.fieldOptions.find(
fields[
j]);
525 if(
it != settings.fieldOptions.end())
537 result <<
"\\hline\n\\end{tabular}\n";
600 if(s ==
"0")
return "PASS";
601 else if(s ==
"1")
return "FAIL";
602 else return "UNKNOWN";
644 std::stringstream
value;
649 value << std::scientific
653 value << std::scientific
657 value << std::scientific
661 value << std::scientific
665 value << std::scientific
669 value << std::scientific
676 if(
r.additionalFields.find(
fieldName) ==
r.additionalFields.end())
694 std::stringstream
value;
703 value << std::scientific
707 value << std::scientific
714 if(
r.additionalFields.find(
fieldName) ==
r.additionalFields.end())
729 std::stringstream
value;
738 value << std::scientific
741 }
else if(
fieldName ==
"averageRuntime") {
742 value << std::scientific
746 value << std::scientific
749 }
else if(
fieldName ==
"runsPerSecond") {
750 if(
r.runsPerSecond > 1000)
760 if(
r.additionalFields.find(
fieldName) ==
r.additionalFields.end())
778 std::stringstream
value;
804 std::stringstream
value;
810 }
else if(
fieldName ==
"expectedFlags") {
813 for (
int flag :
r.expectedFlags)
836 std::stringstream
value;
863 template<
typename ResultType>
865 const std::map<std::string, std::vector<ResultType>>&
results,
866 const std::vector<std::string>&
fields) {
868 std::vector<std::vector<std::string>>
table;
872 for (
size_t i = 0;
i <
fields.size(); ++
i) {
886 for (
const auto&
result :
p.second) {
892 std::vector<std::string>
row (
fields.size());
894 for (
size_t i = 0;
i <
fields.size(); ++
i)
935 template<
typename ResultType>
937 const std::map<std::string, std::vector<ResultType>>&
results,
938 const std::vector<std::string>&
fields,
939 const std::vector<std::string>&
filenames) {
963 std::cout <<
"Unable to write to output file: " <<
filename << std::endl;
977 std::cout <<
"Results have been saved in: " <<
filename << std::endl;
984 std::cout <<
"Unable to write to output file: " <<
filename << std::endl;
998 std::cout <<
"Results have been saved in: " <<
filename << std::endl;
module context.
Definition output.h:547
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:726
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:864
void terminate()
Terminate the output module by closing all output files and resetting its settings.
Definition output.h:615
void setup()
Setup printing to the output stream with default options.
Definition output.h:555
output_context()
Default constructor for the output module.
Definition output.h:625
bool open_file(const std::string &filename)
Try to open a new output file, returning whether it was correctly opened.
Definition output.h:911
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:801
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:833
~output_context()
Destructor which automatically terminates the module.
Definition output.h:631
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:641
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:775
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:691
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:936
output_settings settings
Settings for the output module.
Definition output.h:551
#define CHEBYSHEV_OUTPUT_WIDTH
Default width of output columns.
Definition common.h:32
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:105
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:29
unsigned int columnWidth
Width for the column associated with the field.
Definition output.h:34
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:38
std::map< std::string, long double > additionalFields
Additional custom options.
Definition output.h:41
Global settings of printing results to standard output.
Definition output.h:53
bool quiet
Whether to output to standard output.
Definition output.h:91
std::map< std::string, OutputFormat_t > fileOutputFormat
The output format to use for a specific file, by filename.
Definition output.h:88
std::vector< std::string > outputFiles
A list of output files.
Definition output.h:69
bool outputToFile
Whether to print the results to file.
Definition output.h:94
OutputFormat_t defaultFileOutputFormat
The default output format to use for files, when no format has been set for a file.
Definition output.h:85
std::map< std::string, field_options > fieldOptions
Options for the different fields.
Definition output.h:66
OutputFormat_t outputFormat
The output format to use to print to standard output.
Definition output.h:81
unsigned int defaultColumnWidth
Default width for a field.
Definition output.h:75
std::map< std::string, std::string > fieldNames
Map of field name to output string (e.g.
Definition output.h:63
std::map< std::string, std::ofstream > openFiles
A map of open output files, by filename.
Definition output.h:72
unsigned int outputPrecision
The number of digits to show in scientific notation.
Definition output.h:78
bool wasSetup
Whether the output module was setup.
Definition output.h:97
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