From 199e123383b858a1f9d1b78122dc114b1ab94e4a Mon Sep 17 00:00:00 2001 From: seleznevae Date: Sun, 29 Jul 2018 09:59:40 +0300 Subject: [PATCH] [F] Moved to c++11 --- CMakeLists.txt | 2 +- example/main.cpp | 13 ++++-- lib/fort.hpp | 116 +++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 123 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fda155..06a926f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ if("${FORT_COMPILER}" STREQUAL "MSVC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W4") else("${FORT_COMPILER}" STREQUAL "MSVC") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g -Wextra -std=c99 -Wpedantic") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -Wextra") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -Wextra -std=c++11") endif("${FORT_COMPILER}" STREQUAL "MSVC") diff --git a/example/main.cpp b/example/main.cpp index 7ce16af..831e583 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -16,6 +16,13 @@ int main() << "4" << "2001: A Space Odyssey" << "1968" << "8.5" << fort::endr << "5" << "Blade Runner" << "1982" << "8.1" << fort::endr << fort::endr; + + using fort::CellOption; + using fort::TableOption; + table.set_option(0, 0, 20); + table.set_option(0, 0, fort::TextAlign::Left); + table.set_option(2, FT_ANY_COLUMN, fort::RowType::Header); + std::cout << table.to_string() << std::endl; } @@ -33,9 +40,9 @@ int main() using fort::CellOption; using fort::TableOption; - table.set_option(0, 0, 20); - table.set_option(0, 0, fort::TextAlign::Left); - table.set_option(2, FT_ANY_COLUMN, fort::RowType::Header); + table.set_cell_min_width(0, 0, 20); + table.set_cell_text_align(0, 0, fort::TextAlign::Left); + table.set_cell_row_type(2, FT_ANY_COLUMN, fort::RowType::Header); table.set_option(4); diff --git a/lib/fort.hpp b/lib/fort.hpp index 08e2f97..73831c8 100644 --- a/lib/fort.hpp +++ b/lib/fort.hpp @@ -61,13 +61,13 @@ enum class TableOption { }; enum class TextAlign { - Left, + Left = 0, Center, Right }; enum class RowType { - Common, + Common = 0, Header }; @@ -315,6 +315,42 @@ public: return FT_IS_SUCCESS(ft_set_cell_option(table, row, col, FT_COPT_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 option 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_option(table, row, col, FT_COPT_TEXT_ALIGN, static_cast(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 option 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_option(table, row, col, FT_COPT_TOP_PADDING, value)); + } + /** * Set bottom padding for the specified cell of the table. * @@ -333,14 +369,86 @@ public: return FT_IS_SUCCESS(ft_set_cell_option(table, row, col, FT_COPT_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 option 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_option(table, row, col, FT_COPT_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 option 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_option(table, row, col, FT_COPT_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 option 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_option(table, row, col, FT_COPT_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 option 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_option(table, row, col, FT_COPT_ROW_TYPE, static_cast(value))); + } + template bool set_option(size_t row, size_t col, unsigned value); template - bool set_option(size_t row, size_t col, TextAlign align); + bool set_option(size_t row, size_t col, enum TextAlign align); template - bool set_option(size_t row, size_t col, RowType rowType); + bool set_option(size_t row, size_t col, enum RowType rowType); template bool set_option(unsigned value);