libfort
Loading...
Searching...
No Matches
fort.hpp
Go to the documentation of this file.
1/*
2libfort
3
4MIT License
5
6Copyright (c) 2017 - 2026 Seleznev Anton
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in all
16copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24SOFTWARE.
25*/
26
34#ifndef LIBFORT_HPP
35#define LIBFORT_HPP
36
37#include <iomanip>
38#include <memory>
39#include <sstream>
40#include <string>
41#include <stdexcept>
42#include <type_traits>
43
44#include "fort.h"
45
46namespace fort
47{
48
52enum class text_align {
53 left = FT_ALIGNED_LEFT,
54 center = FT_ALIGNED_CENTER,
55 right = FT_ALIGNED_RIGHT
56};
57
61enum class row_type {
62 common = FT_ROW_COMMON,
64};
65
72enum class add_strategy {
73 replace = FT_STRATEGY_REPLACE,
74 insert = FT_STRATEGY_INSERT
75};
76
80enum class color {
81 default_color = FT_COLOR_DEFAULT,
82 black = FT_COLOR_BLACK,
83 red = FT_COLOR_RED,
84 green = FT_COLOR_GREEN,
85 yellow = FT_COLOR_YELLOW,
86 blue = FT_COLOR_BLUE,
87 magenta = FT_COLOR_MAGENTA,
88 cyan = FT_COLOR_CYAN,
89 light_gray = FT_COLOR_LIGHT_GRAY,
90 dark_gray = FT_COLOR_DARK_GRAY,
91 light_red = FT_COLOR_LIGHT_RED,
92 light_green = FT_COLOR_LIGHT_GREEN,
93 light_yellow = FT_COLOR_LIGHT_YELLOW,
94 light_blue = FT_COLOR_LIGHT_BLUE,
95 light_magenta = FT_COLOR_LIGHT_MAGENTA,
96 light_cyan = FT_COLOR_LIGHT_CYAN,
97 light_whyte = FT_COLOR_LIGHT_WHYTE
98};
99
103enum class text_style {
104 default_style = FT_TSTYLE_DEFAULT,
105 bold = FT_TSTYLE_BOLD,
106 dim = FT_TSTYLE_DIM,
107 italic = FT_TSTYLE_ITALIC,
108 underlined = FT_TSTYLE_UNDERLINED,
109 blink = FT_TSTYLE_BLINK,
110 inverted = FT_TSTYLE_INVERTED,
111 hidden = FT_TSTYLE_HIDDEN
112};
113
114
115enum class table_type {
116 character,
117#ifdef FT_HAVE_UTF8
118 utf8
119#endif /* FT_HAVE_UTF8 */
120};
121
129{
130public:
131 explicit table_manipulator(int i)
132 : value(i)
133 {
134 }
135 template <table_type TT>
136 friend class table;
137private:
138 int value;
139};
140
145
150
155
156// Utility functions for internal library usage.
157namespace detail
158{
159template <typename T>
160constexpr bool is_stream_manipulator_impl() noexcept
161{
162 using Tdec = typename std::decay<T>::type;
163 // Manipulators for integral types
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
167 // Floating-point manipulators
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
170 // Misc
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;
175}
176}
177
183template <typename T>
184constexpr bool is_stream_manipulator() noexcept
185{
186 return detail::is_stream_manipulator_impl<T>();
187}
188
195template <typename table>
197{
198public:
199
200 property_owner(std::size_t row_idx, std::size_t coll_idx, table *tbl, bool def = false)
201 : ps_row_idx_(row_idx), ps_coll_idx_(coll_idx),
202 ps_table_(tbl), set_default_properties_(def) {}
203
213 bool set_cell_min_width(unsigned value)
214 {
215 return set_property(FT_CPROP_MIN_WIDTH, value);
216 }
217
228 {
229 return set_property(FT_CPROP_TEXT_ALIGN, static_cast<int>(value));
230 }
231
241 bool set_cell_top_padding(unsigned value)
242 {
243 return set_property(FT_CPROP_TOP_PADDING, value);
244 }
245
255 bool set_cell_bottom_padding(unsigned value)
256 {
257 return set_property(FT_CPROP_BOTTOM_PADDING, value);
258 }
259
269 bool set_cell_left_padding(unsigned value)
270 {
271 return set_property(FT_CPROP_LEFT_PADDING, value);
272 }
273
283 bool set_cell_right_padding(unsigned value)
284 {
285 return set_property(FT_CPROP_RIGHT_PADDING, value);
286 }
287
298 {
299 return set_property(FT_CPROP_ROW_TYPE, static_cast<int>(value));
300 }
301
311 bool set_cell_empty_str_height(unsigned value)
312 {
313 return set_property(FT_CPROP_EMPTY_STR_HEIGHT, value);
314 }
315
326 {
327 return set_property(FT_CPROP_CONT_FG_COLOR, static_cast<int>(value));
328 }
329
340 {
341 return set_property(FT_CPROP_CELL_BG_COLOR, static_cast<int>(value));
342 }
343
354 {
355 return set_property(FT_CPROP_CONT_BG_COLOR, static_cast<int>(value));
356 }
357
368 {
369 return set_property(FT_CPROP_CELL_TEXT_STYLE, static_cast<int>(value));
370 }
371
382 {
383 return set_property(FT_CPROP_CONT_TEXT_STYLE, static_cast<int>(value));
384 }
385
386protected:
387 std::size_t ps_row_idx_;
388 std::size_t ps_coll_idx_;
389 table *ps_table_;
390 bool set_default_properties_;
391
392 bool set_property(uint32_t property, int value)
393 {
394 int status;
395 if (set_default_properties_) {
396 status = ft_set_default_cell_prop(property, value);
397 } else {
398 status = ft_set_cell_prop(ps_table_->table_, ps_row_idx_, ps_coll_idx_, property, value);
399 }
400 return FT_IS_SUCCESS(status);
401 }
402};
403
404
412template <table_type TT = table_type::character>
413class table: public property_owner<table<TT>>
414{
418 using table_t = table<TT>;
420
421public:
422
428 table_(ft_create_table())
429 {
430 if (table_ == NULL)
431 throw std::bad_alloc();
432 }
433
438 {
439 ft_destroy_table(table_);
440 }
441
445 table(const table &tbl)
446 : property_owner_t(FT_ANY_ROW, FT_ANY_COLUMN, this), table_(NULL)
447 {
448 if (tbl.table_) {
449 std::unique_ptr<ft_table_t, decltype(&ft_destroy_table)>
450 table_copy(ft_copy_table(tbl.table_), &ft_destroy_table);
451 if (!table_copy)
452 throw std::runtime_error("Error during table copy");
453
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);
458 }
459 stream_.copyfmt(tbl.stream_);
460 table_ = table_copy.release();
461 }
462 }
463
468 : property_owner_t(FT_ANY_ROW, FT_ANY_COLUMN, this), table_(tbl.table_)
469 {
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());
474 }
475 stream_.copyfmt(tbl.stream_);
476 tbl.table_ = 0;
477 }
478
482 table &operator=(const table &tbl)
483 {
484 if (&tbl == this)
485 return *this;
486
487 if (tbl.table_) {
488 std::unique_ptr<ft_table_t, decltype(&ft_destroy_table)>
489 table_copy(ft_copy_table(tbl.table_), &ft_destroy_table);
490 if (!table_copy)
491 throw std::runtime_error("Error during table copy");
492
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);
497 }
498 stream_.copyfmt(tbl.stream_);
499 ft_destroy_table(table_);
500 table_ = table_copy.release();
501 }
502 return *this;
503 }
504
509 {
510 if (&tbl == this)
511 return *this;
512
513 if (tbl.table_) {
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());
519 }
520 stream_.copyfmt(tbl.stream_);
521 ft_destroy_table(table_);
522 table_ = tbl.table_;
523 tbl.table_ = NULL;
524 }
525 return *this;
526 }
527
535 std::string to_string() const
536 {
537 const char *str = c_str();
538 if (str == NULL)
539 throw std::runtime_error("Error during table to string conversion");
540 return str;
541 }
542
558 const char *c_str() const
559 {
560#ifdef FT_HAVE_UTF8
561 return (TT == table_type::character)
562 ? ft_to_string(table_)
563 : (const char *)ft_to_u8string(table_);
564#else
565 return ft_to_string(table_);
566#endif
567 }
568
580 template <typename T>
581 table &operator<<(const T &arg)
582 {
583 constexpr bool is_manip = fort::is_stream_manipulator<typename std::decay<T>::type>();
584 stream_ << arg;
585 if (stream_.tellp() >= 0 && !is_manip) {
586#ifdef FT_HAVE_UTF8
587 if (TT == table_type::character) {
588 ft_nwrite(table_, 1, stream_.str().c_str());
589 } else {
590 ft_u8nwrite(table_, 1, (const void *)stream_.str().c_str());
591 }
592#else
593 ft_nwrite(table_, 1, stream_.str().c_str());
594#endif
595
596 stream_.str(std::string());
597 }
598 return *this;
599 }
600
602 {
603 if (arg.value == header.value)
604 ft_set_cell_prop(table_, FT_CUR_ROW, FT_ANY_ROW, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
605 else if (arg.value == endr.value)
606 ft_ln(table_);
607 else if (arg.value == separator.value)
608 ft_add_separator(table_);
609 return *this;
610 }
611
623 bool write(const char *str)
624 {
625#ifdef FT_HAVE_UTF8
626 if (TT == table_type::character) {
627 return FT_IS_SUCCESS(ft_write(table_, str));
628 } else {
629 return FT_IS_SUCCESS(ft_u8write(table_, (const void *)str));
630 }
631#else
632 return FT_IS_SUCCESS(ft_write(table_, str));
633#endif
634 }
635
648 bool write_ln(const char *str)
649 {
650#ifdef FT_HAVE_UTF8
651 if (TT == table_type::character) {
652 return FT_IS_SUCCESS(ft_write_ln(table_, str));
653 } else {
654 return FT_IS_SUCCESS(ft_u8write_ln(table_, str));
655 }
656#else
657 return FT_IS_SUCCESS(ft_write_ln(table_, str));
658#endif
659 }
660
672 bool write(const std::string &str)
673 {
674 return write(str.c_str());
675 }
676
689 bool write_ln(const std::string &str)
690 {
691 return write_ln(str.c_str());
692 }
693
694#ifdef __cpp_variadic_templates
709 template <typename T, typename ...Ts>
710 bool write(const T &str, const Ts &...strings)
711 {
712 return write(str) && write(strings...);
713 }
714
730 template <typename T, typename ...Ts>
731 bool write_ln(const T &str, const Ts &...strings)
732 {
733 return write(str) && write_ln(strings...);
734 }
735#else /* __cpp_variadic_templates */
736
737 template <typename T_0, typename T_1>
738 bool write(const T_0 &arg_0, const T_1 &arg_1)
739 {
740 return write(arg_0) && write(arg_1);
741 }
742
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)
745 {
746 return write(arg_0) && write(arg_1, arg_2);
747 }
748
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)
751 {
752 return write(arg_0) && write(arg_1, arg_2, arg_3);
753 }
754
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)
757 {
758 return write(arg_0) && write(arg_1, arg_2, arg_3, arg_4);
759 }
760
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)
763 {
764 return write(arg_0) && write(arg_1, arg_2, arg_3, arg_4, arg_5);
765 }
766
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)
769 {
770 return write(arg_0) && write(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6);
771 }
772
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)
775 {
776 return write(arg_0) && write(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6, arg_7);
777 }
778
779
780 template <typename T_0, typename T_1>
781 bool write_ln(const T_0 &arg_0, const T_1 &arg_1)
782 {
783 return write(arg_0) && write_ln(arg_1);
784 }
785
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)
788 {
789 return write(arg_0) && write_ln(arg_1, arg_2);
790 }
791
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)
794 {
795 return write(arg_0) && write_ln(arg_1, arg_2, arg_3);
796 }
797
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)
800 {
801 return write(arg_0) && write_ln(arg_1, arg_2, arg_3, arg_4);
802 }
803
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)
806 {
807 return write(arg_0) && write_ln(arg_1, arg_2, arg_3, arg_4, arg_5);
808 }
809
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)
812 {
813 return write(arg_0) && write_ln(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6);
814 }
815
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)
818 {
819 return write(arg_0) && write_ln(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6, arg_7);
820 }
821
822#endif /* __cpp_variadic_templates */
823
835 template <typename InputIt>
836 bool range_write(InputIt first, InputIt last)
837 {
838 while (first != last) {
839 *this << *first;
840 ++first;
841 }
842 return true;
843 }
844
857 template <typename InputIt>
858 bool range_write_ln(InputIt first, InputIt last)
859 {
860 while (first != last) {
861 *this << *first;
862 ++first;
863 }
864 ft_ln(table_);
865 return true;
866 }
867
877 bool set_border_style(const struct ft_border_style *style)
878 {
879 return FT_IS_SUCCESS(ft_set_border_style(table_, style));
880 }
881
892 void set_cur_cell(size_t row_i, size_t col_i)
893 {
894 ft_set_cur_cell(table_, row_i, col_i);
895 }
896
897
907 bool set_left_margin(unsigned value)
908 {
909 return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_LEFT_MARGIN, value));
910 }
911
921 bool set_top_margin(unsigned value)
922 {
923 return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_TOP_MARGIN, value));
924 }
925
935 bool set_right_margin(unsigned value)
936 {
937 return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_RIGHT_MARGIN, value));
938 }
939
949 bool set_bottom_margin(unsigned value)
950 {
951 return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_BOTTOM_MARGIN, value));
952 }
953
964 {
965 return FT_IS_SUCCESS(ft_set_tbl_prop(table_,
966 FT_TPROP_ADDING_STRATEGY,
967 static_cast<int>(value)));
968 }
969private:
970 ft_table_t *table_;
971 mutable std::stringstream stream_;
972 friend class property_owner<table>;
973
974
975public:
976
977 /* Iterators */
978 /* todo: implement chains like table[0][0] = table [0][1] = "somethings" */
979
984 {
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_;
989 public:
990 table_cell(std::size_t row_idx, std::size_t coll_idx, table &tbl)
991 : property_owner_t(row_idx, coll_idx, &tbl) {}
992
993 table_cell &operator=(const char *str)
994 {
995 ft_set_cur_cell(ps_table_->table_, ps_row_idx_, ps_coll_idx_);
996 ps_table_->write(str);
997 return *this;
998 }
999
1000 table_cell &operator=(const std::string &str)
1001 {
1002 return operator=(str.c_str());
1003 }
1004
1014 bool set_cell_span(size_t hor_span)
1015 {
1016 if (set_default_properties_)
1017 return false;
1018
1019 return FT_IS_SUCCESS(ft_set_cell_span(ps_table_->table_, ps_row_idx_, ps_coll_idx_, hor_span));
1020 }
1021 };
1022
1027 {
1028 using property_owner_t::ps_row_idx_;
1029 using property_owner_t::ps_table_;
1030 public:
1031 table_row(std::size_t row_idx, table &tbl)
1032 : property_owner_t(row_idx, FT_ANY_COLUMN, &tbl) {}
1033
1034 class table_cell
1035 operator[](std::size_t coll_idx)
1036 {
1037 return table_cell(ps_row_idx_, coll_idx, *ps_table_);
1038 }
1039
1040 void erase()
1041 {
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");
1046 }
1047 }
1048 };
1049
1054 {
1055 using property_owner_t::ps_coll_idx_;
1056 using property_owner_t::ps_table_;
1057 public:
1058 table_column(std::size_t col_idx, table &tbl)
1059 : property_owner_t(FT_ANY_ROW, col_idx, &tbl) {}
1060
1061 void erase()
1062 {
1063 if (FT_IS_ERROR(ft_erase_range(ps_table_->table_,
1064 0, ps_coll_idx_,
1065 FT_MAX_ROW_INDEX, ps_coll_idx_))) {
1066 throw std::runtime_error("Failed to erase column");
1067 }
1068 }
1069 };
1070
1079 {
1080 using property_owner_t::ps_coll_idx_;
1081 using property_owner_t::ps_row_idx_;
1082 using property_owner_t::ps_table_;
1083 public:
1084 cell_range(size_t top_left_row, size_t top_left_col,
1085 size_t bottom_right_row, size_t bottom_right_col,
1086 table &tbl)
1087 : property_owner_t(top_left_row, top_left_col, &tbl),
1088 bottom_right_row_(bottom_right_row),
1089 bottom_right_col_(bottom_right_col)
1090 {}
1091
1092 void erase()
1093 {
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");
1098 }
1099 }
1100
1101 private:
1102 std::size_t bottom_right_row_;
1103 std::size_t bottom_right_col_;
1104 };
1105
1106
1108 {
1109 public:
1111 : property_owner_t(FT_ANY_ROW, FT_ANY_COLUMN, tbl, true) {}
1112 };
1113
1114 class table_row
1115 operator[](std::size_t row_idx)
1116 {
1117 return table_row(row_idx, *this);
1118 }
1119
1120
1131 class table_cell
1132 cell(std::size_t row_idx, std::size_t col_idx)
1133 {
1134 return (*this)[row_idx][col_idx];
1135 }
1136
1143 size_t
1144 cur_col() const noexcept
1145 {
1146 return ft_cur_col(table_);
1147 }
1148
1155 size_t
1156 cur_row() const noexcept
1157 {
1158 return ft_cur_row(table_);
1159 }
1160
1168 bool
1169 is_empty() const noexcept
1170 {
1171 return ft_is_empty(table_);
1172 }
1173
1180 std::size_t
1181 row_count() const noexcept
1182 {
1183 return ft_row_count(table_);
1184 }
1185
1192 std::size_t
1193 col_count() const noexcept
1194 {
1195 return ft_col_count(table_);
1196 }
1197
1204 class table_cell
1206 {
1207 return cell(cur_row(), cur_col());
1208 }
1209
1218 class table_row
1219 row(std::size_t row_idx)
1220 {
1221 return table_row(row_idx, *this);
1222 }
1223
1232 class table_column
1233 column(std::size_t col_idx)
1234 {
1235 return table_column(col_idx, *this);
1236 }
1237
1246 class cell_range
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)
1249 {
1250 return cell_range(top_left_row, top_left_col,
1251 bottom_right_row, bottom_right_col,
1252 *this);
1253 }
1254
1255 static class default_properties
1256 default_props()
1257 {
1258 return default_properties(NULL);
1259 }
1260};
1261
1270
1271#ifdef FT_HAVE_UTF8
1276#endif
1277
1288{
1289 return FT_IS_SUCCESS(ft_set_default_border_style(style));
1290}
1291
1292
1293} // namespace fort
1294
1295#endif // LIBFORT_HPP
Definition fort.hpp:197
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
Definition fort.hpp:1079
Definition fort.hpp:1108
Definition fort.hpp:984
bool set_cell_span(size_t hor_span)
Definition fort.hpp:1014
Definition fort.hpp:1054
Definition fort.hpp:1027
Definition fort.hpp:129
Definition fort.hpp:414
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)
Definition fort.h:733
Definition fort.c:2233