This class is used to pretty print tables. Example usage to print a 2x2 Table to std::cout:
Table tab;
tab.add_text_column("name", "Name", 6);
tab.add_float_column("time", "Time");
tab.finish_header();
tab["name"] << "x";
tab["time"] << 1.1;
tab.finish_row();
tab["name"] << "y";
tab["time"] << 1.1;
tab.finish_row();
Note
The << operator should be used only once for each column until calling finish_row.
Methods:
- void add_text_column(std::string key, std::string title, std::size_t width=0)¶
Adds a text column to the table definition.
- void add_float_column(std::string key, std::string title, std::size_t precision=3)¶
Adds a float column to the table definition.
- void add_int_column(std::string key, std::string title, std::size_t width=0)¶
Adds a integer column to the table definition.
- void finish_header()¶
Prints the table header. This should be called after all add_..._column calls.
- void finish_row()¶
Prints the current table row. This should be called after setting the column values for the current row using the [] operator.
- void add_delimiter()¶
Adds a row delimiter used for grouping several rows together.
- std::stringstream& operator[](std::string key)¶
Access the stringstream of the column key for the current row.
- static TableFormat parse_format(const std::string& s)¶
Convert table format name to enum value.