HOG2
Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
Table< Ts > Class Template Reference

#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...
 

Detailed Description

template<class... Ts>
class Table< Ts >

Definition at line 20 of file Table.h.

Member Typedef Documentation

◆ DataTuple

template<class... Ts>
typedef std::tuple<Ts...> Table< Ts >::DataTuple

Definition at line 23 of file Table.h.

Constructor & Destructor Documentation

◆ Table()

template<class... Ts>
Table< Ts >::Table ( std::vector< std::string >  headers,
unsigned int  static_column_size = 0,
unsigned int  cell_padding = 1 
)
inline

Construct the table with headers.

Parameters
headersThe names of the columns
static_column_sizeThe size of columns that can't be found automatically

Definition at line 31 of file Table.h.

References Table< Ts >::_num_columns.

Member Function Documentation

◆ addRow()

template<class... Ts>
void Table< Ts >::addRow ( Ts...  entries)
inline

Add a row of data.

Easiest to use like: table.addRow({data1, data2, data3});

Parameters
dataA Tuple of data to add

Definition at line 50 of file Table.h.

References Table< Ts >::_data.

◆ justify() [1/2]

template<class... Ts>
template<typename T , typename = typename std::enable_if< std::is_arithmetic<typename std::remove_reference<T>::type>::value>::type>
static right_type Table< Ts >::justify ( int  )
inlinestaticprotected

Definition at line 137 of file Table.h.

◆ justify() [2/2]

template<class... Ts>
template<typename T >
static left_type Table< Ts >::justify ( long  )
inlinestaticprotected

Definition at line 144 of file Table.h.

◆ print()

template<class... Ts>
template<typename StreamType >
void Table< Ts >::print ( StreamType &  stream)
inline

◆ print_each() [1/3]

template<class... Ts>
template<typename TupleType , typename StreamType >
void Table< Ts >::print_each ( TupleType &&  ,
StreamType &  ,
std::integral_constant< size_t, std::tuple_size< typename std::remove_reference< TupleType >::type >::value >   
)
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().

◆ print_each() [2/3]

template<class... Ts>
template<typename TupleType , typename StreamType >
void Table< Ts >::print_each ( TupleType &&  t,
StreamType &  stream 
)
inlineprotected

This is what gets called first.

Definition at line 226 of file Table.h.

References Table< Ts >::print_each().

◆ print_each() [3/3]

template<class... Ts>
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 Table< Ts >::print_each ( TupleType &&  t,
StreamType &  stream,
std::integral_constant< size_t, I >   
)
inlineprotected

◆ setColumnFormat()

template<class... Ts>
void Table< Ts >::setColumnFormat ( const std::vector< TableColumnFormat > &  column_format)
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.

◆ setColumnPrecision()

template<class... Ts>
void Table< Ts >::setColumnPrecision ( const std::vector< int > &  precision)
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.

◆ size_columns()

template<class... Ts>
void Table< Ts >::size_columns ( )
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().

◆ size_each() [1/3]

template<class... Ts>
template<typename TupleType >
void Table< Ts >::size_each ( TupleType &&  ,
std::vector< unsigned int > &  ,
std::integral_constant< size_t, std::tuple_size< typename std::remove_reference< TupleType >::type >::value >   
)
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().

◆ size_each() [2/3]

template<class... Ts>
template<typename TupleType >
void Table< Ts >::size_each ( TupleType &&  t,
std::vector< unsigned int > &  sizes 
)
inlineprotected

The function that is actually called that starts the recursion.

Definition at line 304 of file Table.h.

References Table< Ts >::size_each().

◆ size_each() [3/3]

template<class... Ts>
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 Table< Ts >::size_each ( TupleType &&  t,
std::vector< unsigned int > &  sizes,
std::integral_constant< size_t, I >   
)
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().

◆ sizeOfData() [1/3]

template<class... Ts>
size_t 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.

◆ sizeOfData() [2/3]

template<class... Ts>
template<class T >
size_t Table< Ts >::sizeOfData ( const T &  data,
decltype(((T *) nullptr) ->size()) *  = nullptr 
)
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().

◆ sizeOfData() [3/3]

template<class... Ts>
template<class T >
size_t Table< Ts >::sizeOfData ( const T &  data,
typename std::enable_if< std::is_integral< T >::value >::type *  = nullptr 
)
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 248 of file Table.h.

Member Data Documentation

◆ _cell_padding

template<class... Ts>
unsigned int Table< Ts >::_cell_padding
protected

Size of the cell padding.

Definition at line 343 of file Table.h.

Referenced by Table< Ts >::print(), and Table< Ts >::print_each().

◆ _column_format

template<class... Ts>
std::vector<TableColumnFormat> Table< Ts >::_column_format
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().

◆ _column_sizes

template<class... Ts>
std::vector<unsigned int> Table< Ts >::_column_sizes
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().

◆ _data

template<class... Ts>
std::vector<DataTuple> Table< Ts >::_data
protected

The actual data.

Definition at line 346 of file Table.h.

Referenced by Table< Ts >::addRow(), Table< Ts >::print(), and Table< Ts >::size_columns().

◆ _headers

template<class... Ts>
std::vector<std::string> Table< Ts >::_headers
protected

The column headers.

Definition at line 334 of file Table.h.

Referenced by Table< Ts >::print(), and Table< Ts >::size_columns().

◆ _num_columns

template<class... Ts>
unsigned int Table< Ts >::_num_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().

◆ _precision

template<class... Ts>
std::vector<int> Table< Ts >::_precision
protected

Precision For each column.

Definition at line 355 of file Table.h.

Referenced by Table< Ts >::print_each(), and Table< Ts >::setColumnPrecision().

◆ _static_column_size

template<class... Ts>
unsigned int Table< Ts >::_static_column_size
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().

◆ left_type

template<class... Ts>
decltype(&std::left) typedef Table< Ts >::left_type
protected

Definition at line 130 of file Table.h.

◆ right_type

template<class... Ts>
decltype(&std::right) typedef Table< Ts >::right_type
protected

Definition at line 129 of file Table.h.


The documentation for this class was generated from the following file: