41 #include <type_traits> 114 enum class table_type {
134 template <table_type TT>
158 template <
typename T>
159 constexpr
bool is_stream_manipulator_impl() noexcept
161 using Tdec =
typename std::decay<T>::type;
163 return std::is_same<Tdec, typename std::decay<decltype(std::dec)>::type>::value
164 || std::is_same<Tdec, typename std::decay<decltype(std::hex)>::type>::value
165 || std::is_same<Tdec, typename std::decay<decltype(std::oct)>::type>::value
167 || std::is_same<Tdec, typename std::decay<decltype(std::fixed)>::type>::value
168 || std::is_same<Tdec, typename std::decay<decltype(std::scientific)>::type>::value
170 || std::is_same<Tdec, typename std::decay<decltype(std::setbase(0))>::type>::value
171 || std::is_same<Tdec, typename std::decay<decltype(std::setfill('\0'))>::type>::value
172 || std::is_same<Tdec, typename std::decay<decltype(std::setprecision(0))>::type>::value
173 || std::is_same<Tdec, typename std::decay<decltype(std::setw(0))>::type>::value;
182 template <
typename T>
185 return detail::is_stream_manipulator_impl<T>();
194 template <
typename table>
200 : ps_row_idx_(row_idx), ps_coll_idx_(coll_idx),
201 ps_table_(tbl), set_default_properties_(def) {}
386 std::size_t ps_row_idx_;
387 std::size_t ps_coll_idx_;
389 bool set_default_properties_;
391 bool set_property(uint32_t property,
int value)
394 if (set_default_properties_) {
397 status =
ft_set_cell_prop(ps_table_->table_, ps_row_idx_, ps_coll_idx_, property, value);
399 return FT_IS_SUCCESS(status);
411 template <table_type TT = table_type::
character>
430 throw std::bad_alloc();
449 if (table_copy == NULL)
450 throw std::runtime_error(
"Error during table copy");
452 stream_.str(std::string());
453 if (tbl.stream_.tellp() >= 0) {
454 stream_ << tbl.stream_.str();
466 if (tbl.stream_.tellp() >= 0) {
467 stream_ << tbl.stream_.str();
468 tbl.stream_.str(std::string());
483 if (table_copy == NULL)
484 throw std::runtime_error(
"Error during table copy");
486 stream_.str(std::string());
487 if (tbl.stream_.tellp() >= 0) {
488 stream_ << tbl.stream_.str();
505 stream_.str(std::string());
506 if (tbl.stream_.tellp() >= 0) {
507 stream_ << tbl.stream_.str();
508 tbl.stream_.str(std::string());
526 const char *str = c_str();
528 throw std::runtime_error(
"Error during table to string conversion");
550 return (TT == table_type::character)
552 : (
const char *)ft_to_u8string(table_);
569 template <
typename T>
572 constexpr
bool is_manip = fort::is_stream_manipulator<typename std::decay<T>::type>();
574 if (stream_.tellp() >= 0 && !is_manip) {
576 if (TT == table_type::character) {
577 ft_nwrite(table_, 1, stream_.str().c_str());
579 ft_u8nwrite(table_, 1, (
const void *)stream_.str().c_str());
582 ft_nwrite(table_, 1, stream_.str().c_str());
585 stream_.str(std::string());
592 if (arg.value == header.value)
594 else if (arg.value == endr.value)
596 else if (arg.value == separator.value)
615 if (TT == table_type::character) {
616 return FT_IS_SUCCESS(
ft_write(table_, str));
618 return FT_IS_SUCCESS(ft_u8write(table_, (
const void *)str));
621 return FT_IS_SUCCESS(
ft_write(table_, str));
640 if (TT == table_type::character) {
643 return FT_IS_SUCCESS(ft_u8write_ln(table_, str));
663 return write(str.c_str());
680 return write_ln(str.c_str());
683 #ifdef __cpp_variadic_templates 698 template <
typename T,
typename ...Ts>
699 bool write(
const T &str,
const Ts &...strings)
701 return write(str) && write(strings...);
719 template <
typename T,
typename ...Ts>
720 bool write_ln(
const T &str,
const Ts &...strings)
722 return write(str) && write_ln(strings...);
726 template <
typename T_0,
typename T_1>
727 bool write(
const T_0 &arg_0,
const T_1 &arg_1)
729 return write(arg_0) && write(arg_1);
732 template <
typename T_0,
typename T_1,
typename T_2>
733 bool write(
const T_0 &arg_0,
const T_1 &arg_1,
const T_2 &arg_2)
735 return write(arg_0) && write(arg_1, arg_2);
738 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3>
739 bool write(
const T_0 &arg_0,
const T_1 &arg_1,
const T_2 &arg_2,
const T_3 &arg_3)
741 return write(arg_0) && write(arg_1, arg_2, arg_3);
744 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3,
typename T_4>
745 bool write(
const T_0 &arg_0,
const T_1 &arg_1,
const T_2 &arg_2,
const T_3 &arg_3,
const T_4 &arg_4)
747 return write(arg_0) && write(arg_1, arg_2, arg_3, arg_4);
750 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3,
typename T_4,
typename T_5>
751 bool write(
const T_0 &arg_0,
const T_1 &arg_1,
const T_2 &arg_2,
const T_3 &arg_3,
const T_4 &arg_4,
const T_5 &arg_5)
753 return write(arg_0) && write(arg_1, arg_2, arg_3, arg_4, arg_5);
756 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3,
typename T_4,
typename T_5,
typename T_6>
757 bool write(
const T_0 &arg_0,
const T_1 &arg_1,
const T_2 &arg_2,
const T_3 &arg_3,
const T_4 &arg_4,
const T_5 &arg_5,
const T_6 &arg_6)
759 return write(arg_0) && write(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6);
762 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3,
typename T_4,
typename T_5,
typename T_6,
typename T_7>
763 bool write(
const T_0 &arg_0,
const T_1 &arg_1,
const T_2 &arg_2,
const T_3 &arg_3,
const T_4 &arg_4,
const T_5 &arg_5,
const T_6 &arg_6,
const T_7 &arg_7)
765 return write(arg_0) && write(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6, arg_7);
769 template <
typename T_0,
typename T_1>
770 bool write_ln(
const T_0 &arg_0,
const T_1 &arg_1)
772 return write(arg_0) && write_ln(arg_1);
775 template <
typename T_0,
typename T_1,
typename T_2>
776 bool write_ln(
const T_0 &arg_0,
const T_1 &arg_1,
const T_2 &arg_2)
778 return write(arg_0) && write_ln(arg_1, arg_2);
781 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3>
782 bool write_ln(
const T_0 &arg_0,
const T_1 &arg_1,
const T_2 &arg_2,
const T_3 &arg_3)
784 return write(arg_0) && write_ln(arg_1, arg_2, arg_3);
787 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3,
typename T_4>
788 bool write_ln(
const T_0 &arg_0,
const T_1 &arg_1,
const T_2 &arg_2,
const T_3 &arg_3,
const T_4 &arg_4)
790 return write(arg_0) && write_ln(arg_1, arg_2, arg_3, arg_4);
793 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3,
typename T_4,
typename T_5>
794 bool write_ln(
const T_0 &arg_0,
const T_1 &arg_1,
const T_2 &arg_2,
const T_3 &arg_3,
const T_4 &arg_4,
const T_5 &arg_5)
796 return write(arg_0) && write_ln(arg_1, arg_2, arg_3, arg_4, arg_5);
799 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3,
typename T_4,
typename T_5,
typename T_6>
800 bool write_ln(
const T_0 &arg_0,
const T_1 &arg_1,
const T_2 &arg_2,
const T_3 &arg_3,
const T_4 &arg_4,
const T_5 &arg_5,
const T_6 &arg_6)
802 return write(arg_0) && write_ln(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6);
805 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3,
typename T_4,
typename T_5,
typename T_6,
typename T_7>
806 bool write_ln(
const T_0 &arg_0,
const T_1 &arg_1,
const T_2 &arg_2,
const T_3 &arg_3,
const T_4 &arg_4,
const T_5 &arg_5,
const T_6 &arg_6,
const T_7 &arg_7)
808 return write(arg_0) && write_ln(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6, arg_7);
824 template <
typename InputIt>
827 while (first != last) {
846 template <
typename InputIt>
849 while (first != last) {
898 return FT_IS_SUCCESS(
ft_set_tbl_prop(table_, FT_TPROP_LEFT_MARGIN, value));
912 return FT_IS_SUCCESS(
ft_set_tbl_prop(table_, FT_TPROP_TOP_MARGIN, value));
926 return FT_IS_SUCCESS(
ft_set_tbl_prop(table_, FT_TPROP_RIGHT_MARGIN, value));
940 return FT_IS_SUCCESS(
ft_set_tbl_prop(table_, FT_TPROP_BOTTOM_MARGIN, value));
955 FT_TPROP_ADDING_STRATEGY,
956 static_cast<int>(value)));
960 mutable std::stringstream stream_;
974 using property_owner_t::ps_coll_idx_;
975 using property_owner_t::ps_row_idx_;
976 using property_owner_t::ps_table_;
977 using property_owner_t::set_default_properties_;
979 table_cell(std::size_t row_idx, std::size_t coll_idx, table &tbl)
985 ps_table_->write(str);
991 return operator=(str.c_str());
1005 if (set_default_properties_)
1008 return FT_IS_SUCCESS(
ft_set_cell_span(ps_table_->table_, ps_row_idx_, ps_coll_idx_, hor_span));
1017 using property_owner_t::ps_row_idx_;
1018 using property_owner_t::ps_table_;
1020 table_row(std::size_t row_idx, table &tbl)
1024 operator[](std::size_t coll_idx)
1026 return table_cell(ps_row_idx_, coll_idx, *ps_table_);
1032 property_owner_t::ps_row_idx_, 0,
1033 property_owner_t::ps_row_idx_, FT_MAX_COL_INDEX))) {
1034 throw std::runtime_error(
"Failed to erase row");
1044 using property_owner_t::ps_coll_idx_;
1045 using property_owner_t::ps_table_;
1054 FT_MAX_ROW_INDEX, ps_coll_idx_))) {
1055 throw std::runtime_error(
"Failed to erase column");
1069 using property_owner_t::ps_coll_idx_;
1070 using property_owner_t::ps_row_idx_;
1071 using property_owner_t::ps_table_;
1073 cell_range(
size_t top_left_row,
size_t top_left_col,
1074 size_t bottom_right_row,
size_t bottom_right_col,
1077 bottom_right_row_(bottom_right_row),
1078 bottom_right_col_(bottom_right_col)
1084 ps_row_idx_, ps_coll_idx_,
1085 bottom_right_row_, bottom_right_col_))) {
1086 throw std::runtime_error(
"Failed to erase column");
1091 std::size_t bottom_right_row_;
1092 std::size_t bottom_right_col_;
1104 operator[](std::size_t row_idx)
1121 cell(std::size_t row_idx, std::size_t col_idx)
1123 return (*
this)[row_idx][col_idx];
1184 return cell(cur_row(), cur_col());
1196 row(std::size_t row_idx)
1210 column(std::size_t col_idx)
1224 range(std::size_t top_left_row, std::size_t top_left_col,
1225 std::size_t bottom_right_row, std::size_t bottom_right_col)
1227 return cell_range(top_left_row, top_left_col,
1228 bottom_right_row, bottom_right_col,
1272 #endif // LIBFORT_HPP bool range_write(InputIt first, InputIt last)
Definition: fort.hpp:825
const table_manipulator endr(1)
table(table &&tbl)
Definition: fort.hpp:463
bool set_cell_content_fg_color(fort::color value)
Definition: fort.hpp:324
table()
Definition: fort.hpp:425
int ft_set_border_style(ft_table_t *table, const struct ft_border_style *style)
Definition: fort.c:3551
table & operator<<(const table_manipulator &arg)
Definition: fort.hpp:590
bool write_ln(const std::string &str)
Definition: fort.hpp:678
bool set_cell_bottom_padding(unsigned value)
Definition: fort.hpp:254
int ft_erase_range(ft_table_t *table, size_t top_left_row, size_t top_left_col, size_t bottom_right_row, size_t bottom_right_col)
Definition: fort.c:2832
#define FT_CUR_ROW
Definition: fort.h:768
bool set_cell_top_padding(unsigned value)
Definition: fort.hpp:240
#define ft_write_ln(table,...)
Definition: fort.h:514
row_type
Definition: fort.hpp:60
#define FT_CPROP_CELL_BG_COLOR
Definition: fort.h:788
ft_table_t * ft_copy_table(ft_table_t *table)
Definition: fort.c:2697
int ft_set_tbl_prop(ft_table_t *table, uint32_t property, int value)
Definition: fort.c:3600
size_t cur_row() const noexcept
Definition: fort.hpp:1145
size_t ft_cur_row(const ft_table_t *table)
Definition: fort.c:2801
table & operator=(const table &tbl)
Definition: fort.hpp:476
bool set_cell_empty_str_height(unsigned value)
Definition: fort.hpp:310
#define FT_CPROP_MIN_WIDTH
Definition: fort.h:779
#define FT_CPROP_TOP_PADDING
Definition: fort.h:781
Main header file describing libfort API.
int ft_set_default_border_style(const struct ft_border_style *style)
Definition: fort.c:3545
#define FT_ANY_COLUMN
Definition: fort.h:765
Definition: fort.hpp:1042
const table_manipulator separator(2)
void ft_set_cur_cell(ft_table_t *table, size_t row, size_t col)
Definition: fort.c:2813
bool set_border_style(const struct ft_border_style *style)
Definition: fort.hpp:866
ft_table_t * ft_create_table(void)
Definition: fort.c:2639
bool set_adding_strategy(fort::add_strategy value)
Definition: fort.hpp:952
#define FT_CPROP_ROW_TYPE
Definition: fort.h:786
void set_cur_cell(size_t row_i, size_t col_i)
Definition: fort.hpp:881
~table()
Definition: fort.hpp:436
void ft_destroy_table(ft_table_t *table)
Definition: fort.c:2671
bool write(const char *str)
Definition: fort.hpp:612
std::size_t row_count() const noexcept
Definition: fort.hpp:1170
table(const table &tbl)
Definition: fort.hpp:444
constexpr bool is_stream_manipulator() noexcept
Definition: fort.hpp:183
Definition: fort.hpp:1067
int ft_add_separator(ft_table_t *table)
Definition: fort.c:3418
bool set_top_margin(unsigned value)
Definition: fort.hpp:910
bool set_cell_row_type(fort::row_type value)
Definition: fort.hpp:296
std::string to_string() const
Definition: fort.hpp:524
bool set_cell_text_align(fort::text_align value)
Definition: fort.hpp:226
table & operator=(table &&tbl)
Definition: fort.hpp:499
bool write(const std::string &str)
Definition: fort.hpp:661
#define FT_CPROP_CONT_FG_COLOR
Definition: fort.h:787
int ft_set_cell_span(ft_table_t *table, size_t row, size_t col, size_t hor_span)
Definition: fort.c:3636
bool set_bottom_margin(unsigned value)
Definition: fort.hpp:938
#define FT_CPROP_EMPTY_STR_HEIGHT
Definition: fort.h:785
bool set_cell_content_text_style(fort::text_style value)
Definition: fort.hpp:380
Definition: fort.hpp:1015
bool set_cell_right_padding(unsigned value)
Definition: fort.hpp:282
color
Definition: fort.hpp:79
int ft_set_default_cell_prop(uint32_t property, int value)
Definition: fort.c:3589
const table_manipulator header(0)
#define FT_CPROP_CONT_BG_COLOR
Definition: fort.h:789
#define FT_CPROP_TEXT_ALIGN
Definition: fort.h:780
bool set_right_margin(unsigned value)
Definition: fort.hpp:924
const char * c_str() const
Definition: fort.hpp:547
#define FT_CPROP_LEFT_PADDING
Definition: fort.h:783
int ft_set_cell_prop(ft_table_t *table, size_t row, size_t col, uint32_t property, int value)
Definition: fort.c:3565
text_align
Definition: fort.hpp:51
#define FT_CPROP_CONT_TEXT_STYLE
Definition: fort.h:791
bool set_cell_content_bg_color(fort::color value)
Definition: fort.hpp:352
size_t ft_cur_col(const ft_table_t *table)
Definition: fort.c:2807
bool is_empty() const noexcept
Definition: fort.hpp:1158
#define FT_CPROP_BOTTOM_PADDING
Definition: fort.h:782
size_t cur_col() const noexcept
Definition: fort.hpp:1133
int ft_nwrite(ft_table_t *table, size_t count, const char *cell_content,...)
Definition: fort.c:3092
bool set_default_border_style(struct ft_border_style *style)
Definition: fort.hpp:1264
bool set_left_margin(unsigned value)
Definition: fort.hpp:896
int ft_ln(ft_table_t *table)
Definition: fort.c:2771
#define FT_ANY_ROW
Definition: fort.h:767
Definition: fort.hpp:1096
bool set_cell_left_padding(unsigned value)
Definition: fort.hpp:268
#define FT_CPROP_CELL_TEXT_STYLE
Definition: fort.h:790
bool set_cell_span(size_t hor_span)
Definition: fort.hpp:1003
bool set_cell_bg_color(fort::color value)
Definition: fort.hpp:338
add_strategy
Definition: fort.hpp:71
bool write_ln(const char *str)
Definition: fort.hpp:637
const char * ft_to_string(const ft_table_t *table)
Definition: fort.c:3405
bool range_write_ln(InputIt first, InputIt last)
Definition: fort.hpp:847
bool set_cell_min_width(unsigned value)
Definition: fort.hpp:212
int ft_is_empty(const ft_table_t *table)
Definition: fort.c:2820
text_style
Definition: fort.hpp:102
#define ft_write(table,...)
Definition: fort.h:496
bool set_cell_text_style(fort::text_style value)
Definition: fort.hpp:366
#define FT_CPROP_RIGHT_PADDING
Definition: fort.h:784
size_t ft_row_count(const ft_table_t *table)
Definition: fort.c:2826
table & operator<<(const T &arg)
Definition: fort.hpp:570