HOG2
|
#include <Table.h>
Public Types | |
typedef std::tuple< Ts... > | DataTuple |
Public Member Functions | |
Table (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) |
Print the table of data. More... | |
void | setColumnFormat (const std::vector< TableColumnFormat > &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<typename TupleType , typename StreamType > | |
void | print_each (TupleType &&, StreamType &, std::integral_constant< size_t, std::tuple_size< typename std::remove_reference< TupleType >::type >::value >) |
These three functions print out each item in a Tuple into the table. More... | |
template<std::size_t I, typename TupleType , typename StreamType , typename = typename std::enable_if< I != std::tuple_size<typename std::remove_reference<TupleType>::type>::value>::type> | |
void | print_each (TupleType &&t, StreamType &stream, std::integral_constant< size_t, I >) |
This gets called on each item. 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 , typename = typename std::enable_if< std::is_arithmetic<typename std::remove_reference<T>::type>::value>::type> | |
static right_type | justify (int) |
template<typename T > | |
static left_type | justify (long) |
Protected Attributes | |
decltype(&std::right) typedef | right_type |
decltype(&std::left) typedef | left_type |
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< TableColumnFormat > | _column_format |
Column Format. More... | |
std::vector< int > | _precision |
Precision For each column. More... | |
|
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 31 of file Table.h.
References Table< Ts >::_num_columns.
|
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 50 of file Table.h.
References Table< Ts >::_data.
|
inlinestaticprotected |
|
inline |
Print the table of data.
Definition at line 56 of file Table.h.
References Table< Ts >::_cell_padding, Table< Ts >::_column_sizes, Table< Ts >::_data, Table< Ts >::_headers, Table< Ts >::_num_columns, Table< Ts >::print_each(), and Table< Ts >::size_columns().
|
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 ends the recursion
Definition at line 163 of file Table.h.
Referenced by Table< Ts >::print(), and Table< Ts >::print_each().
|
inlineprotected |
This is what gets called first.
Definition at line 226 of file Table.h.
References Table< Ts >::print_each().
|
inlineprotected |
This gets called on each item.
Definition at line 179 of file Table.h.
References Table< Ts >::_cell_padding, Table< Ts >::_column_format, Table< Ts >::_column_sizes, Table< Ts >::_precision, kFIXED, kPERCENT, kSCIENTIFIC, and Table< Ts >::print_each().
|
inline |
Set how to format numbers for each column.
Note: this is ignored for std::string columns
@column_format The format for each column: MUST be the same length as the number of columns.
Definition at line 107 of file Table.h.
References Table< Ts >::_column_format.
|
inline |
Set how many digits of precision to show for floating point numbers.
Note: this is ignored for std::string columns
@column_format The precision for each column: MUST be the same length as the number of columns.
Definition at line 121 of file Table.h.
References Table< Ts >::_precision.
|
inlineprotected |
Finds the size each column should be and set it in _column_sizes.
Definition at line 312 of file Table.h.
References Table< Ts >::_column_sizes, Table< Ts >::_data, Table< Ts >::_headers, Table< Ts >::_num_columns, max, and Table< Ts >::size_each().
Referenced by Table< 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 271 of file Table.h.
Referenced by Table< Ts >::size_columns(), and Table< Ts >::size_each().
|
inlineprotected |
The function that is actually called that starts the recursion.
Definition at line 304 of file Table.h.
References Table< Ts >::size_each().
|
inlineprotected |
Recursively called for each element.
Definition at line 287 of file Table.h.
References Table< Ts >::_column_format, kPERCENT, Table< Ts >::size_each(), and Table< Ts >::sizeOfData().
|
inlineprotected |
If it doesn't...
let's just use a statically set size
Definition at line 260 of file Table.h.
References Table< Ts >::_static_column_size.
|
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 237 of file Table.h.
Referenced by Table< Ts >::size_each().
|
inlineprotected |
|
protected |
Size of the cell padding.
Definition at line 343 of file Table.h.
Referenced by Table< Ts >::print(), and Table< Ts >::print_each().
|
protected |
Column Format.
Definition at line 352 of file Table.h.
Referenced by Table< Ts >::print_each(), Table< Ts >::setColumnFormat(), and Table< Ts >::size_each().
|
protected |
Holds the printable width of each column.
Definition at line 349 of file Table.h.
Referenced by Table< Ts >::print(), Table< Ts >::print_each(), and Table< Ts >::size_columns().
The actual data.
Definition at line 346 of file Table.h.
Referenced by Table< Ts >::addRow(), Table< Ts >::print(), and Table< Ts >::size_columns().
|
protected |
The column headers.
Definition at line 334 of file Table.h.
Referenced by Table< Ts >::print(), and Table< Ts >::size_columns().
|
protected |
Number of columns in the table.
Definition at line 337 of file Table.h.
Referenced by Table< Ts >::print(), Table< Ts >::size_columns(), and Table< Ts >::Table().
|
protected |
Precision For each column.
Definition at line 355 of file Table.h.
Referenced by Table< Ts >::print_each(), and Table< Ts >::setColumnPrecision().
|
protected |
Size of columns that we can't get the size of.
Definition at line 340 of file Table.h.
Referenced by Table< Ts >::sizeOfData().
|
protected |
|
protected |