[C] Modified examples

This commit is contained in:
seleznevae
2018-08-09 22:15:05 +03:00
parent 694005845a
commit 1873309019
4 changed files with 248 additions and 40 deletions

View File

@@ -36,26 +36,22 @@ void print_char_str(const char *str)
void base_example(void)
{
ft_table_t *table = ft_create_table();
/* Set "header" type for the first row */
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
ft_write_ln(table, "N", "Planet", "Speed, km/s");
ft_write_ln(table, "N", "Driver", "Time", "Avg Speed");
ft_write_ln(table, "1", "Mercury", "47.362");
ft_write_ln(table, "2", "Venus", "35.02");
ft_write_ln(table, "3", "Earth", "29.78");
ft_write_ln(table, "1", "Ricciardo", "1:25.945", "222.128");
ft_write_ln(table, "2", "Hamilton", "1:26.373", "221.027");
ft_write_ln(table, "3", "Verstappen", "1:26.469", "220.782");
printf("%s\n", ft_to_string(table));
ft_destroy_table(table);
}
void different_cell_options(void)
void different_cell_options_example(void)
{
ft_table_t *table = ft_create_table();
/* Change border style */
ft_set_border_style(table, FT_DOUBLE2_STYLE);
/* Set center alignment for the 1st column */
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
/* Set center alignment for the 3rd column */
ft_set_cell_option(table, FT_ANY_ROW, 3, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
/* Set "header" type for the first row */
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
@@ -63,9 +59,33 @@ void different_cell_options(void)
ft_write_ln(table, "The Shawshank Redemption", "Frank Darabont", "1994", "9.5");
ft_write_ln(table, "The Godfather", "Francis Ford Coppola", "1972", "9.2");
ft_write_ln(table, "12 Angry Men", "Sidney Lumet", "1957", "8.8");
ft_write_ln(table, "2001: A Space Odyssey", "Stanley Kubrick", "1968", "8.5");
/* Set center alignment for the 1st and 3rd columns */
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
ft_set_cell_option(table, FT_ANY_ROW, 3, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
printf("%s\n", ft_to_string(table));
ft_destroy_table(table);
}
void fill_table_with_data_example(void)
{
ft_table_t *table = ft_create_table();
/* Set "header" type for the first row */
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
ft_write_ln(table, "N", "Planet", "Speed, km/s", "Temperature, K");
/* Fill row with printf like function */
ft_printf_ln(table, "1|%s|%6.3f|%d", "Mercury", 47.362, 340);
/* Fill row explicitly with strings */
ft_write_ln(table, "2", "Venus", "35.02", "737");
/* Fill row with the array of strings */
const char *arr[4] = {"3", "Earth", "29.78", "288"};
ft_row_write_ln(table, 4, arr);
printf("%s\n", ft_to_string(table));
ft_destroy_table(table);
}
@@ -73,7 +93,8 @@ void different_cell_options(void)
int main(void)
{
base_example();
different_cell_options();
different_cell_options_example();
fill_table_with_data_example();
int result = 0;

View File

@@ -1,9 +1,65 @@
#include <iostream>
#include <vector>
#include "fort.hpp"
void base_example(void)
{
fort::Table table;
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;
}
void different_cell_options_example(void)
{
fort::Table table;
/* 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 */
table.set_cell_text_align(FT_ANY_ROW, 1, fort::TextAlign::Center);
table.set_cell_text_align(FT_ANY_ROW, 3, fort::TextAlign::Center);
std::cout << table.to_string() << std::endl;
}
void fill_table_with_data_example(void)
{
fort::Table table;
table << fort::header
<< "N" << "Planet" << "Speed, km/s" << "Temperature, K" << fort::endr;
/* Fill with iostream << operator */
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"};
table.row_write_ln(std::begin(arr), std::end(arr));
std::cout << table.to_string() << std::endl;
}
int main()
{
base_example();
different_cell_options_example();
fill_table_with_data_example();
{
fort::Table table;
// Fill table with data