2018-05-05 17:38:45 +02:00
|
|
|
/*
|
|
|
|
libfort
|
|
|
|
|
|
|
|
MIT License
|
|
|
|
|
|
|
|
Copyright (c) 2017 - 2018 Seleznev Anton
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file fort.hpp
|
|
|
|
* @brief Main header file describing libfort C++ API .
|
|
|
|
*
|
|
|
|
* This files contains C++ wrappers around libfort API that can
|
|
|
|
* be used in C++ code.
|
|
|
|
*/
|
2018-04-01 10:36:52 +02:00
|
|
|
#ifndef LIBFORT_HPP
|
|
|
|
#define LIBFORT_HPP
|
|
|
|
|
|
|
|
#include <string>
|
2018-04-01 12:27:02 +02:00
|
|
|
#include <stdexcept>
|
2018-04-01 10:36:52 +02:00
|
|
|
#include <sstream>
|
2018-11-21 18:50:56 +01:00
|
|
|
|
2018-04-01 12:27:02 +02:00
|
|
|
#include "fort.h"
|
2018-04-01 10:36:52 +02:00
|
|
|
|
|
|
|
namespace fort
|
|
|
|
{
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Alignment of cell content.
|
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
enum class text_align {
|
|
|
|
left = FT_ALIGNED_LEFT,
|
|
|
|
center = FT_ALIGNED_CENTER,
|
|
|
|
right = FT_ALIGNED_RIGHT
|
2018-07-25 21:37:10 +02:00
|
|
|
};
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Type of table row. Determines appearance of row.
|
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
enum class row_type {
|
|
|
|
common = FT_ROW_COMMON,
|
|
|
|
header = FT_ROW_HEADER
|
2018-07-25 21:37:10 +02:00
|
|
|
};
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Colors.
|
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
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
|
2018-07-25 21:37:10 +02:00
|
|
|
};
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Text styles.
|
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
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
|
2018-07-25 21:37:10 +02:00
|
|
|
};
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Table manipulator.
|
|
|
|
*
|
|
|
|
* Table manipulators can be used to change current cell and change appearance
|
|
|
|
* of cells.
|
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
class table_manipulator {
|
2018-04-01 10:36:52 +02:00
|
|
|
public:
|
2018-11-21 18:50:56 +01:00
|
|
|
explicit table_manipulator(int i)
|
2018-04-01 10:36:52 +02:00
|
|
|
:value(i)
|
|
|
|
{
|
|
|
|
}
|
2018-11-21 18:50:56 +01:00
|
|
|
friend class table;
|
2018-04-01 10:36:52 +02:00
|
|
|
private:
|
|
|
|
int value;
|
|
|
|
};
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Table manipulator to set current row as a header.
|
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
const table_manipulator header(0);
|
2018-12-01 08:39:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Table manipulator to move current cell to the first cell of the next row.
|
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
const table_manipulator endr(1);
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Table manipulator to add separator to the table.
|
|
|
|
*/
|
|
|
|
const table_manipulator separator(2);
|
2018-11-21 18:50:56 +01:00
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Property owner.
|
|
|
|
*
|
|
|
|
* property_owner is a base class for all objects (table, row, column, cell) for
|
|
|
|
* which user can specify properties.
|
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
template <typename table>
|
2018-12-01 08:39:25 +01:00
|
|
|
class property_owner {
|
2018-11-21 18:50:56 +01:00
|
|
|
public:
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
property_owner(std::size_t row_idx, std::size_t coll_idx, table *tbl, bool def = false)
|
2018-11-23 19:02:08 +01:00
|
|
|
:ps_row_idx_(row_idx), ps_coll_idx_(coll_idx),
|
|
|
|
ps_table_(tbl), set_default_properties_(def) {}
|
2018-11-21 18:50:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2018-11-23 19:02:08 +01:00
|
|
|
return set_property(FT_CPROP_MIN_WIDTH, value);
|
2018-11-21 18:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2018-11-23 19:02:08 +01:00
|
|
|
return set_property(FT_CPROP_TEXT_ALIGN, static_cast<int>(value));
|
2018-11-21 18:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2018-11-23 19:02:08 +01:00
|
|
|
return set_property(FT_CPROP_TOP_PADDING, value);
|
2018-11-21 18:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2018-11-23 19:02:08 +01:00
|
|
|
return set_property(FT_CPROP_BOTTOM_PADDING, value);
|
2018-11-21 18:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2018-11-23 19:02:08 +01:00
|
|
|
return set_property(FT_CPROP_LEFT_PADDING, value);
|
2018-11-21 18:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2018-11-23 19:02:08 +01:00
|
|
|
return set_property(FT_CPROP_RIGHT_PADDING, value);
|
2018-11-21 18:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2018-11-23 19:02:08 +01:00
|
|
|
return set_property(FT_CPROP_ROW_TYPE, static_cast<int>(value));
|
2018-11-21 18:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2018-11-23 19:02:08 +01:00
|
|
|
return set_property(FT_CPROP_EMPTY_STR_HEIGHT, value);
|
2018-11-21 18:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2018-11-23 19:02:08 +01:00
|
|
|
return set_property(FT_CPROP_CONT_FG_COLOR, static_cast<int>(value));
|
2018-11-21 18:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2019-01-12 12:00:12 +01:00
|
|
|
bool set_cell_bg_color(enum fort::color value)
|
2018-11-21 18:50:56 +01:00
|
|
|
{
|
2018-11-23 19:02:08 +01:00
|
|
|
return set_property(FT_CPROP_CELL_BG_COLOR, static_cast<int>(value));
|
2018-11-21 18:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2018-11-23 19:02:08 +01:00
|
|
|
return set_property(FT_CPROP_CONT_BG_COLOR, static_cast<int>(value));
|
2018-11-21 18:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2019-01-12 12:00:12 +01:00
|
|
|
bool set_cell_text_style(enum fort::text_style value)
|
2018-11-21 18:50:56 +01:00
|
|
|
{
|
2018-11-23 19:02:08 +01:00
|
|
|
return set_property(FT_CPROP_CELL_TEXT_STYLE, static_cast<int>(value));
|
2018-11-21 18:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2018-11-23 19:02:08 +01:00
|
|
|
return set_property(FT_CPROP_CONT_TEXT_STYLE, static_cast<int>(value));
|
2018-11-21 18:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::size_t ps_row_idx_;
|
|
|
|
std::size_t ps_coll_idx_;
|
2018-11-23 19:02:08 +01:00
|
|
|
table *ps_table_;
|
|
|
|
bool set_default_properties_;
|
|
|
|
|
|
|
|
bool set_property(uint32_t property, int value)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
if (set_default_properties_) {
|
|
|
|
status = ft_set_default_cell_prop(property, value);
|
|
|
|
} else {
|
|
|
|
status = ft_set_cell_prop(ps_table_->table_, ps_row_idx_, ps_coll_idx_, property, value);
|
|
|
|
}
|
|
|
|
return FT_IS_SUCCESS(status);
|
|
|
|
}
|
2018-11-21 18:50:56 +01:00
|
|
|
};
|
2018-04-01 10:36:52 +02:00
|
|
|
|
2018-05-05 17:38:45 +02:00
|
|
|
/**
|
2018-12-01 08:39:25 +01:00
|
|
|
* Formatted table.
|
2018-05-05 17:38:45 +02:00
|
|
|
*
|
2018-07-22 21:52:55 +02:00
|
|
|
* Table class is a C++ wrapper around struct ft_table.
|
2018-05-05 17:38:45 +02:00
|
|
|
*/
|
2018-12-01 08:39:25 +01:00
|
|
|
class table: public property_owner<table> {
|
2018-04-01 10:36:52 +02:00
|
|
|
public:
|
2018-12-01 08:39:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default constructor.
|
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
table()
|
2018-12-01 08:39:25 +01:00
|
|
|
:property_owner(FT_ANY_ROW, FT_ANY_COLUMN, this), table_(ft_create_table())
|
2018-04-01 10:36:52 +02:00
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
|
|
|
|
if (table_ == NULL)
|
2018-12-01 08:39:25 +01:00
|
|
|
throw std::runtime_error("Libfort runtime error");
|
2018-04-01 10:36:52 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
~table()
|
2018-04-01 10:36:52 +02:00
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
ft_destroy_table(table_);
|
2018-04-01 10:36:52 +02:00
|
|
|
}
|
|
|
|
|
2018-11-02 18:06:04 +01:00
|
|
|
/**
|
2018-11-02 22:16:20 +01:00
|
|
|
* Copy contstructor.
|
2018-11-02 18:06:04 +01:00
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
table(const table& tbl)
|
2018-12-01 08:39:25 +01:00
|
|
|
:property_owner(FT_ANY_ROW, FT_ANY_COLUMN, this), table_(NULL)
|
2018-11-02 22:16:20 +01:00
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
if (tbl.table_) {
|
|
|
|
ft_table_t *table_copy = ft_copy_table(tbl.table_);
|
2018-11-02 22:16:20 +01:00
|
|
|
if (table_copy == NULL)
|
2018-12-01 08:39:25 +01:00
|
|
|
throw std::runtime_error("Libfort runtime error");
|
2018-11-02 22:16:20 +01:00
|
|
|
|
2018-11-21 18:50:56 +01:00
|
|
|
stream_.str(std::string());
|
|
|
|
if (tbl.stream_.tellp() >= 0) {
|
|
|
|
stream_ << tbl.stream_.str();
|
2018-11-02 22:16:20 +01:00
|
|
|
}
|
2018-11-21 18:50:56 +01:00
|
|
|
table_ = table_copy;
|
2018-11-02 22:16:20 +01:00
|
|
|
}
|
|
|
|
}
|
2018-11-02 18:06:04 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Move contstructor.
|
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
table(table&& tbl)
|
2018-12-01 08:39:25 +01:00
|
|
|
:property_owner(FT_ANY_ROW, FT_ANY_COLUMN, this), table_(tbl.table_)
|
2018-11-02 18:06:04 +01:00
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
if (tbl.stream_.tellp() >= 0) {
|
|
|
|
stream_ << tbl.stream_.str();
|
|
|
|
tbl.stream_.str(std::string());
|
2018-11-02 18:06:04 +01:00
|
|
|
}
|
2018-11-21 18:50:56 +01:00
|
|
|
tbl.table_ = 0;
|
2018-11-02 18:06:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-11-02 22:16:20 +01:00
|
|
|
* Copy assignment operator.
|
2018-11-02 18:06:04 +01:00
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
table& operator=(const table& tbl)
|
2018-11-02 22:16:20 +01:00
|
|
|
{
|
|
|
|
if (&tbl == this)
|
|
|
|
return *this;
|
|
|
|
|
2018-11-21 18:50:56 +01:00
|
|
|
if (tbl.table_) {
|
|
|
|
ft_table_t *table_copy = ft_copy_table(tbl.table_);
|
2018-11-02 22:16:20 +01:00
|
|
|
if (table_copy == NULL)
|
2018-12-01 08:39:25 +01:00
|
|
|
throw std::runtime_error("Libfort runtime error");
|
2018-11-02 22:16:20 +01:00
|
|
|
|
2018-11-21 18:50:56 +01:00
|
|
|
stream_.str(std::string());
|
|
|
|
if (tbl.stream_.tellp() >= 0) {
|
|
|
|
stream_ << tbl.stream_.str();
|
2018-11-02 22:16:20 +01:00
|
|
|
}
|
2018-11-21 18:50:56 +01:00
|
|
|
ft_destroy_table(table_);
|
|
|
|
table_ = table_copy;
|
2018-11-02 22:16:20 +01:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2018-11-02 18:06:04 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Move assignment operator.
|
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
table& operator=(table&& tbl)
|
2018-11-02 18:06:04 +01:00
|
|
|
{
|
|
|
|
if (&tbl == this)
|
|
|
|
return *this;
|
|
|
|
|
2018-11-21 18:50:56 +01:00
|
|
|
if (tbl.table_) {
|
|
|
|
stream_.str(std::string());
|
|
|
|
if (tbl.stream_.tellp() >= 0) {
|
|
|
|
stream_ << tbl.stream_.str();
|
|
|
|
tbl.stream_.str(std::string());
|
2018-11-02 18:06:04 +01:00
|
|
|
}
|
2018-11-21 18:50:56 +01:00
|
|
|
ft_destroy_table(table_);
|
|
|
|
table_ = tbl.table_;
|
|
|
|
tbl.table_ = NULL;
|
2018-11-02 18:06:04 +01:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-07-22 21:52:55 +02:00
|
|
|
/**
|
|
|
|
* Convert table to string representation.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - String representation of formatted table, on success.
|
|
|
|
* - In case of error std::runtime_error is thrown.
|
|
|
|
*/
|
2018-04-01 10:36:52 +02:00
|
|
|
std::string to_string() const
|
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
const char *str = ft_to_string(table_);
|
2018-04-01 10:36:52 +02:00
|
|
|
if (str == NULL)
|
2018-12-01 08:39:25 +01:00
|
|
|
throw std::runtime_error("Libfort runtime error");
|
2018-04-01 10:36:52 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2018-07-22 21:52:55 +02:00
|
|
|
/**
|
|
|
|
* Convert table to string representation.
|
|
|
|
*
|
|
|
|
* Table object has ownership of the returned pointer. So there is no need to
|
|
|
|
* free it. To take ownership user should explicitly copy the returned
|
|
|
|
* string with strdup or similar functions.
|
|
|
|
*
|
|
|
|
* Returned pointer may be later invalidated by:
|
|
|
|
* - Calling destroying the table;
|
|
|
|
* - Other invocations of c_str or to_string.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - The pointer to the string representation of formatted table, on success.
|
|
|
|
* - NULL on error.
|
|
|
|
*/
|
2018-04-01 10:36:52 +02:00
|
|
|
const char *c_str() const
|
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
return ft_to_string(table_);
|
2018-04-01 10:36:52 +02:00
|
|
|
}
|
|
|
|
|
2018-07-22 21:52:55 +02:00
|
|
|
/**
|
2018-12-22 09:35:55 +01:00
|
|
|
* Write provided object to the table.
|
2018-07-22 21:52:55 +02:00
|
|
|
*
|
|
|
|
* To convert object to the string representation conversion for
|
|
|
|
* std::ostream is used.
|
|
|
|
*
|
|
|
|
* @param arg
|
|
|
|
* Obect that would be inserted in the current cell.
|
|
|
|
* @return
|
|
|
|
* - Reference to the current table.
|
|
|
|
*/
|
2018-04-01 10:36:52 +02:00
|
|
|
template <typename T>
|
2018-11-21 18:50:56 +01:00
|
|
|
table &operator<<(const T &arg)
|
2018-04-01 10:36:52 +02:00
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
stream_ << arg;
|
|
|
|
if (stream_.tellp() >= 0) {
|
|
|
|
ft_nwrite(table_, 1, stream_.str().c_str());
|
|
|
|
stream_.str(std::string());
|
2018-04-08 14:48:15 +02:00
|
|
|
}
|
2018-04-01 10:36:52 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-11-21 18:50:56 +01:00
|
|
|
table &operator<<(const table_manipulator &arg)
|
2018-04-01 10:36:52 +02:00
|
|
|
{
|
|
|
|
if (arg.value == header.value)
|
2018-11-21 18:50:56 +01:00
|
|
|
ft_set_cell_prop(table_, FT_CUR_ROW, FT_ANY_ROW, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
2018-07-22 21:52:55 +02:00
|
|
|
else if (arg.value == endr.value)
|
2018-11-21 18:50:56 +01:00
|
|
|
ft_ln(table_);
|
2018-04-01 10:36:52 +02:00
|
|
|
else if (arg.value == separator.value)
|
2018-11-21 18:50:56 +01:00
|
|
|
ft_add_separator(table_);
|
2018-04-01 10:36:52 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Write string to the the table.
|
|
|
|
*
|
|
|
|
* Write specified string to the current cell.
|
|
|
|
*
|
|
|
|
* @param str
|
|
|
|
* String to write.
|
|
|
|
* @return
|
|
|
|
* - 0: Success; data were written
|
|
|
|
* - (<0): In case of error
|
|
|
|
*/
|
2018-04-08 14:48:15 +02:00
|
|
|
bool write(const char *str)
|
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
return FT_IS_SUCCESS(ft_write(table_, str));
|
2018-04-08 14:48:15 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Write string to the the table and go to the next line.
|
|
|
|
*
|
|
|
|
* Write specified string to the current cell and move current position to
|
|
|
|
* the first cell of the next line(row).
|
|
|
|
*
|
|
|
|
* @param str
|
|
|
|
* String to write.
|
|
|
|
* @return
|
|
|
|
* - 0: Success; data were written
|
|
|
|
* - (<0): In case of error
|
|
|
|
*/
|
2018-04-08 14:48:15 +02:00
|
|
|
bool write_ln(const char *str)
|
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
return FT_IS_SUCCESS(ft_write_ln(table_, str));
|
2018-04-08 14:48:15 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Write string to the the table.
|
|
|
|
*
|
|
|
|
* Write specified string to the current cell.
|
|
|
|
*
|
|
|
|
* @param str
|
|
|
|
* String to write.
|
|
|
|
* @return
|
|
|
|
* - 0: Success; data were written
|
|
|
|
* - (<0): In case of error
|
|
|
|
*/
|
2018-04-08 14:48:15 +02:00
|
|
|
bool write(const std::string &str)
|
|
|
|
{
|
|
|
|
return write(str.c_str());
|
|
|
|
}
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Write string to the the table and go to the next line.
|
|
|
|
*
|
|
|
|
* Write specified string to the current cell and move current position to
|
|
|
|
* the first cell of the next line(row).
|
|
|
|
*
|
|
|
|
* @param str
|
|
|
|
* String to write.
|
|
|
|
* @return
|
|
|
|
* - 0: Success; data were written
|
|
|
|
* - (<0): In case of error
|
|
|
|
*/
|
2018-04-08 14:48:15 +02:00
|
|
|
bool write_ln(const std::string &str)
|
|
|
|
{
|
|
|
|
return write_ln(str.c_str());
|
|
|
|
}
|
|
|
|
|
2018-04-08 15:56:43 +02:00
|
|
|
#ifdef __cpp_variadic_templates
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Write strings to the table.
|
|
|
|
*
|
|
|
|
* Write specified strings to the same number of consecutive cells in the
|
|
|
|
* current row.
|
|
|
|
*
|
|
|
|
* @param str
|
|
|
|
* String to write.
|
|
|
|
* @param strings
|
|
|
|
* Strings to write.
|
|
|
|
* @return
|
|
|
|
* - 0: Success; data were written
|
|
|
|
* - (<0): In case of error
|
|
|
|
*/
|
2018-04-08 14:48:15 +02:00
|
|
|
template <typename T, typename ...Ts>
|
2018-12-01 08:39:25 +01:00
|
|
|
bool write(const T &str, const Ts &...strings)
|
2018-04-08 14:48:15 +02:00
|
|
|
{
|
2018-12-01 08:39:25 +01:00
|
|
|
return write(str) && write(strings...);
|
2018-04-08 14:48:15 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Write strings to the table and go to the next line.
|
|
|
|
*
|
|
|
|
* Write specified strings to the same number of consecutive cells in the
|
|
|
|
* current row and move current position to the first cell of the next
|
|
|
|
* line(row).
|
|
|
|
*
|
|
|
|
* @param str
|
|
|
|
* String to write.
|
|
|
|
* @param strings
|
|
|
|
* Strings to write.
|
|
|
|
* @return
|
|
|
|
* - 0: Success; data were written
|
|
|
|
* - (<0): In case of error
|
|
|
|
*/
|
2018-04-08 14:48:15 +02:00
|
|
|
template <typename T, typename ...Ts>
|
2018-12-01 08:39:25 +01:00
|
|
|
bool write_ln(const T &str, const Ts &...strings)
|
2018-04-08 14:48:15 +02:00
|
|
|
{
|
2018-12-01 08:39:25 +01:00
|
|
|
return write(str) && write_ln(strings...);
|
2018-04-08 14:48:15 +02:00
|
|
|
}
|
2018-04-08 15:56:43 +02:00
|
|
|
#else /* __cpp_variadic_templates */
|
|
|
|
|
|
|
|
template <typename T_0, typename T_1>
|
|
|
|
bool write(const T_0 &arg_0, const T_1 &arg_1)
|
|
|
|
{
|
|
|
|
return write(arg_0) && write(arg_1);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T_0, typename T_1, typename T_2>
|
|
|
|
bool write(const T_0 &arg_0, const T_1 &arg_1, const T_2 &arg_2)
|
|
|
|
{
|
|
|
|
return write(arg_0) && write(arg_1, arg_2);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T_0, typename T_1, typename T_2, typename T_3>
|
|
|
|
bool write(const T_0 &arg_0, const T_1 &arg_1, const T_2 &arg_2, const T_3 &arg_3)
|
|
|
|
{
|
|
|
|
return write(arg_0) && write(arg_1, arg_2, arg_3);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T_0, typename T_1, typename T_2, typename T_3, typename T_4>
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return write(arg_0) && write(arg_1, arg_2, arg_3, arg_4);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T_0, typename T_1, typename T_2, typename T_3, typename T_4, typename T_5>
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return write(arg_0) && write(arg_1, arg_2, arg_3, arg_4, arg_5);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T_0, typename T_1, typename T_2, typename T_3, typename T_4, typename T_5, typename T_6>
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return write(arg_0) && write(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6);
|
|
|
|
}
|
|
|
|
|
|
|
|
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>
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return write(arg_0) && write(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6, arg_7);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T_0, typename T_1>
|
|
|
|
bool write_ln(const T_0 &arg_0, const T_1 &arg_1)
|
|
|
|
{
|
|
|
|
return write(arg_0) && write_ln(arg_1);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T_0, typename T_1, typename T_2>
|
|
|
|
bool write_ln(const T_0 &arg_0, const T_1 &arg_1, const T_2 &arg_2)
|
|
|
|
{
|
|
|
|
return write(arg_0) && write_ln(arg_1, arg_2);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T_0, typename T_1, typename T_2, typename T_3>
|
|
|
|
bool write_ln(const T_0 &arg_0, const T_1 &arg_1, const T_2 &arg_2, const T_3 &arg_3)
|
|
|
|
{
|
|
|
|
return write(arg_0) && write_ln(arg_1, arg_2, arg_3);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T_0, typename T_1, typename T_2, typename T_3, typename T_4>
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return write(arg_0) && write_ln(arg_1, arg_2, arg_3, arg_4);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T_0, typename T_1, typename T_2, typename T_3, typename T_4, typename T_5>
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return write(arg_0) && write_ln(arg_1, arg_2, arg_3, arg_4, arg_5);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T_0, typename T_1, typename T_2, typename T_3, typename T_4, typename T_5, typename T_6>
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return write(arg_0) && write_ln(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6);
|
|
|
|
}
|
|
|
|
|
|
|
|
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>
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return write(arg_0) && write_ln(arg_1, arg_2, arg_3, arg_4, arg_5, arg_6, arg_7);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __cpp_variadic_templates */
|
2018-04-01 10:36:52 +02:00
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Write elements from range to the table.
|
|
|
|
*
|
|
|
|
* Write objects from range to consecutive cells in the current row.
|
|
|
|
*
|
|
|
|
* @param first, last
|
|
|
|
* Range of elements.
|
|
|
|
* @return
|
|
|
|
* - 0: Success; data were written
|
|
|
|
* - (<0): In case of error
|
|
|
|
*/
|
2018-08-09 21:15:05 +02:00
|
|
|
template <typename InputIt>
|
2018-12-01 08:39:25 +01:00
|
|
|
bool range_write(InputIt first, InputIt last)
|
2018-08-09 21:15:05 +02:00
|
|
|
{
|
|
|
|
while (first != last) {
|
|
|
|
*this << *first;
|
|
|
|
++first;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
/**
|
|
|
|
* Write elements from range to the table and go to the next line.
|
|
|
|
*
|
|
|
|
* Write objects from range to consecutive cells in the current row and
|
|
|
|
* move current position to the first cell of the next line(row).
|
|
|
|
*
|
|
|
|
* @param first, last
|
|
|
|
* Range of elements.
|
|
|
|
* @return
|
|
|
|
* - 0: Success; data were written
|
|
|
|
* - (<0): In case of error
|
|
|
|
*/
|
2018-08-09 21:15:05 +02:00
|
|
|
template <typename InputIt>
|
2018-12-01 08:39:25 +01:00
|
|
|
bool range_write_ln(InputIt first, InputIt last)
|
2018-08-09 21:15:05 +02:00
|
|
|
{
|
|
|
|
while (first != last) {
|
|
|
|
*this << *first;
|
|
|
|
++first;
|
|
|
|
}
|
2018-11-21 18:50:56 +01:00
|
|
|
ft_ln(table_);
|
2018-08-09 21:15:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-25 21:37:10 +02:00
|
|
|
/**
|
2018-11-21 18:50:56 +01:00
|
|
|
* Set border style for the table.
|
2018-07-25 21:37:10 +02:00
|
|
|
*
|
2018-11-21 18:50:56 +01:00
|
|
|
* @param style
|
|
|
|
* Pointer to border style.
|
2018-07-25 21:37:10 +02:00
|
|
|
* @return
|
2018-11-21 18:50:56 +01:00
|
|
|
* - True: Success; table border style was changed.
|
|
|
|
* - False: Error
|
2018-07-25 21:37:10 +02:00
|
|
|
*/
|
2019-04-27 15:00:20 +02:00
|
|
|
bool set_border_style(const struct ft_border_style *style)
|
2018-07-25 21:37:10 +02:00
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
return FT_IS_SUCCESS(ft_set_border_style(table_, style));
|
2018-07-25 21:37:10 +02:00
|
|
|
}
|
|
|
|
|
2018-07-29 08:59:40 +02:00
|
|
|
/**
|
2018-11-21 18:50:56 +01:00
|
|
|
* Set current cell position.
|
2018-07-29 08:59:40 +02:00
|
|
|
*
|
2018-11-21 18:50:56 +01:00
|
|
|
* Current cell - cell that will be edited with all modifiing functions.
|
2018-07-29 08:59:40 +02:00
|
|
|
*
|
2018-11-21 18:50:56 +01:00
|
|
|
* @param row_i
|
|
|
|
* New row number for the current cell.
|
|
|
|
* @param col_i
|
|
|
|
* New row number for the current cell.
|
2018-07-29 08:59:40 +02:00
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
void set_cur_cell(size_t row_i, size_t col_i)
|
2018-07-29 08:59:40 +02:00
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
ft_set_cur_cell(table_, row_i, col_i);
|
2018-07-29 08:59:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 21:37:10 +02:00
|
|
|
|
2018-07-29 08:59:40 +02:00
|
|
|
/**
|
2018-11-21 18:50:56 +01:00
|
|
|
* Set table left margin.
|
2018-07-29 08:59:40 +02:00
|
|
|
*
|
|
|
|
* @param value
|
2018-11-21 18:50:56 +01:00
|
|
|
* Left margin.
|
2018-07-29 08:59:40 +02:00
|
|
|
* @return
|
2018-11-21 18:50:56 +01:00
|
|
|
* - true: Success; table property was changed.
|
|
|
|
* - false: In case of error.
|
2018-07-29 08:59:40 +02:00
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
bool set_left_margin(unsigned value)
|
2018-07-29 08:59:40 +02:00
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_LEFT_MARGIN, value));
|
2018-07-29 08:59:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-11-21 18:50:56 +01:00
|
|
|
* Set table top margin.
|
2018-07-29 08:59:40 +02:00
|
|
|
*
|
|
|
|
* @param value
|
2018-11-21 18:50:56 +01:00
|
|
|
* Top margin.
|
2018-07-29 08:59:40 +02:00
|
|
|
* @return
|
2018-11-21 18:50:56 +01:00
|
|
|
* - true: Success; table property was changed.
|
|
|
|
* - false: In case of error.
|
2018-07-29 08:59:40 +02:00
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
bool set_top_margin(unsigned value)
|
2018-07-29 08:59:40 +02:00
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_TOP_MARGIN, value));
|
2018-07-29 08:59:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-11-21 18:50:56 +01:00
|
|
|
* Set table right margin.
|
2018-07-29 08:59:40 +02:00
|
|
|
*
|
|
|
|
* @param value
|
2018-11-21 18:50:56 +01:00
|
|
|
* Right margin.
|
2018-07-29 08:59:40 +02:00
|
|
|
* @return
|
2018-11-21 18:50:56 +01:00
|
|
|
* - true: Success; table property was changed.
|
|
|
|
* - false: In case of error.
|
2018-07-29 08:59:40 +02:00
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
bool set_right_margin(unsigned value)
|
2018-07-29 08:59:40 +02:00
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_RIGHT_MARGIN, value));
|
2018-07-29 08:59:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-11-21 18:50:56 +01:00
|
|
|
* Set table bottom margin.
|
2018-07-29 08:59:40 +02:00
|
|
|
*
|
|
|
|
* @param value
|
2018-11-21 18:50:56 +01:00
|
|
|
* Bottom margin.
|
2018-07-29 08:59:40 +02:00
|
|
|
* @return
|
2018-11-21 18:50:56 +01:00
|
|
|
* - true: Success; table property was changed.
|
|
|
|
* - false: In case of error.
|
2018-07-29 08:59:40 +02:00
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
bool set_bottom_margin(unsigned value)
|
2018-07-29 08:59:40 +02:00
|
|
|
{
|
2018-11-21 18:50:56 +01:00
|
|
|
return FT_IS_SUCCESS(ft_set_tbl_prop(table_, FT_TPROP_BOTTOM_MARGIN, value));
|
2018-07-25 21:37:10 +02:00
|
|
|
}
|
2018-04-01 10:36:52 +02:00
|
|
|
private:
|
2018-11-21 18:50:56 +01:00
|
|
|
ft_table_t *table_;
|
|
|
|
mutable std::stringstream stream_;
|
2018-12-01 08:39:25 +01:00
|
|
|
friend class property_owner<table>;
|
2018-11-21 18:50:56 +01:00
|
|
|
|
2018-08-12 11:00:07 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/* Iterators */
|
|
|
|
/* todo: implement chains like table[0][0] = table [0][1] = "somethings" */
|
|
|
|
|
2018-12-22 09:48:57 +01:00
|
|
|
/**
|
|
|
|
* Table cell.
|
|
|
|
*/
|
2018-12-22 09:06:10 +01:00
|
|
|
class table_cell: public property_owner<table>
|
2018-08-12 11:00:07 +02:00
|
|
|
{
|
|
|
|
public:
|
2018-12-22 09:06:10 +01:00
|
|
|
table_cell(std::size_t row_idx, std::size_t coll_idx, table &tbl)
|
2018-12-01 08:39:25 +01:00
|
|
|
:property_owner(row_idx, coll_idx, &tbl) {}
|
2018-08-12 11:00:07 +02:00
|
|
|
|
2018-12-22 09:06:10 +01:00
|
|
|
table_cell& operator=(const char *str)
|
2018-08-12 11:00:07 +02:00
|
|
|
{
|
2018-11-23 19:02:08 +01:00
|
|
|
ft_set_cur_cell(ps_table_->table_, ps_row_idx_, ps_coll_idx_);
|
|
|
|
ps_table_->write(str);
|
2018-08-12 11:00:07 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2018-12-01 08:39:25 +01:00
|
|
|
|
2018-12-22 09:06:10 +01:00
|
|
|
table_cell& operator=(const std::string &str)
|
2018-12-01 08:39:25 +01:00
|
|
|
{
|
|
|
|
return operator=(str.c_str());
|
|
|
|
}
|
2018-12-22 09:06:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
if (set_default_properties_)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return FT_IS_SUCCESS(ft_set_cell_span(ps_table_->table_, ps_row_idx_, ps_coll_idx_, hor_span));
|
|
|
|
}
|
2018-08-12 11:00:07 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 09:48:57 +01:00
|
|
|
/**
|
|
|
|
* Table row.
|
|
|
|
*/
|
2018-12-22 09:06:10 +01:00
|
|
|
class table_row: public property_owner<table>
|
2018-08-12 11:00:07 +02:00
|
|
|
{
|
|
|
|
public:
|
2018-12-22 09:06:10 +01:00
|
|
|
table_row(std::size_t row_idx, table &tbl)
|
2018-12-01 08:39:25 +01:00
|
|
|
:property_owner(row_idx, FT_ANY_COLUMN, &tbl) {}
|
2018-08-12 11:00:07 +02:00
|
|
|
|
2018-12-22 09:06:10 +01:00
|
|
|
class table_cell
|
2018-08-12 11:00:07 +02:00
|
|
|
operator[](std::size_t coll_idx)
|
|
|
|
{
|
2018-12-22 09:06:10 +01:00
|
|
|
return table_cell(ps_row_idx_, coll_idx, *ps_table_);
|
2018-08-12 11:00:07 +02:00
|
|
|
}
|
2018-11-21 18:50:56 +01:00
|
|
|
};
|
2018-08-12 11:00:07 +02:00
|
|
|
|
2018-12-22 09:48:57 +01:00
|
|
|
/**
|
|
|
|
* Table column.
|
|
|
|
*/
|
2018-12-22 09:06:10 +01:00
|
|
|
class table_column: public property_owner<table>
|
2018-11-21 18:50:56 +01:00
|
|
|
{
|
|
|
|
public:
|
2018-12-22 09:06:10 +01:00
|
|
|
table_column(std::size_t col_idx, table &tbl)
|
2018-12-01 08:39:25 +01:00
|
|
|
:property_owner(FT_ANY_ROW, col_idx, &tbl) {}
|
2018-11-23 19:02:08 +01:00
|
|
|
};
|
|
|
|
|
2018-12-01 08:39:25 +01:00
|
|
|
class default_properties: public property_owner<table>
|
2018-11-23 19:02:08 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
default_properties(table *tbl)
|
2018-12-01 08:39:25 +01:00
|
|
|
:property_owner(FT_ANY_ROW, FT_ANY_COLUMN, tbl, true) {}
|
2018-08-12 11:00:07 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 09:06:10 +01:00
|
|
|
class table_row
|
2018-08-12 11:00:07 +02:00
|
|
|
operator[](std::size_t row_idx)
|
|
|
|
{
|
2018-12-22 09:06:10 +01:00
|
|
|
return table_row(row_idx, *this);
|
2018-08-12 11:00:07 +02:00
|
|
|
}
|
2018-11-21 18:50:56 +01:00
|
|
|
|
2018-12-22 09:35:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get cell.
|
|
|
|
*
|
|
|
|
* @param row_idx
|
|
|
|
* Row index.
|
|
|
|
* @param col_idx
|
|
|
|
* Column index.
|
|
|
|
* @return
|
|
|
|
* table_cell object.
|
|
|
|
*/
|
|
|
|
class table_cell
|
|
|
|
cell(std::size_t row_idx, std::size_t col_idx)
|
|
|
|
{
|
|
|
|
return (*this)[row_idx][col_idx];
|
|
|
|
}
|
|
|
|
|
2019-08-27 12:48:36 +02:00
|
|
|
/**
|
|
|
|
* Get column number of the current cell.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* Column number of the current cell.
|
|
|
|
*/
|
2019-08-26 13:26:41 +02:00
|
|
|
size_t
|
|
|
|
cur_col()
|
|
|
|
{
|
|
|
|
return ft_cur_col(table_);
|
|
|
|
}
|
|
|
|
|
2019-08-27 12:48:36 +02:00
|
|
|
/**
|
|
|
|
* Get row number of the current cell.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* Row number of the current cell.
|
|
|
|
*/
|
2019-08-26 13:26:41 +02:00
|
|
|
size_t
|
|
|
|
cur_row()
|
|
|
|
{
|
|
|
|
return ft_cur_row(table_);
|
|
|
|
}
|
|
|
|
|
2019-08-27 12:48:36 +02:00
|
|
|
/**
|
|
|
|
* Get current cell.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* Current cell.
|
|
|
|
*/
|
2019-08-26 13:26:41 +02:00
|
|
|
class table_cell
|
|
|
|
cur_cell()
|
|
|
|
{
|
|
|
|
return cell(cur_row(), cur_col());
|
|
|
|
}
|
|
|
|
|
2018-12-22 09:35:55 +01:00
|
|
|
/**
|
|
|
|
* Get row.
|
|
|
|
*
|
|
|
|
* @param row_idx
|
|
|
|
* Row index.
|
|
|
|
* @return
|
|
|
|
* table_row object.
|
|
|
|
*/
|
2018-12-22 09:06:10 +01:00
|
|
|
class table_row
|
2018-11-21 18:50:56 +01:00
|
|
|
row(std::size_t row_idx)
|
|
|
|
{
|
2018-12-22 09:06:10 +01:00
|
|
|
return table_row(row_idx, *this);
|
2018-11-21 18:50:56 +01:00
|
|
|
}
|
|
|
|
|
2018-12-22 09:35:55 +01:00
|
|
|
/**
|
|
|
|
* Get column.
|
|
|
|
*
|
|
|
|
* @param col_idx
|
|
|
|
* Column index.
|
|
|
|
* @return
|
|
|
|
* table_column object.
|
|
|
|
*/
|
2018-12-22 09:06:10 +01:00
|
|
|
class table_column
|
2018-11-21 18:50:56 +01:00
|
|
|
column(std::size_t col_idx)
|
|
|
|
{
|
2018-12-22 09:06:10 +01:00
|
|
|
return table_column(col_idx, *this);
|
2018-11-21 18:50:56 +01:00
|
|
|
}
|
|
|
|
|
2018-11-23 19:02:08 +01:00
|
|
|
static class default_properties
|
|
|
|
default_props()
|
|
|
|
{
|
|
|
|
return default_properties(NULL);
|
|
|
|
}
|
2018-04-01 10:36:52 +02:00
|
|
|
};
|
|
|
|
|
2018-07-25 21:37:10 +02:00
|
|
|
|
2018-11-03 18:24:50 +01:00
|
|
|
/**
|
|
|
|
* Set default border style for all new formatted tables.
|
|
|
|
*
|
|
|
|
* @param style
|
|
|
|
* Pointer to border style.
|
|
|
|
* @return
|
|
|
|
* - True: Success; table border style was changed.
|
|
|
|
* - False: Error
|
|
|
|
*/
|
2018-11-21 18:50:56 +01:00
|
|
|
inline bool set_default_border_style(struct ft_border_style *style)
|
2018-11-03 18:24:50 +01:00
|
|
|
{
|
|
|
|
return FT_IS_SUCCESS(ft_set_default_border_style(style));
|
|
|
|
}
|
2018-07-25 21:37:10 +02:00
|
|
|
|
|
|
|
|
2018-04-01 10:36:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // LIBFORT_HPP
|