[F] Fix compilation error

This commit is contained in:
seleznevae 2020-01-19 22:24:17 +03:00
parent 1ed13718d5
commit 4871105b0f
4 changed files with 131 additions and 53 deletions

View File

@ -1023,7 +1023,11 @@ public:
}; };
/** /**
* Table column. * Range of cells.
*
* @note: at the moment function of propery owener will work only on the
* top left cell.
* @todo: Implement their work on the whole range.
*/ */
class cell_range: public property_owner_t class cell_range: public property_owner_t
{ {
@ -1031,17 +1035,26 @@ public:
using property_owner_t::ps_row_idx_; using property_owner_t::ps_row_idx_;
using property_owner_t::ps_table_; using property_owner_t::ps_table_;
public: public:
table_column(std::size_t col_idx, table &tbl) cell_range(size_t top_left_row, size_t top_left_col,
: property_owner_t(FT_ANY_ROW, col_idx, &tbl) {} size_t bottom_right_row, size_t bottom_right_col,
table &tbl)
: property_owner_t(top_left_row, top_left_col, &tbl),
bottom_right_row_(bottom_right_row),
bottom_right_col_(bottom_right_col)
{}
void erase() void erase()
{ {
if (FT_IS_ERROR(ft_erase_range(ps_table_->table_, if (FT_IS_ERROR(ft_erase_range(ps_table_->table_,
0, ps_coll_idx_, ps_row_idx_, ps_coll_idx_,
(UINT_MAX - 2), ps_coll_idx_))) { bottom_right_row_, bottom_right_col_))) {
throw std::runtime_error("Failed to erase column"); throw std::runtime_error("Failed to erase column");
} }
} }
private:
std::size_t bottom_right_row_;
std::size_t bottom_right_col_;
}; };
@ -1164,6 +1177,23 @@ public:
return table_column(col_idx, *this); return table_column(col_idx, *this);
} }
/**
* Get range of cells.
*
* @param col_idx
* Column index.
* @return
* table_column object.
*/
class cell_range
range(std::size_t top_left_row, std::size_t top_left_col,
std::size_t bottom_right_row, std::size_t bottom_right_col)
{
return cell_range(top_left_row, top_left_col,
bottom_right_row, bottom_right_col,
*this);
}
static class default_properties static class default_properties
default_props() default_props()
{ {

View File

@ -1023,7 +1023,11 @@ public:
}; };
/** /**
* Table column. * Range of cells.
*
* @note: at the moment function of propery owener will work only on the
* top left cell.
* @todo: Implement their work on the whole range.
*/ */
class cell_range: public property_owner_t class cell_range: public property_owner_t
{ {
@ -1031,17 +1035,26 @@ public:
using property_owner_t::ps_row_idx_; using property_owner_t::ps_row_idx_;
using property_owner_t::ps_table_; using property_owner_t::ps_table_;
public: public:
table_column(std::size_t col_idx, table &tbl) cell_range(size_t top_left_row, size_t top_left_col,
: property_owner_t(FT_ANY_ROW, col_idx, &tbl) {} size_t bottom_right_row, size_t bottom_right_col,
table &tbl)
: property_owner_t(top_left_row, top_left_col, &tbl),
bottom_right_row_(bottom_right_row),
bottom_right_col_(bottom_right_col)
{}
void erase() void erase()
{ {
if (FT_IS_ERROR(ft_erase_range(ps_table_->table_, if (FT_IS_ERROR(ft_erase_range(ps_table_->table_,
0, ps_coll_idx_, ps_row_idx_, ps_coll_idx_,
(UINT_MAX - 2), ps_coll_idx_))) { bottom_right_row_, bottom_right_col_))) {
throw std::runtime_error("Failed to erase column"); throw std::runtime_error("Failed to erase column");
} }
} }
private:
std::size_t bottom_right_row_;
std::size_t bottom_right_col_;
}; };
@ -1164,6 +1177,23 @@ public:
return table_column(col_idx, *this); return table_column(col_idx, *this);
} }
/**
* Get range of cells.
*
* @param col_idx
* Column index.
* @return
* table_column object.
*/
class cell_range
range(std::size_t top_left_row, std::size_t top_left_col,
std::size_t bottom_right_row, std::size_t bottom_right_col)
{
return cell_range(top_left_row, top_left_col,
bottom_right_row, bottom_right_col,
*this);
}
static class default_properties static class default_properties
default_props() default_props()
{ {

View File

@ -1825,7 +1825,7 @@ static struct ft_table *create_test_table()
void test_table_erase(void) void test_table_erase(void)
{ {
WHEN("Test invalid arguments") { WHEN("Invalid arguments") {
ft_table_t *table = create_test_table(); ft_table_t *table = create_test_table();
// invalid rows // invalid rows

View File

@ -401,6 +401,31 @@ static fort::char_table create_test_table()
void test_cpp_table_erase(void) void test_cpp_table_erase(void)
{ {
WHEN("Invalid arguments") {
std::string err_msg;
try {
fort::char_table table = create_test_table();
table.range(1, 1, 0, 0).erase();
} catch (std::exception &e) {
err_msg = e.what();
}
assert_string_equal(err_msg, std::string("Failed to erase column"));
}
WHEN("Erase one cell") {
fort::char_table table = create_test_table();
table.range(1, 1, 1, 1).erase();
std::string table_str = table.to_string();
std::string table_str_etalon =
"+----+----+----+\n"
"| 00 | 01 | 02 |\n"
"| 10 | 12 | |\n"
"| 20 | 21 | 22 |\n"
"+----+----+----+\n";
assert_string_equal(table_str, table_str_etalon);
}
WHEN("Erase row") { WHEN("Erase row") {
fort::char_table table = create_test_table(); fort::char_table table = create_test_table();
table[1].erase(); table[1].erase();
@ -414,51 +439,44 @@ void test_cpp_table_erase(void)
assert_string_equal(table_str, table_str_etalon); assert_string_equal(table_str, table_str_etalon);
} }
// WHEN("Erase last row") { WHEN("Erase last row") {
// ft_table_t *table = create_test_table(); fort::char_table table = create_test_table();
// assert_true(FT_IS_SUCCESS(ft_erase_range(table, 2, 0, 2, 999))); table[2].erase();
// const char *table_str = ft_to_string(table); std::string table_str = table.to_string();
// assert_true(table_str != NULL); std::string table_str_etalon =
// const char *table_str_etalon = "+----+----+----+\n"
// "+----+----+----+\n" "| 00 | 01 | 02 |\n"
// "| 00 | 01 | 02 |\n" "| 10 | 11 | 12 |\n"
// "| 10 | 11 | 12 |\n" "+----+----+----+\n";
// "+----+----+----+\n"; assert_string_equal(table_str, table_str_etalon);
// assert_str_equal(table_str, table_str_etalon); }
// ft_destroy_table(table);
// }
// WHEN("Erase column") { WHEN("Erase column") {
// ft_table_t *table = create_test_table(); fort::char_table table = create_test_table();
// assert_true(FT_IS_SUCCESS(ft_erase_range(table, 0, 1, 999, 1))); table.column(1).erase();
// const char *table_str = ft_to_string(table); std::string table_str = table.to_string();
// assert_true(table_str != NULL); std::string table_str_etalon =
// const char *table_str_etalon = "+----+----+\n"
// "+----+----+\n" "| 00 | 02 |\n"
// "| 00 | 02 |\n" "| 10 | 12 |\n"
// "| 10 | 12 |\n" "| 20 | 22 |\n"
// "| 20 | 22 |\n" "+----+----+\n";
// "+----+----+\n"; assert_string_equal(table_str, table_str_etalon);
// assert_str_equal(table_str, table_str_etalon); }
// ft_destroy_table(table);
// }
// WHEN("Erase last column") { WHEN("Erase last column") {
// ft_table_t *table = create_test_table(); fort::char_table table = create_test_table();
// assert_true(FT_IS_SUCCESS(ft_erase_range(table, 0, 2, 999, 2))); table.column(2).erase();
// const char *table_str = ft_to_string(table);
// assert_true(table_str != NULL);
// const char *table_str_etalon =
// "+----+----+\n"
// "| 00 | 01 |\n"
// "| 10 | 11 |\n"
// "| 20 | 21 |\n"
// "+----+----+\n";
// assert_str_equal(table_str, table_str_etalon);
// ft_destroy_table(table);
// }
std::string table_str = table.to_string();
std::string table_str_etalon =
"+----+----+\n"
"| 00 | 01 |\n"
"| 10 | 11 |\n"
"| 20 | 21 |\n"
"+----+----+\n";
assert_string_equal(table_str, table_str_etalon);
}
} }