115enum class table_type {
135 template <table_type TT>
160constexpr bool is_stream_manipulator_impl() noexcept
162 using Tdec =
typename std::decay<T>::type;
164 return std::is_same<Tdec,
typename std::decay<
decltype(std::dec)>::type>::value
165 || std::is_same<Tdec,
typename std::decay<
decltype(std::hex)>::type>::value
166 || std::is_same<Tdec,
typename std::decay<
decltype(std::oct)>::type>::value
168 || std::is_same<Tdec,
typename std::decay<
decltype(std::fixed)>::type>::value
169 || std::is_same<Tdec,
typename std::decay<
decltype(std::scientific)>::type>::value
171 || std::is_same<Tdec,
typename std::decay<
decltype(std::setbase(0))>::type>::value
172 || std::is_same<Tdec,
typename std::decay<
decltype(std::setfill(
'\0'))>::type>::value
173 || std::is_same<Tdec,
typename std::decay<
decltype(std::setprecision(0))>::type>::value
174 || std::is_same<Tdec,
typename std::decay<
decltype(std::setw(0))>::type>::value;
186 return detail::is_stream_manipulator_impl<T>();
195template <
typename table>
201 : ps_row_idx_(row_idx), ps_coll_idx_(coll_idx),
202 ps_table_(tbl), set_default_properties_(def) {}
387 std::size_t ps_row_idx_;
388 std::size_t ps_coll_idx_;
390 bool set_default_properties_;
392 bool set_property(uint32_t property,
int value)
395 if (set_default_properties_) {
396 status = ft_set_default_cell_prop(property, value);
398 status = ft_set_cell_prop(ps_table_->table_, ps_row_idx_, ps_coll_idx_, property, value);
400 return FT_IS_SUCCESS(status);
412template <table_type TT = table_type::
character>
428 table_(ft_create_table())
431 throw std::bad_alloc();
439 ft_destroy_table(table_);
449 std::unique_ptr<
ft_table_t,
decltype(&ft_destroy_table)>
450 table_copy(ft_copy_table(tbl.table_), &ft_destroy_table);
452 throw std::runtime_error(
"Error during table copy");
454 stream_.str(std::string());
455 if (tbl.stream_.tellp() >= 0) {
456 stream_.str(tbl.stream_.str());
457 stream_.seekp(0, std::ios_base::end);
459 stream_.copyfmt(tbl.stream_);
460 table_ = table_copy.release();
470 if (tbl.stream_.tellp() >= 0) {
471 stream_.str(tbl.stream_.str());
472 stream_.seekp(0, std::ios_base::end);
473 tbl.stream_.str(std::string());
475 stream_.copyfmt(tbl.stream_);
488 std::unique_ptr<
ft_table_t,
decltype(&ft_destroy_table)>
489 table_copy(ft_copy_table(tbl.table_), &ft_destroy_table);
491 throw std::runtime_error(
"Error during table copy");
493 stream_.str(std::string());
494 if (tbl.stream_.tellp() >= 0) {
495 stream_.str(tbl.stream_.str());
496 stream_.seekp(0, std::ios_base::end);
498 stream_.copyfmt(tbl.stream_);
499 ft_destroy_table(table_);
500 table_ = table_copy.release();
514 stream_.str(std::string());
515 if (tbl.stream_.tellp() >= 0) {
516 stream_.str(tbl.stream_.str());
517 stream_.seekp(0, std::ios_base::end);
518 tbl.stream_.str(std::string());
520 stream_.copyfmt(tbl.stream_);
521 ft_destroy_table(table_);
537 const char *str =
c_str();
539 throw std::runtime_error(
"Error during table to string conversion");
561 return (TT == table_type::character)
562 ? ft_to_string(table_)
563 : (
const char *)ft_to_u8string(table_);
565 return ft_to_string(table_);
580 template <
typename T>
583 constexpr bool is_manip = fort::is_stream_manipulator<typename std::decay<T>::type>();
585 if (stream_.tellp() >= 0 && !is_manip) {
587 if (TT == table_type::character) {
588 ft_nwrite(table_, 1, stream_.str().c_str());
590 ft_u8nwrite(table_, 1, (
const void *)stream_.str().c_str());
593 ft_nwrite(table_, 1, stream_.str().c_str());
596 stream_.str(std::string());
603 if (arg.value ==
header.value)
605 else if (arg.value ==
endr.value)
608 ft_add_separator(table_);
626 if (TT == table_type::character) {
627 return FT_IS_SUCCESS(
ft_write(table_, str));
629 return FT_IS_SUCCESS(ft_u8write(table_, (
const void *)str));
632 return FT_IS_SUCCESS(
ft_write(table_, str));
651 if (TT == table_type::character) {
654 return FT_IS_SUCCESS(ft_u8write_ln(table_, str));
674 return write(str.c_str());
694#ifdef __cpp_variadic_templates
709 template <
typename T,
typename ...Ts>
710 bool write(
const T &str,
const Ts &...strings)
730 template <
typename T,
typename ...Ts>
731 bool write_ln(
const T &str,
const Ts &...strings)
737 template <
typename T_0,
typename T_1>
738 bool write(
const T_0 &arg_0,
const T_1 &arg_1)
743 template <
typename T_0,
typename T_1,
typename T_2>
744 bool write(
const T_0 &arg_0,
const T_1 &arg_1,
const T_2 &arg_2)
749 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3>
750 bool write(
const T_0 &arg_0,
const T_1 &arg_1,
const T_2 &arg_2,
const T_3 &arg_3)
752 return write(arg_0) &&
write(arg_1, arg_2, arg_3);
755 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3,
typename T_4>
756 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)
758 return write(arg_0) &&
write(arg_1, arg_2, arg_3, arg_4);
761 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3,
typename T_4,
typename T_5>
762 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)
764 return write(arg_0) &&
write(arg_1, arg_2, arg_3, arg_4, arg_5);
767 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3,
typename T_4,
typename T_5,
typename T_6>
768 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)
770 return write(arg_0) &&
write(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6);
773 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>
774 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)
776 return write(arg_0) &&
write(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6, arg_7);
780 template <
typename T_0,
typename T_1>
781 bool write_ln(
const T_0 &arg_0,
const T_1 &arg_1)
786 template <
typename T_0,
typename T_1,
typename T_2>
787 bool write_ln(
const T_0 &arg_0,
const T_1 &arg_1,
const T_2 &arg_2)
792 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3>
793 bool write_ln(
const T_0 &arg_0,
const T_1 &arg_1,
const T_2 &arg_2,
const T_3 &arg_3)
798 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3,
typename T_4>
799 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)
804 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3,
typename T_4,
typename T_5>
805 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)
807 return write(arg_0) &&
write_ln(arg_1, arg_2, arg_3, arg_4, arg_5);
810 template <
typename T_0,
typename T_1,
typename T_2,
typename T_3,
typename T_4,
typename T_5,
typename T_6>
811 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)
813 return write(arg_0) &&
write_ln(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6);
816 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>
817 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)
819 return write(arg_0) &&
write_ln(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6, arg_7);
835 template <
typename InputIt>
838 while (first != last) {
857 template <
typename InputIt>
860 while (first != last) {
879 return FT_IS_SUCCESS(ft_set_border_style(table_, style));
894 ft_set_cur_cell(table_, row_i, col_i);
909 return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_LEFT_MARGIN, value));
923 return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_TOP_MARGIN, value));
937 return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_RIGHT_MARGIN, value));
951 return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_BOTTOM_MARGIN, value));
965 return FT_IS_SUCCESS(ft_set_tbl_prop(table_,
966 FT_TPROP_ADDING_STRATEGY,
967 static_cast<int>(value)));
971 mutable std::stringstream stream_;
985 using property_owner_t::ps_coll_idx_;
986 using property_owner_t::ps_row_idx_;
987 using property_owner_t::ps_table_;
988 using property_owner_t::set_default_properties_;
995 ft_set_cur_cell(ps_table_->table_, ps_row_idx_, ps_coll_idx_);
996 ps_table_->
write(str);
1000 table_cell &operator=(
const std::string &str)
1002 return operator=(str.c_str());
1016 if (set_default_properties_)
1019 return FT_IS_SUCCESS(ft_set_cell_span(ps_table_->table_, ps_row_idx_, ps_coll_idx_, hor_span));
1028 using property_owner_t::ps_row_idx_;
1029 using property_owner_t::ps_table_;
1035 operator[](std::size_t coll_idx)
1037 return table_cell(ps_row_idx_, coll_idx, *ps_table_);
1042 if (FT_IS_ERROR(ft_erase_range(ps_table_->table_,
1043 property_owner_t::ps_row_idx_, 0,
1044 property_owner_t::ps_row_idx_, FT_MAX_COL_INDEX))) {
1045 throw std::runtime_error(
"Failed to erase row");
1055 using property_owner_t::ps_coll_idx_;
1056 using property_owner_t::ps_table_;
1063 if (FT_IS_ERROR(ft_erase_range(ps_table_->table_,
1065 FT_MAX_ROW_INDEX, ps_coll_idx_))) {
1066 throw std::runtime_error(
"Failed to erase column");
1080 using property_owner_t::ps_coll_idx_;
1081 using property_owner_t::ps_row_idx_;
1082 using property_owner_t::ps_table_;
1084 cell_range(
size_t top_left_row,
size_t top_left_col,
1085 size_t bottom_right_row,
size_t bottom_right_col,
1088 bottom_right_row_(bottom_right_row),
1089 bottom_right_col_(bottom_right_col)
1094 if (FT_IS_ERROR(ft_erase_range(ps_table_->table_,
1095 ps_row_idx_, ps_coll_idx_,
1096 bottom_right_row_, bottom_right_col_))) {
1097 throw std::runtime_error(
"Failed to erase column");
1102 std::size_t bottom_right_row_;
1103 std::size_t bottom_right_col_;
1115 operator[](std::size_t row_idx)
1132 cell(std::size_t row_idx, std::size_t col_idx)
1134 return (*
this)[row_idx][col_idx];
1146 return ft_cur_col(table_);
1158 return ft_cur_row(table_);
1171 return ft_is_empty(table_);
1183 return ft_row_count(table_);
1195 return ft_col_count(table_);
1247 range(std::size_t top_left_row, std::size_t top_left_col,
1248 std::size_t bottom_right_row, std::size_t bottom_right_col)
1250 return cell_range(top_left_row, top_left_col,
1251 bottom_right_row, bottom_right_col,
1255 static class default_properties
1258 return default_properties(NULL);
1289 return FT_IS_SUCCESS(ft_set_default_border_style(style));
bool set_cell_top_padding(unsigned value)
Definition fort.hpp:241
bool set_cell_min_width(unsigned value)
Definition fort.hpp:213
bool set_cell_right_padding(unsigned value)
Definition fort.hpp:283
bool set_cell_content_bg_color(fort::color value)
Definition fort.hpp:353
bool set_cell_row_type(fort::row_type value)
Definition fort.hpp:297
bool set_cell_content_fg_color(fort::color value)
Definition fort.hpp:325
bool set_cell_bg_color(fort::color value)
Definition fort.hpp:339
bool set_cell_left_padding(unsigned value)
Definition fort.hpp:269
bool set_cell_text_align(fort::text_align value)
Definition fort.hpp:227
bool set_cell_bottom_padding(unsigned value)
Definition fort.hpp:255
bool set_cell_empty_str_height(unsigned value)
Definition fort.hpp:311
bool set_cell_content_text_style(fort::text_style value)
Definition fort.hpp:381
bool set_cell_text_style(fort::text_style value)
Definition fort.hpp:367
bool set_cell_span(size_t hor_span)
Definition fort.hpp:1014
bool set_border_style(const struct ft_border_style *style)
Definition fort.hpp:877
std::string to_string() const
Definition fort.hpp:535
bool set_adding_strategy(fort::add_strategy value)
Definition fort.hpp:963
bool set_bottom_margin(unsigned value)
Definition fort.hpp:949
~table()
Definition fort.hpp:437
bool write_ln(const char *str)
Definition fort.hpp:648
size_t cur_col() const noexcept
Definition fort.hpp:1144
class table_row row(std::size_t row_idx)
Definition fort.hpp:1219
bool is_empty() const noexcept
Definition fort.hpp:1169
bool set_left_margin(unsigned value)
Definition fort.hpp:907
table(const table &tbl)
Definition fort.hpp:445
table & operator<<(const T &arg)
Definition fort.hpp:581
table & operator=(const table &tbl)
Definition fort.hpp:482
std::size_t col_count() const noexcept
Definition fort.hpp:1193
const char * c_str() const
Definition fort.hpp:558
table & operator=(table &&tbl)
Definition fort.hpp:508
bool write_ln(const std::string &str)
Definition fort.hpp:689
class table_cell cur_cell()
Definition fort.hpp:1205
std::size_t row_count() const noexcept
Definition fort.hpp:1181
bool write(const std::string &str)
Definition fort.hpp:672
bool set_top_margin(unsigned value)
Definition fort.hpp:921
bool write(const char *str)
Definition fort.hpp:623
size_t cur_row() const noexcept
Definition fort.hpp:1156
bool range_write_ln(InputIt first, InputIt last)
Definition fort.hpp:858
class cell_range range(std::size_t top_left_row, std::size_t top_left_col, std::size_t bottom_right_row, std::size_t bottom_right_col)
Definition fort.hpp:1247
bool range_write(InputIt first, InputIt last)
Definition fort.hpp:836
bool set_right_margin(unsigned value)
Definition fort.hpp:935
table & operator<<(const table_manipulator &arg)
Definition fort.hpp:601
class table_cell cell(std::size_t row_idx, std::size_t col_idx)
Definition fort.hpp:1132
table(table &&tbl)
Definition fort.hpp:467
table()
Definition fort.hpp:426
class table_column column(std::size_t col_idx)
Definition fort.hpp:1233
void set_cur_cell(size_t row_i, size_t col_i)
Definition fort.hpp:892
Main header file describing libfort API.
@ FT_ROW_HEADER
Definition fort.h:880
@ FT_ROW_COMMON
Definition fort.h:879
#define FT_CPROP_RIGHT_PADDING
Definition fort.h:817
#define FT_ANY_ROW
Definition fort.h:800
#define FT_CPROP_TOP_PADDING
Definition fort.h:814
@ FT_ALIGNED_RIGHT
Definition fort.h:872
@ FT_ALIGNED_LEFT
Definition fort.h:870
@ FT_ALIGNED_CENTER
Definition fort.h:871
#define FT_CPROP_BOTTOM_PADDING
Definition fort.h:815
#define ft_write_ln(table,...)
Definition fort.h:547
#define FT_CPROP_LEFT_PADDING
Definition fort.h:816
struct ft_table ft_table_t
Definition fort.h:293
#define FT_CUR_ROW
Definition fort.h:801
#define FT_CPROP_CELL_TEXT_STYLE
Definition fort.h:823
@ FT_COLOR_MAGENTA
Definition fort.h:838
@ FT_COLOR_LIGHT_GRAY
Definition fort.h:840
@ FT_COLOR_CYAN
Definition fort.h:839
@ FT_COLOR_LIGHT_GREEN
Definition fort.h:843
@ FT_COLOR_LIGHT_CYAN
Definition fort.h:847
@ FT_COLOR_DARK_GRAY
Definition fort.h:841
@ FT_COLOR_BLUE
Definition fort.h:837
@ FT_COLOR_BLACK
Definition fort.h:833
@ FT_COLOR_LIGHT_YELLOW
Definition fort.h:844
@ FT_COLOR_LIGHT_MAGENTA
Definition fort.h:846
@ FT_COLOR_GREEN
Definition fort.h:835
@ FT_COLOR_DEFAULT
Definition fort.h:832
@ FT_COLOR_LIGHT_BLUE
Definition fort.h:845
@ FT_COLOR_YELLOW
Definition fort.h:836
@ FT_COLOR_LIGHT_WHYTE
Definition fort.h:848
@ FT_COLOR_LIGHT_RED
Definition fort.h:842
@ FT_COLOR_RED
Definition fort.h:834
#define FT_CPROP_CELL_BG_COLOR
Definition fort.h:821
#define FT_CPROP_CONT_BG_COLOR
Definition fort.h:822
#define FT_CPROP_MIN_WIDTH
Definition fort.h:812
#define FT_CPROP_EMPTY_STR_HEIGHT
Definition fort.h:818
@ FT_TSTYLE_HIDDEN
Definition fort.h:862
@ FT_TSTYLE_BOLD
Definition fort.h:856
@ FT_TSTYLE_ITALIC
Definition fort.h:858
@ FT_TSTYLE_BLINK
Definition fort.h:860
@ FT_TSTYLE_INVERTED
Definition fort.h:861
@ FT_TSTYLE_UNDERLINED
Definition fort.h:859
@ FT_TSTYLE_DEFAULT
Definition fort.h:855
@ FT_TSTYLE_DIM
Definition fort.h:857
#define FT_CPROP_ROW_TYPE
Definition fort.h:819
#define FT_CPROP_CONT_FG_COLOR
Definition fort.h:820
#define FT_ANY_COLUMN
Definition fort.h:798
#define FT_CPROP_TEXT_ALIGN
Definition fort.h:813
#define ft_write(table,...)
Definition fort.h:529
@ FT_STRATEGY_REPLACE
Definition fort.h:934
@ FT_STRATEGY_INSERT
Definition fort.h:935
#define FT_CPROP_CONT_TEXT_STYLE
Definition fort.h:824
constexpr bool is_stream_manipulator() noexcept
Definition fort.hpp:184
row_type
Definition fort.hpp:61
color
Definition fort.hpp:80
const table_manipulator header(0)
text_align
Definition fort.hpp:52
add_strategy
Definition fort.hpp:72
text_style
Definition fort.hpp:103
bool set_default_border_style(struct ft_border_style *style)
Definition fort.hpp:1287
const table_manipulator endr(1)
const table_manipulator separator(2)