libfort
fort.hpp
Go to the documentation of this file.
1 /*
2 libfort
3 
4 MIT License
5 
6 Copyright (c) 2017 - 2020 Seleznev Anton
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice shall be included in all
16 copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 SOFTWARE.
25 */
26 
34 #ifndef LIBFORT_HPP
35 #define LIBFORT_HPP
36 
37 #include <iomanip>
38 #include <sstream>
39 #include <string>
40 #include <stdexcept>
41 #include <type_traits>
42 
43 #include "fort.h"
44 
45 namespace fort
46 {
47 
51 enum class text_align {
52  left = FT_ALIGNED_LEFT,
53  center = FT_ALIGNED_CENTER,
54  right = FT_ALIGNED_RIGHT
55 };
56 
60 enum class row_type {
61  common = FT_ROW_COMMON,
63 };
64 
71 enum class add_strategy {
72  replace = FT_STRATEGY_REPLACE,
73  insert = FT_STRATEGY_INSERT
74 };
75 
79 enum class color {
80  default_color = FT_COLOR_DEFAULT,
81  black = FT_COLOR_BLACK,
82  red = FT_COLOR_RED,
83  green = FT_COLOR_GREEN,
84  yellow = FT_COLOR_YELLOW,
85  blue = FT_COLOR_BLUE,
86  magenta = FT_COLOR_MAGENTA,
87  cyan = FT_COLOR_CYAN,
88  light_gray = FT_COLOR_LIGHT_GRAY,
89  dark_gray = FT_COLOR_DARK_GRAY,
90  light_red = FT_COLOR_LIGHT_RED,
91  light_green = FT_COLOR_LIGHT_GREEN,
92  light_yellow = FT_COLOR_LIGHT_YELLOW,
93  light_blue = FT_COLOR_LIGHT_BLUE,
94  light_magenta = FT_COLOR_LIGHT_MAGENTA,
95  light_cyan = FT_COLOR_LIGHT_CYAN,
96  light_whyte = FT_COLOR_LIGHT_WHYTE
97 };
98 
102 enum class text_style {
103  default_style = FT_TSTYLE_DEFAULT,
104  bold = FT_TSTYLE_BOLD,
105  dim = FT_TSTYLE_DIM,
106  italic = FT_TSTYLE_ITALIC,
107  underlined = FT_TSTYLE_UNDERLINED,
108  blink = FT_TSTYLE_BLINK,
109  inverted = FT_TSTYLE_INVERTED,
110  hidden = FT_TSTYLE_HIDDEN
111 };
112 
113 
114 enum class table_type {
115  character,
116 #ifdef FT_HAVE_UTF8
117  utf8
118 #endif /* FT_HAVE_UTF8 */
119 };
120 
128 {
129 public:
130  explicit table_manipulator(int i)
131  : value(i)
132  {
133  }
134  template <table_type TT>
135  friend class table;
136 private:
137  int value;
138 };
139 
143 const table_manipulator header(0);
144 
148 const table_manipulator endr(1);
149 
154 
155 // Utility functions for internal library usage.
156 namespace detail
157 {
158 template <typename T>
159 constexpr bool is_stream_manipulator_impl() noexcept
160 {
161  using Tdec = typename std::decay<T>::type;
162  // Manipulators for integral types
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
166  // Floating-point manipulators
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
169  // Misc
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;
174 }
175 }
176 
182 template <typename T>
183 constexpr bool is_stream_manipulator() noexcept
184 {
185  return detail::is_stream_manipulator_impl<T>();
186 }
187 
194 template <typename table>
196 {
197 public:
198 
199  property_owner(std::size_t row_idx, std::size_t coll_idx, table *tbl, bool def = false)
200  : ps_row_idx_(row_idx), ps_coll_idx_(coll_idx),
201  ps_table_(tbl), set_default_properties_(def) {}
202 
212  bool set_cell_min_width(unsigned value)
213  {
214  return set_property(FT_CPROP_MIN_WIDTH, value);
215  }
216 
227  {
228  return set_property(FT_CPROP_TEXT_ALIGN, static_cast<int>(value));
229  }
230 
240  bool set_cell_top_padding(unsigned value)
241  {
242  return set_property(FT_CPROP_TOP_PADDING, value);
243  }
244 
254  bool set_cell_bottom_padding(unsigned value)
255  {
256  return set_property(FT_CPROP_BOTTOM_PADDING, value);
257  }
258 
268  bool set_cell_left_padding(unsigned value)
269  {
270  return set_property(FT_CPROP_LEFT_PADDING, value);
271  }
272 
282  bool set_cell_right_padding(unsigned value)
283  {
284  return set_property(FT_CPROP_RIGHT_PADDING, value);
285  }
286 
297  {
298  return set_property(FT_CPROP_ROW_TYPE, static_cast<int>(value));
299  }
300 
310  bool set_cell_empty_str_height(unsigned value)
311  {
312  return set_property(FT_CPROP_EMPTY_STR_HEIGHT, value);
313  }
314 
325  {
326  return set_property(FT_CPROP_CONT_FG_COLOR, static_cast<int>(value));
327  }
328 
339  {
340  return set_property(FT_CPROP_CELL_BG_COLOR, static_cast<int>(value));
341  }
342 
353  {
354  return set_property(FT_CPROP_CONT_BG_COLOR, static_cast<int>(value));
355  }
356 
367  {
368  return set_property(FT_CPROP_CELL_TEXT_STYLE, static_cast<int>(value));
369  }
370 
381  {
382  return set_property(FT_CPROP_CONT_TEXT_STYLE, static_cast<int>(value));
383  }
384 
385 protected:
386  std::size_t ps_row_idx_;
387  std::size_t ps_coll_idx_;
388  table *ps_table_;
389  bool set_default_properties_;
390 
391  bool set_property(uint32_t property, int value)
392  {
393  int status;
394  if (set_default_properties_) {
395  status = ft_set_default_cell_prop(property, value);
396  } else {
397  status = ft_set_cell_prop(ps_table_->table_, ps_row_idx_, ps_coll_idx_, property, value);
398  }
399  return FT_IS_SUCCESS(status);
400  }
401 };
402 
403 
411 template <table_type TT = table_type::character>
412 class table: public property_owner<table<TT>>
413 {
417  using table_t = table<TT>;
419 
420 public:
421 
427  table_(ft_create_table())
428  {
429  if (table_ == NULL)
430  throw std::bad_alloc();
431  }
432 
437  {
438  ft_destroy_table(table_);
439  }
440 
444  table(const table &tbl)
445  : property_owner_t(FT_ANY_ROW, FT_ANY_COLUMN, this), table_(NULL)
446  {
447  if (tbl.table_) {
448  ft_table_t *table_copy = ft_copy_table(tbl.table_);
449  if (table_copy == NULL)
450  throw std::runtime_error("Error during table copy");
451 
452  stream_.str(std::string());
453  if (tbl.stream_.tellp() >= 0) {
454  stream_ << tbl.stream_.str();
455  }
456  table_ = table_copy;
457  }
458  }
459 
463  table(table &&tbl)
464  : property_owner_t(FT_ANY_ROW, FT_ANY_COLUMN, this), table_(tbl.table_)
465  {
466  if (tbl.stream_.tellp() >= 0) {
467  stream_ << tbl.stream_.str();
468  tbl.stream_.str(std::string());
469  }
470  tbl.table_ = 0;
471  }
472 
476  table &operator=(const table &tbl)
477  {
478  if (&tbl == this)
479  return *this;
480 
481  if (tbl.table_) {
482  ft_table_t *table_copy = ft_copy_table(tbl.table_);
483  if (table_copy == NULL)
484  throw std::runtime_error("Error during table copy");
485 
486  stream_.str(std::string());
487  if (tbl.stream_.tellp() >= 0) {
488  stream_ << tbl.stream_.str();
489  }
490  ft_destroy_table(table_);
491  table_ = table_copy;
492  }
493  return *this;
494  }
495 
500  {
501  if (&tbl == this)
502  return *this;
503 
504  if (tbl.table_) {
505  stream_.str(std::string());
506  if (tbl.stream_.tellp() >= 0) {
507  stream_ << tbl.stream_.str();
508  tbl.stream_.str(std::string());
509  }
510  ft_destroy_table(table_);
511  table_ = tbl.table_;
512  tbl.table_ = NULL;
513  }
514  return *this;
515  }
516 
524  std::string to_string() const
525  {
526  const char *str = c_str();
527  if (str == NULL)
528  throw std::runtime_error("Error during table to string conversion");
529  return str;
530  }
531 
547  const char *c_str() const
548  {
549 #ifdef FT_HAVE_UTF8
550  return (TT == table_type::character)
551  ? ft_to_string(table_)
552  : (const char *)ft_to_u8string(table_);
553 #else
554  return ft_to_string(table_);
555 #endif
556  }
557 
569  template <typename T>
570  table &operator<<(const T &arg)
571  {
572  constexpr bool is_manip = fort::is_stream_manipulator<typename std::decay<T>::type>();
573  stream_ << arg;
574  if (stream_.tellp() >= 0 && !is_manip) {
575 #ifdef FT_HAVE_UTF8
576  if (TT == table_type::character) {
577  ft_nwrite(table_, 1, stream_.str().c_str());
578  } else {
579  ft_u8nwrite(table_, 1, (const void *)stream_.str().c_str());
580  }
581 #else
582  ft_nwrite(table_, 1, stream_.str().c_str());
583 #endif
584 
585  stream_.str(std::string());
586  }
587  return *this;
588  }
589 
591  {
592  if (arg.value == header.value)
594  else if (arg.value == endr.value)
595  ft_ln(table_);
596  else if (arg.value == separator.value)
597  ft_add_separator(table_);
598  return *this;
599  }
600 
612  bool write(const char *str)
613  {
614 #ifdef FT_HAVE_UTF8
615  if (TT == table_type::character) {
616  return FT_IS_SUCCESS(ft_write(table_, str));
617  } else {
618  return FT_IS_SUCCESS(ft_u8write(table_, (const void *)str));
619  }
620 #else
621  return FT_IS_SUCCESS(ft_write(table_, str));
622 #endif
623  }
624 
637  bool write_ln(const char *str)
638  {
639 #ifdef FT_HAVE_UTF8
640  if (TT == table_type::character) {
641  return FT_IS_SUCCESS(ft_write_ln(table_, str));
642  } else {
643  return FT_IS_SUCCESS(ft_u8write_ln(table_, str));
644  }
645 #else
646  return FT_IS_SUCCESS(ft_write_ln(table_, str));
647 #endif
648  }
649 
661  bool write(const std::string &str)
662  {
663  return write(str.c_str());
664  }
665 
678  bool write_ln(const std::string &str)
679  {
680  return write_ln(str.c_str());
681  }
682 
683 #ifdef __cpp_variadic_templates
684 
698  template <typename T, typename ...Ts>
699  bool write(const T &str, const Ts &...strings)
700  {
701  return write(str) && write(strings...);
702  }
703 
719  template <typename T, typename ...Ts>
720  bool write_ln(const T &str, const Ts &...strings)
721  {
722  return write(str) && write_ln(strings...);
723  }
724 #else /* __cpp_variadic_templates */
725 
726  template <typename T_0, typename T_1>
727  bool write(const T_0 &arg_0, const T_1 &arg_1)
728  {
729  return write(arg_0) && write(arg_1);
730  }
731 
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)
734  {
735  return write(arg_0) && write(arg_1, arg_2);
736  }
737 
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)
740  {
741  return write(arg_0) && write(arg_1, arg_2, arg_3);
742  }
743 
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)
746  {
747  return write(arg_0) && write(arg_1, arg_2, arg_3, arg_4);
748  }
749 
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)
752  {
753  return write(arg_0) && write(arg_1, arg_2, arg_3, arg_4, arg_5);
754  }
755 
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)
758  {
759  return write(arg_0) && write(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6);
760  }
761 
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)
764  {
765  return write(arg_0) && write(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6, arg_7);
766  }
767 
768 
769  template <typename T_0, typename T_1>
770  bool write_ln(const T_0 &arg_0, const T_1 &arg_1)
771  {
772  return write(arg_0) && write_ln(arg_1);
773  }
774 
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)
777  {
778  return write(arg_0) && write_ln(arg_1, arg_2);
779  }
780 
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)
783  {
784  return write(arg_0) && write_ln(arg_1, arg_2, arg_3);
785  }
786 
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)
789  {
790  return write(arg_0) && write_ln(arg_1, arg_2, arg_3, arg_4);
791  }
792 
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)
795  {
796  return write(arg_0) && write_ln(arg_1, arg_2, arg_3, arg_4, arg_5);
797  }
798 
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)
801  {
802  return write(arg_0) && write_ln(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6);
803  }
804 
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)
807  {
808  return write(arg_0) && write_ln(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6, arg_7);
809  }
810 
811 #endif /* __cpp_variadic_templates */
812 
824  template <typename InputIt>
825  bool range_write(InputIt first, InputIt last)
826  {
827  while (first != last) {
828  *this << *first;
829  ++first;
830  }
831  return true;
832  }
833 
846  template <typename InputIt>
847  bool range_write_ln(InputIt first, InputIt last)
848  {
849  while (first != last) {
850  *this << *first;
851  ++first;
852  }
853  ft_ln(table_);
854  return true;
855  }
856 
866  bool set_border_style(const struct ft_border_style *style)
867  {
868  return FT_IS_SUCCESS(ft_set_border_style(table_, style));
869  }
870 
881  void set_cur_cell(size_t row_i, size_t col_i)
882  {
883  ft_set_cur_cell(table_, row_i, col_i);
884  }
885 
886 
896  bool set_left_margin(unsigned value)
897  {
898  return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_LEFT_MARGIN, value));
899  }
900 
910  bool set_top_margin(unsigned value)
911  {
912  return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_TOP_MARGIN, value));
913  }
914 
924  bool set_right_margin(unsigned value)
925  {
926  return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_RIGHT_MARGIN, value));
927  }
928 
938  bool set_bottom_margin(unsigned value)
939  {
940  return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_BOTTOM_MARGIN, value));
941  }
942 
953  {
954  return FT_IS_SUCCESS(ft_set_tbl_prop(table_,
955  FT_TPROP_ADDING_STRATEGY,
956  static_cast<int>(value)));
957  }
958 private:
959  ft_table_t *table_;
960  mutable std::stringstream stream_;
961  friend class property_owner<table>;
962 
963 
964 public:
965 
966  /* Iterators */
967  /* todo: implement chains like table[0][0] = table [0][1] = "somethings" */
968 
973  {
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_;
978  public:
979  table_cell(std::size_t row_idx, std::size_t coll_idx, table &tbl)
980  : property_owner_t(row_idx, coll_idx, &tbl) {}
981 
982  table_cell &operator=(const char *str)
983  {
984  ft_set_cur_cell(ps_table_->table_, ps_row_idx_, ps_coll_idx_);
985  ps_table_->write(str);
986  return *this;
987  }
988 
989  table_cell &operator=(const std::string &str)
990  {
991  return operator=(str.c_str());
992  }
993 
1003  bool set_cell_span(size_t hor_span)
1004  {
1005  if (set_default_properties_)
1006  return false;
1007 
1008  return FT_IS_SUCCESS(ft_set_cell_span(ps_table_->table_, ps_row_idx_, ps_coll_idx_, hor_span));
1009  }
1010  };
1011 
1016  {
1017  using property_owner_t::ps_row_idx_;
1018  using property_owner_t::ps_table_;
1019  public:
1020  table_row(std::size_t row_idx, table &tbl)
1021  : property_owner_t(row_idx, FT_ANY_COLUMN, &tbl) {}
1022 
1023  class table_cell
1024  operator[](std::size_t coll_idx)
1025  {
1026  return table_cell(ps_row_idx_, coll_idx, *ps_table_);
1027  }
1028 
1029  void erase()
1030  {
1031  if (FT_IS_ERROR(ft_erase_range(ps_table_->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");
1035  }
1036  }
1037  };
1038 
1043  {
1044  using property_owner_t::ps_coll_idx_;
1045  using property_owner_t::ps_table_;
1046  public:
1047  table_column(std::size_t col_idx, table &tbl)
1048  : property_owner_t(FT_ANY_ROW, col_idx, &tbl) {}
1049 
1050  void erase()
1051  {
1052  if (FT_IS_ERROR(ft_erase_range(ps_table_->table_,
1053  0, ps_coll_idx_,
1054  FT_MAX_ROW_INDEX, ps_coll_idx_))) {
1055  throw std::runtime_error("Failed to erase column");
1056  }
1057  }
1058  };
1059 
1068  {
1069  using property_owner_t::ps_coll_idx_;
1070  using property_owner_t::ps_row_idx_;
1071  using property_owner_t::ps_table_;
1072  public:
1073  cell_range(size_t top_left_row, size_t top_left_col,
1074  size_t bottom_right_row, size_t bottom_right_col,
1075  table &tbl)
1076  : property_owner_t(top_left_row, top_left_col, &tbl),
1077  bottom_right_row_(bottom_right_row),
1078  bottom_right_col_(bottom_right_col)
1079  {}
1080 
1081  void erase()
1082  {
1083  if (FT_IS_ERROR(ft_erase_range(ps_table_->table_,
1084  ps_row_idx_, ps_coll_idx_,
1085  bottom_right_row_, bottom_right_col_))) {
1086  throw std::runtime_error("Failed to erase column");
1087  }
1088  }
1089 
1090  private:
1091  std::size_t bottom_right_row_;
1092  std::size_t bottom_right_col_;
1093  };
1094 
1095 
1097  {
1098  public:
1099  default_properties(table *tbl)
1100  : property_owner_t(FT_ANY_ROW, FT_ANY_COLUMN, tbl, true) {}
1101  };
1102 
1103  class table_row
1104  operator[](std::size_t row_idx)
1105  {
1106  return table_row(row_idx, *this);
1107  }
1108 
1109 
1120  class table_cell
1121  cell(std::size_t row_idx, std::size_t col_idx)
1122  {
1123  return (*this)[row_idx][col_idx];
1124  }
1125 
1132  size_t
1133  cur_col() const noexcept
1134  {
1135  return ft_cur_col(table_);
1136  }
1137 
1144  size_t
1145  cur_row() const noexcept
1146  {
1147  return ft_cur_row(table_);
1148  }
1149 
1157  bool
1158  is_empty() const noexcept
1159  {
1160  return ft_is_empty(table_);
1161  }
1162 
1169  std::size_t
1170  row_count() const noexcept
1171  {
1172  return ft_row_count(table_);
1173  }
1174 
1181  class table_cell
1182  cur_cell()
1183  {
1184  return cell(cur_row(), cur_col());
1185  }
1186 
1195  class table_row
1196  row(std::size_t row_idx)
1197  {
1198  return table_row(row_idx, *this);
1199  }
1200 
1209  class table_column
1210  column(std::size_t col_idx)
1211  {
1212  return table_column(col_idx, *this);
1213  }
1214 
1223  class cell_range
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)
1226  {
1227  return cell_range(top_left_row, top_left_col,
1228  bottom_right_row, bottom_right_col,
1229  *this);
1230  }
1231 
1232  static class default_properties
1233  default_props()
1234  {
1235  return default_properties(NULL);
1236  }
1237 };
1238 
1247 
1248 #ifdef FT_HAVE_UTF8
1249 
1253 #endif
1254 
1264 inline bool set_default_border_style(struct ft_border_style *style)
1265 {
1266  return FT_IS_SUCCESS(ft_set_default_border_style(style));
1267 }
1268 
1269 
1270 } // namespace fort
1271 
1272 #endif // LIBFORT_HPP
bool range_write(InputIt first, InputIt last)
Definition: fort.hpp:825
Definition: fort.h:801
const table_manipulator endr(1)
Definition: fort.c:2231
Definition: fort.h:847
table(table &&tbl)
Definition: fort.hpp:463
Definition: fort.h:800
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
Definition: fort.h:839
Definition: fort.h:822
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
Definition: fort.h:829
size_t cur_row() const noexcept
Definition: fort.hpp:1145
size_t ft_cur_row(const ft_table_t *table)
Definition: fort.c:2801
Definition: fort.h:811
Definition: fort.h:809
table & operator=(const table &tbl)
Definition: fort.hpp:476
Definition: fort.h:815
bool set_cell_empty_str_height(unsigned value)
Definition: fort.hpp:310
Definition: fort.h:901
#define FT_CPROP_MIN_WIDTH
Definition: fort.h:779
Definition: fort.h:808
#define FT_CPROP_TOP_PADDING
Definition: fort.h:781
Main header file describing libfort API.
Definition: fort.h:803
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
Definition: fort.h:810
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
Definition: fort.h:828
#define FT_CPROP_ROW_TYPE
Definition: fort.h:786
Definition: fort.h:827
Definition: fort.h:823
Definition: fort.hpp:45
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
Definition: fort.h:826
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.h:700
Definition: fort.hpp:1067
int ft_add_separator(ft_table_t *table)
Definition: fort.c:3418
Definition: fort.h:825
bool set_top_margin(unsigned value)
Definition: fort.hpp:910
Definition: fort.h:812
Definition: fort.h:902
bool set_cell_row_type(fort::row_type value)
Definition: fort.hpp:296
std::string to_string() const
Definition: fort.hpp:524
Definition: fort.h:804
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
Definition: fort.h:813
Definition: fort.h:807
#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
Definition: fort.h:824
bool set_cell_right_padding(unsigned value)
Definition: fort.hpp:282
Definition: fort.hpp:195
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
Definition: fort.h:837
Definition: fort.h:799
Definition: fort.h:806
#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
Definition: fort.h:814
#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
Definition: fort.h:802
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
Definition: fort.hpp:127
#define FT_ANY_ROW
Definition: fort.h:767
Definition: fort.hpp:972
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
Definition: fort.h:805
Definition: fort.h:838
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
Definition: fort.h:846
Definition: fort.hpp:412
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