24 #include <type_traits> 59 template <
class... Ts>
73 unsigned int static_column_size = 0,
74 unsigned int cell_padding = 1)
91 void addRow(Ts... entries) {
_data.emplace_back(std::make_tuple(entries...)); }
96 template <
typename StreamType>
110 stream << std::string(total_width,
'-') <<
"\n";
127 stream << std::string(total_width,
'-') <<
"\n";
130 for (
auto & row :
_data)
138 stream << std::string(total_width,
'-') << std::endl;
150 assert(column_format.size() == std::tuple_size<DataTuple>::value);
164 assert(precision.size() == std::tuple_size<DataTuple>::value);
170 template <
typename T>
173 if constexpr (std::is_arithmetic<
typename std::remove_reference<T>::type>::
value)
194 template <std::
size_t I,
typename TupleType,
typename StreamType>
195 void print_each(TupleType && t, StreamType & stream, std::integral_constant<size_t, I>)
197 auto & val = std::get<I>(t);
199 auto original_precision = stream.precision();
200 auto original_flags = stream.flags();
206 std::tuple_size<typename std::remove_reference<TupleType>::type>::value);
215 std::tuple_size<typename std::remove_reference<TupleType>::type>::value);
218 stream << std::scientific;
221 stream << std::fixed;
224 stream << std::fixed << std::setprecision(2);
228 << justify<decltype(val)>(0) << val << std::string(
_cell_padding,
' ') <<
"|";
232 stream.flags(original_flags);
236 stream.precision(original_precision);
239 if constexpr (I + 1 != std::tuple_size<
typename std::remove_reference<TupleType>::type>::
value)
240 print_each(std::forward<TupleType>(t), stream, std::integral_constant<size_t, I + 1>());
246 template <
typename TupleType,
typename StreamType>
249 print_each(std::forward<TupleType>(t), stream, std::integral_constant<size_t, 0>());
258 size_t sizeOfData(
const T & data, decltype(((T *)
nullptr)->size()) * =
nullptr)
270 typename std::enable_if<std::is_integral<T>::value>::type * =
nullptr)
275 return std::log10(data) + 1;
291 template <
typename TupleType>
293 std::vector<unsigned int> & ,
294 std::integral_constant<
296 std::tuple_size<
typename std::remove_reference<TupleType>::type>::value>)
303 template <std::size_t I,
305 typename =
typename std::enable_if<
306 I != std::tuple_size<typename std::remove_reference<TupleType>::type>::value>::type>
308 size_each(TupleType && t, std::vector<unsigned int> & sizes, std::integral_constant<size_t, I>)
318 size_each(std::forward<TupleType>(t), sizes, std::integral_constant<size_t, I + 1>());
324 template <
typename TupleType>
325 void size_each(TupleType && t, std::vector<unsigned int> & sizes)
327 size_each(std::forward<TupleType>(t), sizes, std::integral_constant<size_t, 0>());
345 for (
auto & row :
_data)
size_t sizeOfData(...)
If it doesn't...
std::tuple< Ts... > DataTuple
The type stored for each row.
std::vector< int > _precision
Precision For each column.
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 v...
void print(StreamType &stream)
Pretty print the table of data.
A class for "pretty printing" a table of data.
size_t sizeOfData(const T &data, decltype(((T *) nullptr) ->size()) *=nullptr)
Try to find the size the column will take up.
void setColumnPrecision(const std::vector< int > &precision)
Set how many digits of precision to show for floating point numbers.
unsigned int _cell_padding
Size of the cell padding.
VariadicTableColumnFormat
Note! This class comes from https://github.com/friedmud/variadic_table.
std::vector< VariadicTableColumnFormat > _column_format
Column Format.
std::vector< DataTuple > _data
The actual data.
auto max(const L &left, const R &right)
unsigned int _num_columns
Number of columns in the table.
VariadicTable(std::vector< std::string > headers, unsigned int static_column_size=0, unsigned int cell_padding=1)
Construct the table with headers.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
void size_each(TupleType &&t, std::vector< unsigned int > &sizes)
The function that is actually called that starts the recursion.
void addRow(Ts... entries)
Add a row of data.
void setColumnFormat(const std::vector< VariadicTableColumnFormat > &column_format)
Set how to format numbers for each column.
unsigned int _static_column_size
Size of columns that we can't get the size of.
void print_each(TupleType &&t, StreamType &stream)
This is what gets called first.
std::vector< unsigned int > _column_sizes
Holds the printable width of each column.
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.
std::vector< std::string > _headers
The column headers.
void size_columns()
Finds the size each column should be and set it in _column_sizes.
void size_each(TupleType &&t, std::vector< unsigned int > &sizes, std::integral_constant< size_t, I >)
Recursively called for each element.
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.