[A] Added basic operators
This commit is contained in:
parent
c0536323d0
commit
927f33f1b8
44
lib/fort.hpp
44
lib/fort.hpp
@ -105,6 +105,50 @@ public:
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not implemented yet.
|
||||
*/
|
||||
Table(const Table& tbl) = delete;
|
||||
|
||||
/**
|
||||
* Move contstructor.
|
||||
*/
|
||||
Table(Table&& tbl)
|
||||
:table(tbl.table)
|
||||
{
|
||||
if (tbl.stream.tellp() >= 0) {
|
||||
stream << tbl.stream.str();
|
||||
tbl.stream.str(std::string());
|
||||
}
|
||||
tbl.table = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not implemented yet.
|
||||
*/
|
||||
Table& operator=(const Table& tbl) = delete;
|
||||
|
||||
/**
|
||||
* Move assignment operator.
|
||||
*/
|
||||
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());
|
||||
}
|
||||
ft_destroy_table(table);
|
||||
table = tbl.table;
|
||||
tbl.table = NULL;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert table to string representation.
|
||||
*
|
||||
|
@ -34,7 +34,7 @@ bool set_test_options_for_table(fort::Table *table)
|
||||
|
||||
void test_cpp_table_basic(void)
|
||||
{
|
||||
WHEN("All columns are equal and not empty") {
|
||||
WHEN("All columns are equal and not empty.") {
|
||||
fort::Table table;
|
||||
assert_true(set_test_options_for_table(&table));
|
||||
|
||||
@ -61,6 +61,37 @@ void test_cpp_table_basic(void)
|
||||
assert_string_equal(table_str, table_str_etalon);
|
||||
}
|
||||
|
||||
WHEN("Checking basic constructors and assignmets.") {
|
||||
fort::Table table;
|
||||
assert_true(set_test_options_for_table(&table));
|
||||
|
||||
table << fort::header
|
||||
<< "3" << "c" << "234" << "3.140000" << fort::endr
|
||||
<< "3" << "c" << "234" << "3.140000" << fort::endr
|
||||
<< "3" << "c" << "234" << "3.140000" << fort::endr;
|
||||
|
||||
fort::Table table2(std::move(table));
|
||||
fort::Table table3;
|
||||
table3 = std::move(table2);
|
||||
|
||||
std::string table_str = table3.to_string();
|
||||
std::string table_str_etalon =
|
||||
"+---+---+-----+----------+\n"
|
||||
"| | | | |\n"
|
||||
"| 3 | c | 234 | 3.140000 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+-----+----------+\n"
|
||||
"| | | | |\n"
|
||||
"| 3 | c | 234 | 3.140000 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+-----+----------+\n"
|
||||
"| | | | |\n"
|
||||
"| 3 | c | 234 | 3.140000 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+-----+----------+\n";
|
||||
assert_string_equal(table_str, table_str_etalon);
|
||||
}
|
||||
|
||||
WHEN("All columns are not equal and not empty") {
|
||||
fort::Table table;
|
||||
assert_true(set_test_options_for_table(&table));
|
||||
|
Loading…
Reference in New Issue
Block a user