2018-04-01 10:36:52 +02:00
|
|
|
#include <iostream>
|
2018-08-09 21:15:05 +02:00
|
|
|
#include <vector>
|
2018-04-01 10:36:52 +02:00
|
|
|
#include "fort.hpp"
|
|
|
|
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table create_basic_table(void)
|
2018-11-03 18:24:50 +01:00
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table table;
|
2018-11-03 18:24:50 +01:00
|
|
|
/* Set table border style */
|
|
|
|
table.set_border_style(FT_BASIC_STYLE);
|
|
|
|
|
|
|
|
// Fill table with data
|
|
|
|
table << fort::header
|
|
|
|
<< "Rank" << "Title" << "Year" << "Rating" << fort::endr
|
|
|
|
<< "1" << "The Shawshank Redemption" << "1994" << "9.5" << fort::endr
|
|
|
|
<< "2" << "12 Angry Men" << "1957" << "8.8" << fort::endr
|
|
|
|
<< "3" << "It's a Wonderful Life" << "1946" << "8.6" << fort::endr
|
|
|
|
<< fort::separator
|
|
|
|
<< "4" << "2001: A Space Odyssey" << "1968" << "8.5" << fort::endr
|
|
|
|
<< "5" << "Blade Runner" << "1982" << "8.1" << fort::endr
|
|
|
|
<< fort::endr;
|
|
|
|
|
2018-11-21 18:50:56 +01:00
|
|
|
table.column(0).set_cell_text_align(fort::text_align::center);
|
|
|
|
table.column(1).set_cell_text_align(fort::text_align::left);
|
2018-11-03 18:24:50 +01:00
|
|
|
|
|
|
|
std::cout << table.to_string() << std::endl;
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
2018-08-09 21:15:05 +02:00
|
|
|
void base_example(void)
|
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table table;
|
2018-08-09 21:15:05 +02:00
|
|
|
table << fort::header
|
|
|
|
<< "N" << "Driver" << "Time" << "Avg Speed" << fort::endr
|
|
|
|
<< "1" << "Ricciardo" << "1:25.945" << "47.362" << fort::endr
|
|
|
|
<< "2" << "Hamilton" << "1:26.373" << "35.02" << fort::endr
|
|
|
|
<< "3" << "Verstappen" << "1:26.469" << "29.78" << fort::endr;
|
|
|
|
|
|
|
|
std::cout << table.to_string() << std::endl;
|
|
|
|
}
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
void different_cell_properties_example(void)
|
2018-08-09 21:15:05 +02:00
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table table;
|
2018-08-09 21:15:05 +02:00
|
|
|
/* Change border style */
|
|
|
|
table.set_border_style(FT_DOUBLE2_STYLE);
|
|
|
|
|
|
|
|
table << fort::header
|
|
|
|
<< "Movie title" << "Director" << "Year" << "Rating" << fort::endr
|
|
|
|
<< "The Shawshank Redemption" << "Frank Darabont" << "1994" << "9.5" << fort::endr
|
|
|
|
<< "The Godfather" << "Francis Ford Coppola" << "1972" << "9.2" << fort::endr
|
|
|
|
<< "2001: A Space Odyssey" << "Stanley Kubrick" << "1968" << "8.5" << fort::endr;
|
|
|
|
|
|
|
|
/* Set center alignment for the 1st and 3rd columns */
|
2018-11-21 18:50:56 +01:00
|
|
|
table.column(1).set_cell_text_align(fort::text_align::center);
|
|
|
|
table.column(3).set_cell_text_align(fort::text_align::center);
|
|
|
|
|
2018-08-09 21:15:05 +02:00
|
|
|
|
|
|
|
std::cout << table.to_string() << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void fill_table_with_data_example(void)
|
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table table;
|
2018-08-12 11:00:07 +02:00
|
|
|
table << fort::header;
|
|
|
|
/* Fill each cell with operator[] */
|
|
|
|
table [0][0] = "N";
|
|
|
|
table [0][1] = "Planet";
|
|
|
|
table [0][2] = "Speed, km/s";
|
|
|
|
table [0][3] = "Temperature, K";
|
|
|
|
table << fort::endr;
|
|
|
|
|
2018-08-09 21:15:05 +02:00
|
|
|
|
2018-08-12 11:00:07 +02:00
|
|
|
/* Fill with iostream operator<< */
|
2018-08-09 21:15:05 +02:00
|
|
|
table << 1 << "Mercury" << 47.362 << 340 << fort::endr;
|
|
|
|
|
|
|
|
/* Fill row explicitly with strings */
|
|
|
|
table.write_ln("2", "Venus", "35.02", "737");
|
|
|
|
|
|
|
|
/* Fill row with data from the container */
|
|
|
|
std::vector<std::string> arr = {"3", "Earth", "29.78", "288"};
|
2018-12-01 08:39:25 +01:00
|
|
|
table.range_write_ln(std::begin(arr), std::end(arr));
|
2018-08-09 21:15:05 +02:00
|
|
|
|
|
|
|
std::cout << table.to_string() << std::endl;
|
|
|
|
}
|
|
|
|
|
2018-04-01 10:36:52 +02:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2018-08-09 21:15:05 +02:00
|
|
|
base_example();
|
2018-11-03 21:50:30 +01:00
|
|
|
different_cell_properties_example();
|
2018-08-09 21:15:05 +02:00
|
|
|
fill_table_with_data_example();
|
|
|
|
|
2018-04-08 14:48:15 +02:00
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table table;
|
2018-04-08 14:48:15 +02:00
|
|
|
// Fill table with data
|
|
|
|
table << fort::header
|
2018-07-22 21:52:55 +02:00
|
|
|
<< "Rank" << "Title" << "Year" << "Rating" << fort::endr
|
|
|
|
<< "1" << "The Shawshank Redemption" << "1994" << "9.5" << fort::endr
|
|
|
|
<< "2" << "12 Angry Men" << "1957" << "8.8" << fort::endr
|
|
|
|
<< "3" << "It's a Wonderful Life" << "1946" << "8.6" << fort::endr
|
2018-04-08 14:48:15 +02:00
|
|
|
<< fort::separator
|
2018-07-22 21:52:55 +02:00
|
|
|
<< "4" << "2001: A Space Odyssey" << "1968" << "8.5" << fort::endr
|
|
|
|
<< "5" << "Blade Runner" << "1982" << "8.1" << fort::endr
|
|
|
|
<< fort::endr;
|
2018-07-29 08:59:40 +02:00
|
|
|
|
2018-11-21 18:50:56 +01:00
|
|
|
table[0][0].set_cell_min_width(20);
|
|
|
|
table[0][0].set_cell_text_align(fort::text_align::left);
|
|
|
|
table[2].set_cell_row_type(fort::row_type::header);
|
2018-07-29 08:59:40 +02:00
|
|
|
|
2018-04-08 14:48:15 +02:00
|
|
|
std::cout << table.to_string() << std::endl;
|
|
|
|
}
|
2018-04-01 10:36:52 +02:00
|
|
|
|
|
|
|
|
2018-04-08 14:48:15 +02:00
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
fort::table table;
|
2018-04-08 14:48:15 +02:00
|
|
|
// Fill table with data
|
|
|
|
table << fort::header;
|
|
|
|
table.write_ln("Rank", "Title", "Year", "Rating");
|
|
|
|
table.write_ln("1", "The Shawshank Redemption", "1994", "9.5");
|
|
|
|
table.write_ln("2", "12 Angry Men", "1957", "8.8");
|
|
|
|
table.write_ln("3", "It's a Wonderful Life", "1946", "8.6");
|
|
|
|
table.write_ln("4", "2001: A Space Odyssey", "1968", "8.5");
|
|
|
|
table.write_ln("5", "Blade Runner", "1982", "8.1");
|
2018-07-22 21:52:55 +02:00
|
|
|
|
2018-07-25 21:37:10 +02:00
|
|
|
|
2018-11-21 18:50:56 +01:00
|
|
|
table[0][0].set_cell_min_width(20);
|
|
|
|
table[0][0].set_cell_text_align(fort::text_align::left);
|
|
|
|
table.row(2).set_cell_row_type(fort::row_type::header);
|
2018-07-25 21:37:10 +02:00
|
|
|
|
2018-11-21 18:50:56 +01:00
|
|
|
table.set_left_margin(4);
|
2018-07-25 21:37:10 +02:00
|
|
|
|
2018-07-22 21:52:55 +02:00
|
|
|
table.set_border_style(FT_SOLID_STYLE);
|
2018-04-08 14:48:15 +02:00
|
|
|
std::cout << table.to_string();
|
|
|
|
}
|
2018-11-24 10:38:01 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
fort::table table;
|
|
|
|
// Fill table with data
|
|
|
|
table << fort::header
|
|
|
|
<< "Rank" << "Title" << "Year" << "Rating" << fort::endr
|
|
|
|
<< "1" << "The Shawshank Redemption" << "1994" << "9.5" << fort::endr
|
|
|
|
<< "2" << "12 Angry Men" << "1957" << "8.8" << fort::endr
|
|
|
|
<< "3" << "It's a Wonderful Life" << "1946" << "8.6" << fort::endr
|
|
|
|
<< fort::endr;
|
|
|
|
|
|
|
|
table[0][0].set_cell_min_width(20);
|
|
|
|
table.column(1).set_cell_text_align(fort::text_align::center);
|
|
|
|
table[3][3].set_cell_left_padding(15);
|
|
|
|
|
|
|
|
std::cout << table.to_string() << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
fort::table table;
|
|
|
|
/* Set table border style */
|
|
|
|
table.set_border_style(FT_BASIC_STYLE);
|
|
|
|
|
|
|
|
// Fill table with data
|
|
|
|
table << fort::header
|
|
|
|
<< "Rank" << "Title" << "Year" << "Rating" << fort::endr
|
|
|
|
<< "1" << "The Shawshank Redemption" << "1994" << "9.5" << fort::endr
|
|
|
|
<< "2" << "12 Angry Men" << "1957" << "8.8" << fort::endr
|
|
|
|
<< "3" << "It's a Wonderful Life" << "1946" << "8.6" << fort::endr
|
|
|
|
<< fort::separator
|
|
|
|
<< "4" << "2001: A Space Odyssey" << "1968" << "8.5" << fort::endr
|
|
|
|
<< "5" << "Blade Runner" << "1982" << "8.1" << fort::endr
|
|
|
|
<< fort::endr;
|
|
|
|
|
|
|
|
table.column(0).set_cell_text_align(fort::text_align::center);
|
|
|
|
table.column(1).set_cell_text_align(fort::text_align::left);
|
|
|
|
|
|
|
|
std::cout << table.to_string() << std::endl;
|
|
|
|
}
|
2018-04-01 10:36:52 +02:00
|
|
|
return 0;
|
|
|
|
}
|