A class for "pretty printing" a table of data. More...
#include <SolutionInvalidity.h>
Public Types | |
typedef std::tuple< Ts... > | DataTuple |
The type stored for each row. More... | |
Public Member Functions | |
VariadicTable (std::vector< std::string > headers, unsigned int static_column_size=0, unsigned int cell_padding=1) | |
Construct the table with headers. More... | |
void | addRow (Ts... entries) |
Add a row of data. More... | |
template<typename StreamType > | |
void | print (StreamType &stream) |
Pretty print the table of data. More... | |
void | setColumnFormat (const std::vector< VariadicTableColumnFormat > &column_format) |
Set how to format numbers for each column. More... | |
void | setColumnPrecision (const std::vector< int > &precision) |
Set how many digits of precision to show for floating point numbers. More... | |
Protected Member Functions | |
template<std::size_t I, typename TupleType , typename StreamType > | |
void | print_each (TupleType &&t, StreamType &stream, std::integral_constant< size_t, I >) |
These three functions print out each item in a Tuple into the table. More... | |
template<typename TupleType , typename StreamType > | |
void | print_each (TupleType &&t, StreamType &stream) |
This is what gets called first. More... | |
template<class T > | |
size_t | sizeOfData (const T &data, decltype(((T *) nullptr) ->size()) *=nullptr) |
Try to find the size the column will take up. More... | |
template<class T > | |
size_t | sizeOfData (const T &data, typename std::enable_if< std::is_integral< T >::value >::type *=nullptr) |
Try to find the size the column will take up. More... | |
size_t | sizeOfData (...) |
If it doesn't... More... | |
template<typename TupleType > | |
void | size_each (TupleType &&, std::vector< unsigned int > &, std::integral_constant< size_t, std::tuple_size< typename std::remove_reference< TupleType >::type >::value >) |
These three functions iterate over the Tuple, find the printed size of each element and set it in a vector. More... | |
template<std::size_t I, typename TupleType , typename = typename std::enable_if< I != std::tuple_size<typename std::remove_reference<TupleType>::type>::value>::type> | |
void | size_each (TupleType &&t, std::vector< unsigned int > &sizes, std::integral_constant< size_t, I >) |
Recursively called for each element. More... | |
template<typename TupleType > | |
void | size_each (TupleType &&t, std::vector< unsigned int > &sizes) |
The function that is actually called that starts the recursion. More... | |
void | size_columns () |
Finds the size each column should be and set it in _column_sizes. More... | |
Static Protected Member Functions | |
template<typename T > | |
static auto | justify (int) |
Protected Attributes | |
std::vector< std::string > | _headers |
The column headers. More... | |
unsigned int | _num_columns |
Number of columns in the table. More... | |
unsigned int | _static_column_size |
Size of columns that we can't get the size of. More... | |
unsigned int | _cell_padding |
Size of the cell padding. More... | |
std::vector< DataTuple > | _data |
The actual data. More... | |
std::vector< unsigned int > | _column_sizes |
Holds the printable width of each column. More... | |
std::vector< VariadicTableColumnFormat > | _column_format |
Column Format. More... | |
std::vector< int > | _precision |
Precision For each column. More... | |
A class for "pretty printing" a table of data.
Requries C++11 (and nothing more)
It's templated on the types that will be in each column (all values in a column must have the same type)
For instance, to use it with data that looks like: "Fred", 193.4, 35, "Sam" with header names: "Name", "Weight", "Age", "Brother"
You would invoke the table like so: VariadicTable<std::string, double, int, std::string> vt("Name", "Weight", "Age", "Brother");
Then add the data to the table: vt.addRow("Fred", 193.4, 35, "Sam");
And finally print it: vt.print();
Definition at line 31 of file SolutionInvalidity.h.
typedef std::tuple<Ts...> VariadicTable< Ts >::DataTuple |
The type stored for each row.
Definition at line 64 of file VariadicTable.h.
|
inline |
Construct the table with headers.
headers | The names of the columns |
static_column_size | The size of columns that can't be found automatically |
Definition at line 72 of file VariadicTable.h.
|
inline |
Add a row of data.
Easiest to use like: table.addRow({data1, data2, data3});
data | A Tuple of data to add |
Definition at line 91 of file VariadicTable.h.
|
inlinestaticprotected |
Definition at line 171 of file VariadicTable.h.
|
inline |
Pretty print the table of data.
Definition at line 97 of file VariadicTable.h.
Referenced by SolutionInvalidity::print(), PerfGraph::print(), and PerfGraph::printHeaviestBranch().
|
inlineprotected |
These three functions print out each item in a Tuple into the table.
Original Idea From From https://stackoverflow.com/a/26908596
BTW: This would all be a lot easier with generic lambdas there would only need to be one of this sequence and then you could pass in a generic lambda. Unfortunately, that's C++14 This gets called on each item
Definition at line 195 of file VariadicTable.h.
Referenced by VariadicTable< Ts >::print(), and VariadicTable< Ts >::print_each().
|
inlineprotected |
This is what gets called first.
Definition at line 247 of file VariadicTable.h.
|
inline |
Set how to format numbers for each column.
Note: this is ignored for std::string columns
The format for each column: MUST be the same length as the number of columns.
Definition at line 148 of file VariadicTable.h.
Referenced by PerfGraph::printHeaviestSections(), SolutionInvalidity::summaryTable(), and PerfGraph::treeTable().
|
inline |
Set how many digits of precision to show for floating point numbers.
Note: this is ignored for std::string columns
The precision for each column: MUST be the same length as the number of columns.
Definition at line 162 of file VariadicTable.h.
|
inlineprotected |
Finds the size each column should be and set it in _column_sizes.
Definition at line 333 of file VariadicTable.h.
Referenced by VariadicTable< Ts >::print().
|
inlineprotected |
These three functions iterate over the Tuple, find the printed size of each element and set it in a vector.
End the recursion
Definition at line 292 of file VariadicTable.h.
Referenced by VariadicTable< Ts >::size_columns(), and VariadicTable< Ts >::size_each().
|
inlineprotected |
Recursively called for each element.
Definition at line 308 of file VariadicTable.h.
|
inlineprotected |
The function that is actually called that starts the recursion.
Definition at line 325 of file VariadicTable.h.
|
inlineprotected |
Try to find the size the column will take up.
If the datatype has a size() member... let's call it
Definition at line 258 of file VariadicTable.h.
Referenced by VariadicTable< Ts >::size_each().
|
inlineprotected |
Try to find the size the column will take up.
If the datatype is an integer - let's get it's length
Definition at line 269 of file VariadicTable.h.
|
inlineprotected |
If it doesn't...
let's just use a statically set size
Definition at line 281 of file VariadicTable.h.
|
protected |
Size of the cell padding.
Definition at line 364 of file VariadicTable.h.
Referenced by VariadicTable< Ts >::print(), and VariadicTable< Ts >::print_each().
|
protected |
Column Format.
Definition at line 373 of file VariadicTable.h.
Referenced by VariadicTable< Ts >::print_each(), VariadicTable< Ts >::setColumnFormat(), and VariadicTable< Ts >::size_each().
|
protected |
Holds the printable width of each column.
Definition at line 370 of file VariadicTable.h.
Referenced by VariadicTable< Ts >::print(), VariadicTable< Ts >::print_each(), and VariadicTable< Ts >::size_columns().
|
protected |
The actual data.
Definition at line 367 of file VariadicTable.h.
Referenced by VariadicTable< Ts >::addRow(), VariadicTable< Ts >::print(), and VariadicTable< Ts >::size_columns().
|
protected |
The column headers.
Definition at line 355 of file VariadicTable.h.
Referenced by VariadicTable< Ts >::print(), and VariadicTable< Ts >::size_columns().
|
protected |
Number of columns in the table.
Definition at line 358 of file VariadicTable.h.
Referenced by VariadicTable< Ts >::print(), VariadicTable< Ts >::size_columns(), and VariadicTable< Ts >::VariadicTable().
|
protected |
Precision For each column.
Definition at line 376 of file VariadicTable.h.
Referenced by VariadicTable< Ts >::print_each(), and VariadicTable< Ts >::setColumnPrecision().
|
protected |
Size of columns that we can't get the size of.
Definition at line 361 of file VariadicTable.h.
Referenced by VariadicTable< Ts >::sizeOfData().