[A] Added more cpp tests.
This commit is contained in:
706
lib/fort.hpp
706
lib/fort.hpp
@@ -37,125 +37,350 @@ SOFTWARE.
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
||||
#include "fort.h"
|
||||
|
||||
namespace fort
|
||||
{
|
||||
|
||||
enum class CellProperty {
|
||||
MinWidth,
|
||||
TextAlign,
|
||||
TopPadding,
|
||||
BottomPadding,
|
||||
LeftPadding,
|
||||
RightPading,
|
||||
EmptyStrHeight,
|
||||
RowType
|
||||
|
||||
enum class text_align {
|
||||
left = FT_ALIGNED_LEFT,
|
||||
center = FT_ALIGNED_CENTER,
|
||||
right = FT_ALIGNED_RIGHT
|
||||
};
|
||||
|
||||
enum class TableProperty {
|
||||
LeftMargin,
|
||||
TopMargin,
|
||||
RightMargin,
|
||||
BottomMargin,
|
||||
enum class row_type {
|
||||
common = FT_ROW_COMMON,
|
||||
header = FT_ROW_HEADER
|
||||
};
|
||||
|
||||
enum class TextAlign {
|
||||
Left = 0,
|
||||
Center,
|
||||
Right
|
||||
enum class color {
|
||||
default_color = FT_COLOR_DEFAULT,
|
||||
black = FT_COLOR_BLACK,
|
||||
red = FT_COLOR_RED,
|
||||
green = FT_COLOR_GREEN,
|
||||
yellow = FT_COLOR_YELLOW,
|
||||
blue = FT_COLOR_BLUE,
|
||||
magenta = FT_COLOR_MAGENTA,
|
||||
cyan = FT_COLOR_CYAN,
|
||||
light_gray = FT_COLOR_LIGHT_GRAY,
|
||||
dark_gray = FT_COLOR_DARK_GRAY,
|
||||
light_red = FT_COLOR_LIGHT_RED,
|
||||
light_green = FT_COLOR_LIGHT_GREEN,
|
||||
light_yellow = FT_COLOR_LIGHT_YELLOW,
|
||||
light_blue = FT_COLOR_LIGHT_BLUE,
|
||||
light_magenta = FT_COLOR_LIGHT_MAGENTA,
|
||||
light_cyan = FT_COLOR_LIGHT_CYAN,
|
||||
light_whyte = FT_COLOR_LIGHT_WHYTE
|
||||
};
|
||||
|
||||
enum class RowType {
|
||||
Common = 0,
|
||||
Header
|
||||
enum class text_style {
|
||||
default_style = FT_TSTYLE_DEFAULT,
|
||||
bold = FT_TSTYLE_BOLD,
|
||||
dim = FT_TSTYLE_DIM,
|
||||
italic = FT_TSTYLE_ITALIC,
|
||||
underlined = FT_TSTYLE_UNDERLINED,
|
||||
blink = FT_TSTYLE_BLINK,
|
||||
inverted = FT_TSTYLE_INVERTED,
|
||||
hidden = FT_TSTYLE_HIDDEN
|
||||
};
|
||||
|
||||
class TableManipulator {
|
||||
class table_manipulator {
|
||||
public:
|
||||
explicit TableManipulator(int i)
|
||||
explicit table_manipulator(int i)
|
||||
:value(i)
|
||||
{
|
||||
}
|
||||
friend class Table;
|
||||
friend class table;
|
||||
private:
|
||||
int value;
|
||||
};
|
||||
|
||||
const TableManipulator header(0);
|
||||
const TableManipulator endr(1);
|
||||
const TableManipulator separator(2);
|
||||
const table_manipulator header(0);
|
||||
const table_manipulator endr(1);
|
||||
const table_manipulator separator(2);
|
||||
|
||||
|
||||
template <typename table>
|
||||
class property_setter {
|
||||
public:
|
||||
|
||||
property_setter(std::size_t row_idx, std::size_t coll_idx, table &tbl)
|
||||
:ps_row_idx_(row_idx), ps_coll_idx_(coll_idx), ps_table_(tbl) {}
|
||||
|
||||
/**
|
||||
* Set min width for the specified cell of the table.
|
||||
*
|
||||
* @param value
|
||||
* Value of the min width.
|
||||
* @return
|
||||
* - true: Success; cell property was changed.
|
||||
* - false: In case of error
|
||||
*/
|
||||
bool set_cell_min_width(unsigned value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(ps_table_.table_, ps_row_idx_, ps_coll_idx_, FT_CPROP_MIN_WIDTH, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set text alignment for the specified cell of the table.
|
||||
*
|
||||
* @param value
|
||||
* Value of the text alignment.
|
||||
* @return
|
||||
* - true: Success; cell property was changed.
|
||||
* - false: In case of error
|
||||
*/
|
||||
bool set_cell_text_align(enum fort::text_align value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(ps_table_.table_, ps_row_idx_, ps_coll_idx_, FT_CPROP_TEXT_ALIGN, static_cast<int>(value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set top padding for the specified cell of the table.
|
||||
*
|
||||
* @param value
|
||||
* Value of the top padding.
|
||||
* @return
|
||||
* - true: Success; cell property was changed.
|
||||
* - false: In case of error.
|
||||
*/
|
||||
bool set_cell_top_padding(unsigned value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(ps_table_.table_, ps_row_idx_, ps_coll_idx_, FT_CPROP_TOP_PADDING, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set bottom padding for the specified cell of the table.
|
||||
*
|
||||
* @param value
|
||||
* Value of the bottom padding.
|
||||
* @return
|
||||
* - true: Success; cell property was changed.
|
||||
* - false: In case of error.
|
||||
*/
|
||||
bool set_cell_bottom_padding(unsigned value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(ps_table_.table_, ps_row_idx_, ps_coll_idx_, FT_CPROP_BOTTOM_PADDING, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set left padding for the specified cell of the table.
|
||||
*
|
||||
* @param value
|
||||
* Value of the left padding.
|
||||
* @return
|
||||
* - true: Success; cell property was changed.
|
||||
* - false: In case of error.
|
||||
*/
|
||||
bool set_cell_left_padding(unsigned value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(ps_table_.table_, ps_row_idx_, ps_coll_idx_, FT_CPROP_LEFT_PADDING, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set right padding for the specified cell of the table.
|
||||
*
|
||||
* @param value
|
||||
* Value of the left padding.
|
||||
* @return
|
||||
* - true: Success; cell property was changed.
|
||||
* - false: In case of error.
|
||||
*/
|
||||
bool set_cell_right_padding(unsigned value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(ps_table_.table_, ps_row_idx_, ps_coll_idx_, FT_CPROP_RIGHT_PADDING, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set row type for the specified cell of the table.
|
||||
*
|
||||
* @param value
|
||||
* Value of the row type.
|
||||
* @return
|
||||
* - true: Success; cell property was changed.
|
||||
* - false: In case of error.
|
||||
*/
|
||||
bool set_cell_row_type(enum fort::row_type value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(ps_table_.table_, ps_row_idx_, ps_coll_idx_, FT_CPROP_ROW_TYPE, static_cast<int>(value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set empty string height for the specified cell of the table.
|
||||
*
|
||||
* @param value
|
||||
* Value of the empty string height.
|
||||
* @return
|
||||
* - true: Success; cell property was changed.
|
||||
* - false: In case of error.
|
||||
*/
|
||||
bool set_cell_empty_str_height(unsigned value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(ps_table_.table_, ps_row_idx_, ps_coll_idx_, FT_CPROP_EMPTY_STR_HEIGHT, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set content foreground color for the specified cell of the table.
|
||||
*
|
||||
* @param value
|
||||
* Color.
|
||||
* @return
|
||||
* - true: Success; cell property was changed.
|
||||
* - false: In case of error.
|
||||
*/
|
||||
bool set_cell_content_fg_color(enum fort::color value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(ps_table_.table_, ps_row_idx_, ps_coll_idx_, FT_CPROP_CONT_FG_COLOR, static_cast<int>(value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cell background color for the specified cell of the table.
|
||||
*
|
||||
* @param value
|
||||
* Color.
|
||||
* @return
|
||||
* - true: Success; cell property was changed.
|
||||
* - false: In case of error.
|
||||
*/
|
||||
bool set_cell_cell_bg_color(enum fort::color value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(ps_table_.table_, ps_row_idx_, ps_coll_idx_, FT_CPROP_CELL_BG_COLOR, static_cast<int>(value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set content background color for the specified cell of the table.
|
||||
*
|
||||
* @param value
|
||||
* Color.
|
||||
* @return
|
||||
* - true: Success; cell property was changed.
|
||||
* - false: In case of error.
|
||||
*/
|
||||
bool set_cell_content_bg_color(enum fort::color value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(ps_table_.table_, ps_row_idx_, ps_coll_idx_, FT_CPROP_CONT_BG_COLOR, static_cast<int>(value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cell text style for the specified cell of the table.
|
||||
*
|
||||
* @param value
|
||||
* Text style.
|
||||
* @return
|
||||
* - true: Success; cell property was changed.
|
||||
* - false: In case of error.
|
||||
*/
|
||||
bool set_cell_cell_text_style(enum fort::text_style value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(ps_table_.table_, ps_row_idx_, ps_coll_idx_, FT_CPROP_CELL_TEXT_STYLE, static_cast<int>(value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set content text style for the specified cell of the table.
|
||||
*
|
||||
* @param value
|
||||
* Text style.
|
||||
* @return
|
||||
* - true: Success; cell property was changed.
|
||||
* - false: In case of error.
|
||||
*/
|
||||
bool set_cell_content_text_style(enum fort::text_style value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(ps_table_.table_, ps_row_idx_, ps_coll_idx_, FT_CPROP_CONT_TEXT_STYLE, static_cast<int>(value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set column span for the specified cell of the table.
|
||||
*
|
||||
* @param hor_span
|
||||
* Column span.
|
||||
* @return
|
||||
* - true: Success; cell span was changed.
|
||||
* - false: In case of error.
|
||||
*/
|
||||
bool set_cell_span(size_t hor_span)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_span(ps_table_.table_, ps_row_idx_, ps_coll_idx_, hor_span));
|
||||
}
|
||||
protected:
|
||||
std::size_t ps_row_idx_;
|
||||
std::size_t ps_coll_idx_;
|
||||
table &ps_table_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Table - formatted table.
|
||||
*
|
||||
* Table class is a C++ wrapper around struct ft_table.
|
||||
*/
|
||||
class Table {
|
||||
class table: public property_setter<table> {
|
||||
public:
|
||||
Table()
|
||||
:table(ft_create_table())
|
||||
table()
|
||||
:property_setter(FT_ANY_ROW, FT_ANY_COLUMN, *this), table_(ft_create_table())
|
||||
{
|
||||
if (table == NULL)
|
||||
|
||||
if (table_ == NULL)
|
||||
throw std::runtime_error("Runtime error");
|
||||
}
|
||||
|
||||
~Table()
|
||||
~table()
|
||||
{
|
||||
ft_destroy_table(table);
|
||||
ft_destroy_table(table_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy contstructor.
|
||||
*/
|
||||
Table(const Table& tbl)
|
||||
:table(NULL)
|
||||
table(const table& tbl)
|
||||
:property_setter(FT_ANY_ROW, FT_ANY_COLUMN, *this), table_(NULL)
|
||||
{
|
||||
if (tbl.table) {
|
||||
ft_table_t *table_copy = ft_copy_table(tbl.table);
|
||||
if (tbl.table_) {
|
||||
ft_table_t *table_copy = ft_copy_table(tbl.table_);
|
||||
if (table_copy == NULL)
|
||||
throw std::runtime_error("Runtime error");
|
||||
|
||||
stream.str(std::string());
|
||||
if (tbl.stream.tellp() >= 0) {
|
||||
stream << tbl.stream.str();
|
||||
stream_.str(std::string());
|
||||
if (tbl.stream_.tellp() >= 0) {
|
||||
stream_ << tbl.stream_.str();
|
||||
}
|
||||
table = table_copy;
|
||||
table_ = table_copy;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move contstructor.
|
||||
*/
|
||||
Table(Table&& tbl)
|
||||
:table(tbl.table)
|
||||
table(table&& tbl)
|
||||
:property_setter(FT_ANY_ROW, FT_ANY_COLUMN, *this), table_(tbl.table_)
|
||||
{
|
||||
if (tbl.stream.tellp() >= 0) {
|
||||
stream << tbl.stream.str();
|
||||
tbl.stream.str(std::string());
|
||||
if (tbl.stream_.tellp() >= 0) {
|
||||
stream_ << tbl.stream_.str();
|
||||
tbl.stream_.str(std::string());
|
||||
}
|
||||
tbl.table = 0;
|
||||
tbl.table_ = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
Table& operator=(const Table& tbl)
|
||||
table& operator=(const table& tbl)
|
||||
{
|
||||
if (&tbl == this)
|
||||
return *this;
|
||||
|
||||
if (tbl.table) {
|
||||
ft_table_t *table_copy = ft_copy_table(tbl.table);
|
||||
if (tbl.table_) {
|
||||
ft_table_t *table_copy = ft_copy_table(tbl.table_);
|
||||
if (table_copy == NULL)
|
||||
throw std::runtime_error("Runtime error");
|
||||
|
||||
stream.str(std::string());
|
||||
if (tbl.stream.tellp() >= 0) {
|
||||
stream << tbl.stream.str();
|
||||
stream_.str(std::string());
|
||||
if (tbl.stream_.tellp() >= 0) {
|
||||
stream_ << tbl.stream_.str();
|
||||
}
|
||||
ft_destroy_table(table);
|
||||
table = table_copy;
|
||||
ft_destroy_table(table_);
|
||||
table_ = table_copy;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -163,20 +388,20 @@ public:
|
||||
/**
|
||||
* Move assignment operator.
|
||||
*/
|
||||
Table& operator=(Table&& tbl)
|
||||
table& operator=(table&& tbl)
|
||||
{
|
||||
if (&tbl == this)
|
||||
return *this;
|
||||
|
||||
if (tbl.table) {
|
||||
stream.str(std::string());
|
||||
if (tbl.stream.tellp() >= 0) {
|
||||
stream << tbl.stream.str();
|
||||
tbl.stream.str(std::string());
|
||||
if (tbl.table_) {
|
||||
stream_.str(std::string());
|
||||
if (tbl.stream_.tellp() >= 0) {
|
||||
stream_ << tbl.stream_.str();
|
||||
tbl.stream_.str(std::string());
|
||||
}
|
||||
ft_destroy_table(table);
|
||||
table = tbl.table;
|
||||
tbl.table = NULL;
|
||||
ft_destroy_table(table_);
|
||||
table_ = tbl.table_;
|
||||
tbl.table_ = NULL;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -190,7 +415,7 @@ public:
|
||||
*/
|
||||
std::string to_string() const
|
||||
{
|
||||
const char *str = ft_to_string(table);
|
||||
const char *str = ft_to_string(table_);
|
||||
if (str == NULL)
|
||||
throw std::runtime_error("Runtime error");
|
||||
return str;
|
||||
@@ -213,7 +438,7 @@ public:
|
||||
*/
|
||||
const char *c_str() const
|
||||
{
|
||||
return ft_to_string(table);
|
||||
return ft_to_string(table_);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,35 +453,35 @@ public:
|
||||
* - Reference to the current table.
|
||||
*/
|
||||
template <typename T>
|
||||
Table &operator<<(const T &arg)
|
||||
table &operator<<(const T &arg)
|
||||
{
|
||||
stream << arg;
|
||||
if (stream.tellp() >= 0) {
|
||||
ft_nwrite(table, 1, stream.str().c_str());
|
||||
stream.str(std::string());
|
||||
stream_ << arg;
|
||||
if (stream_.tellp() >= 0) {
|
||||
ft_nwrite(table_, 1, stream_.str().c_str());
|
||||
stream_.str(std::string());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Table &operator<<(const TableManipulator &arg)
|
||||
table &operator<<(const table_manipulator &arg)
|
||||
{
|
||||
if (arg.value == header.value)
|
||||
ft_set_cell_prop(table, FT_CUR_ROW, FT_ANY_ROW, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||
ft_set_cell_prop(table_, FT_CUR_ROW, FT_ANY_ROW, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||
else if (arg.value == endr.value)
|
||||
ft_ln(table);
|
||||
ft_ln(table_);
|
||||
else if (arg.value == separator.value)
|
||||
ft_add_separator(table);
|
||||
ft_add_separator(table_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool write(const char *str)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_write(table, str));
|
||||
return FT_IS_SUCCESS(ft_write(table_, str));
|
||||
}
|
||||
|
||||
bool write_ln(const char *str)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_write_ln(table, str));
|
||||
return FT_IS_SUCCESS(ft_write_ln(table_, str));
|
||||
}
|
||||
|
||||
bool write(const std::string &str)
|
||||
@@ -388,166 +613,10 @@ public:
|
||||
*this << *first;
|
||||
++first;
|
||||
}
|
||||
ft_ln(table);
|
||||
ft_ln(table_);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set min width for the specified cell of the table.
|
||||
*
|
||||
* @param row
|
||||
* Cell row.
|
||||
* @param col
|
||||
* Cell column.
|
||||
* @param value
|
||||
* Value of the min width.
|
||||
* @return
|
||||
* - 0: Success; cell property was changed.
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
bool set_cell_min_width(size_t row, size_t col, unsigned value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, FT_CPROP_MIN_WIDTH, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set text alignment for the specified cell of the table.
|
||||
*
|
||||
* @param row
|
||||
* Cell row.
|
||||
* @param col
|
||||
* Cell column.
|
||||
* @param value
|
||||
* Value of the text alignment.
|
||||
* @return
|
||||
* - 0: Success; cell property was changed.
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
bool set_cell_text_align(size_t row, size_t col, enum TextAlign value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, FT_CPROP_TEXT_ALIGN, static_cast<int>(value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set top padding for the specified cell of the table.
|
||||
*
|
||||
* @param row
|
||||
* Cell row.
|
||||
* @param col
|
||||
* Cell column.
|
||||
* @param value
|
||||
* Value of the top padding.
|
||||
* @return
|
||||
* - 0: Success; cell property was changed.
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
bool set_cell_top_padding(size_t row, size_t col, unsigned value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, FT_CPROP_TOP_PADDING, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set bottom padding for the specified cell of the table.
|
||||
*
|
||||
* @param row
|
||||
* Cell row.
|
||||
* @param col
|
||||
* Cell column.
|
||||
* @param value
|
||||
* Value of the bottom padding.
|
||||
* @return
|
||||
* - 0: Success; cell property was changed.
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
bool set_cell_bottom_padding(size_t row, size_t col, unsigned value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, FT_CPROP_BOTTOM_PADDING, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set left padding for the specified cell of the table.
|
||||
*
|
||||
* @param row
|
||||
* Cell row.
|
||||
* @param col
|
||||
* Cell column.
|
||||
* @param value
|
||||
* Value of the left padding.
|
||||
* @return
|
||||
* - 0: Success; cell property was changed.
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
bool set_cell_left_padding(size_t row, size_t col, unsigned value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, FT_CPROP_LEFT_PADDING, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set right padding for the specified cell of the table.
|
||||
*
|
||||
* @param row
|
||||
* Cell row.
|
||||
* @param col
|
||||
* Cell column.
|
||||
* @param value
|
||||
* Value of the left padding.
|
||||
* @return
|
||||
* - 0: Success; cell property was changed.
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
bool set_cell_right_padding(size_t row, size_t col, unsigned value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, FT_CPROP_RIGHT_PADDING, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set empty string height for the specified cell of the table.
|
||||
*
|
||||
* @param row
|
||||
* Cell row.
|
||||
* @param col
|
||||
* Cell column.
|
||||
* @param value
|
||||
* Value of the empty string height.
|
||||
* @return
|
||||
* - 0: Success; cell property was changed.
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
bool set_cell_empty_str_height(size_t row, size_t col, unsigned value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, FT_CPROP_EMPTY_STR_HEIGHT, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set row type for the specified cell of the table.
|
||||
*
|
||||
* @param row
|
||||
* Cell row.
|
||||
* @param col
|
||||
* Cell column.
|
||||
* @param value
|
||||
* Value of the row type.
|
||||
* @return
|
||||
* - 0: Success; cell property was changed.
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
bool set_cell_row_type(size_t row, size_t col, enum RowType value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, FT_CPROP_ROW_TYPE, static_cast<int>(value)));
|
||||
}
|
||||
|
||||
template <CellProperty property>
|
||||
bool set_property(size_t row, size_t col, unsigned value);
|
||||
|
||||
template <CellProperty property>
|
||||
bool set_property(size_t row, size_t col, enum TextAlign align);
|
||||
|
||||
template <CellProperty property>
|
||||
bool set_property(size_t row, size_t col, enum RowType rowType);
|
||||
|
||||
template <TableProperty property>
|
||||
bool set_property(unsigned value);
|
||||
|
||||
/**
|
||||
* Set border style for the table.
|
||||
*
|
||||
@@ -559,7 +628,7 @@ public:
|
||||
*/
|
||||
bool set_border_style(struct ft_border_style *style)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_border_style(table, style));
|
||||
return FT_IS_SUCCESS(ft_set_border_style(table_, style));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -567,58 +636,115 @@ public:
|
||||
*
|
||||
* Current cell - cell that will be edited with all modifiing functions.
|
||||
*
|
||||
* @param row
|
||||
* @param row_i
|
||||
* New row number for the current cell.
|
||||
* @param col
|
||||
* @param col_i
|
||||
* New row number for the current cell.
|
||||
*/
|
||||
void set_cur_cell(size_t row, size_t col)
|
||||
void set_cur_cell(size_t row_i, size_t col_i)
|
||||
{
|
||||
ft_set_cur_cell(table, row, col);
|
||||
ft_set_cur_cell(table_, row_i, col_i);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set table left margin.
|
||||
*
|
||||
* @param value
|
||||
* Left margin.
|
||||
* @return
|
||||
* - true: Success; table property was changed.
|
||||
* - false: In case of error.
|
||||
*/
|
||||
bool set_left_margin(unsigned value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_LEFT_MARGIN, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set table top margin.
|
||||
*
|
||||
* @param value
|
||||
* Top margin.
|
||||
* @return
|
||||
* - true: Success; table property was changed.
|
||||
* - false: In case of error.
|
||||
*/
|
||||
bool set_top_margin(unsigned value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_TOP_MARGIN, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set table right margin.
|
||||
*
|
||||
* @param value
|
||||
* Right margin.
|
||||
* @return
|
||||
* - true: Success; table property was changed.
|
||||
* - false: In case of error.
|
||||
*/
|
||||
bool set_right_margin(unsigned value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_RIGHT_MARGIN, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set table bottom margin.
|
||||
*
|
||||
* @param value
|
||||
* Bottom margin.
|
||||
* @return
|
||||
* - true: Success; table property was changed.
|
||||
* - false: In case of error.
|
||||
*/
|
||||
bool set_bottom_margin(unsigned value)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_BOTTOM_MARGIN, value));
|
||||
}
|
||||
private:
|
||||
ft_table_t *table;
|
||||
mutable std::stringstream stream;
|
||||
ft_table_t *table_;
|
||||
mutable std::stringstream stream_;
|
||||
friend class property_setter<table>;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/* Iterators */
|
||||
/* todo: implement chains like table[0][0] = table [0][1] = "somethings" */
|
||||
|
||||
class table_cell_iterator
|
||||
class table_cell_iterator: public property_setter<table>
|
||||
{
|
||||
public:
|
||||
table_cell_iterator(std::size_t row_idx, std::size_t coll_idx, Table &tbl)
|
||||
:row_idx_(row_idx), coll_idx_(coll_idx), table_(tbl) {}
|
||||
table_cell_iterator(std::size_t row_idx, std::size_t coll_idx, table &tbl)
|
||||
:property_setter(row_idx, coll_idx, tbl) {}
|
||||
|
||||
table_cell_iterator& operator=(const char *str)
|
||||
{
|
||||
ft_set_cur_cell(table_.table, row_idx_, coll_idx_);
|
||||
table_.write(str);
|
||||
ft_set_cur_cell(ps_table_.table_, ps_row_idx_, ps_coll_idx_);
|
||||
ps_table_.write(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
std::size_t row_idx_;
|
||||
std::size_t coll_idx_;
|
||||
Table &table_;
|
||||
};
|
||||
|
||||
class table_row_iterator
|
||||
class table_row_iterator: public property_setter<table>
|
||||
{
|
||||
public:
|
||||
table_row_iterator(std::size_t row_idx, Table &tbl)
|
||||
:row_idx_(row_idx), table_(tbl) {}
|
||||
table_row_iterator(std::size_t row_idx, table &tbl)
|
||||
:property_setter(row_idx, FT_ANY_COLUMN, tbl) {}
|
||||
|
||||
class table_cell_iterator
|
||||
operator[](std::size_t coll_idx)
|
||||
{
|
||||
return table_cell_iterator(row_idx_, coll_idx, table_);
|
||||
return table_cell_iterator(ps_row_idx_, coll_idx, ps_table_);
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
std::size_t row_idx_;
|
||||
Table &table_;
|
||||
class table_column_iterator: public property_setter<table>
|
||||
{
|
||||
public:
|
||||
table_column_iterator(std::size_t col_idx, table &tbl)
|
||||
:property_setter(FT_ANY_ROW, col_idx, tbl) {}
|
||||
};
|
||||
|
||||
class table_row_iterator
|
||||
@@ -626,6 +752,19 @@ public:
|
||||
{
|
||||
return table_row_iterator(row_idx, *this);
|
||||
}
|
||||
|
||||
class table_row_iterator
|
||||
row(std::size_t row_idx)
|
||||
{
|
||||
return table_row_iterator(row_idx, *this);
|
||||
}
|
||||
|
||||
class table_column_iterator
|
||||
column(std::size_t col_idx)
|
||||
{
|
||||
return table_column_iterator(col_idx, *this);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -638,61 +777,12 @@ public:
|
||||
* - True: Success; table border style was changed.
|
||||
* - False: Error
|
||||
*/
|
||||
bool set_default_border_style(struct ft_border_style *style)
|
||||
inline bool set_default_border_style(struct ft_border_style *style)
|
||||
{
|
||||
return FT_IS_SUCCESS(ft_set_default_border_style(style));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Declare specializations for set_property functions
|
||||
*/
|
||||
#define DECLARE_SPECS_FOR_CELL_PROPS_X \
|
||||
SET_CELL_PROP_SPEC(CellProperty::MinWidth, FT_CPROP_MIN_WIDTH, unsigned) \
|
||||
SET_CELL_PROP_SPEC(CellProperty::TextAlign, FT_CPROP_TEXT_ALIGN, TextAlign) \
|
||||
SET_CELL_PROP_SPEC(CellProperty::TopPadding, FT_CPROP_TOP_PADDING, unsigned) \
|
||||
SET_CELL_PROP_SPEC(CellProperty::BottomPadding, FT_CPROP_BOTTOM_PADDING, unsigned) \
|
||||
SET_CELL_PROP_SPEC(CellProperty::LeftPadding, FT_CPROP_LEFT_PADDING, unsigned) \
|
||||
SET_CELL_PROP_SPEC(CellProperty::RightPading, FT_CPROP_RIGHT_PADDING, unsigned) \
|
||||
SET_CELL_PROP_SPEC(CellProperty::EmptyStrHeight, FT_CPROP_EMPTY_STR_HEIGHT, unsigned) \
|
||||
SET_CELL_PROP_SPEC(CellProperty::RowType, FT_CPROP_ROW_TYPE, RowType)
|
||||
|
||||
#define SET_CELL_PROP_SPEC(CELL_OPTION, C_OPTION, VALUE_TYPE) \
|
||||
template <> \
|
||||
bool Table::set_property<CELL_OPTION>(size_t row, size_t col, VALUE_TYPE value) \
|
||||
{ \
|
||||
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, C_OPTION, static_cast<int>(value))); \
|
||||
}
|
||||
|
||||
DECLARE_SPECS_FOR_CELL_PROPS_X
|
||||
|
||||
#undef SET_TABLE_PROP_SPEC
|
||||
#undef DECLARE_SPECS_FOR_PROPS_X
|
||||
|
||||
|
||||
|
||||
#define DECLARE_SPECS_FOR_TABLE_PROPS_X \
|
||||
SET_TABLE_PROP_SPEC(TableProperty::LeftMargin, FT_TPROP_LEFT_MARGIN) \
|
||||
SET_TABLE_PROP_SPEC(TableProperty::TopMargin, FT_TPROP_TOP_MARGIN) \
|
||||
SET_TABLE_PROP_SPEC(TableProperty::RightMargin, FT_TPROP_RIGHT_MARGIN) \
|
||||
SET_TABLE_PROP_SPEC(TableProperty::BottomMargin, FT_TPROP_BOTTOM_MARGIN)
|
||||
|
||||
#define SET_TABLE_PROP_SPEC(TABLE_OPTION, TBL_OPTION) \
|
||||
template <> \
|
||||
bool Table::set_property<TABLE_OPTION>(unsigned value) \
|
||||
{ \
|
||||
return FT_IS_SUCCESS(ft_set_tbl_prop(table, TBL_OPTION, static_cast<int>(value))); \
|
||||
}
|
||||
|
||||
DECLARE_SPECS_FOR_TABLE_PROPS_X
|
||||
|
||||
#undef SET_TABLE_PROP_SPEC
|
||||
#undef DECLARE_SPECS_FOR_TABLE_PROPS_X
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // LIBFORT_HPP
|
||||
|
Reference in New Issue
Block a user