-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix print group #126
Fix print group #126
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
#include <new> | ||
#include <algorithm> | ||
#include <iostream> | ||
#include <iomanip> | ||
#include <fstream> | ||
|
||
#include <tightdb/terminate.hpp> | ||
|
@@ -389,7 +390,7 @@ size_t Group::commit(size_t current_version, size_t readlock_version, bool persi | |
TIGHTDB_ASSERT(readlock_version <= current_version); | ||
|
||
// FIXME: Under what circumstances can this even happen???? | ||
// FIXME: What about when a user owned read-only buffer is attached? | ||
// FIXME: What about when a user owned read-only buffer is attached? | ||
if (!m_alloc.is_attached()) throw runtime_error("Cannot persist"); | ||
|
||
// If we have an empty db file, we can just serialize directly | ||
|
@@ -535,39 +536,34 @@ bool Group::operator==(const Group& g) const | |
void Group::to_string(ostream& out) const | ||
{ | ||
// Calculate widths | ||
size_t name_width = 6; | ||
size_t rows_width = 4; | ||
size_t index_width = 4; | ||
size_t name_width = 10; | ||
size_t rows_width = 6; | ||
size_t count = size(); | ||
for (size_t i = 0; i < count; ++i) { | ||
StringData name = get_table_name(i); | ||
if (name_width < name.size()) name_width = name.size(); | ||
|
||
ConstTableRef table = get_table(name); | ||
size_t row_count = table->size(); | ||
if (rows_width < row_count) rows_width = row_count; | ||
if (rows_width < row_count) rows_width = row_count; // FIXME: should be the number of digits in row_count: floor(log10(row_count+1)) | ||
} | ||
|
||
|
||
// Print header | ||
out << " "; | ||
out.width(name_width); | ||
out << "tables" << " "; | ||
out.width(rows_width); | ||
out << "rows\n"; | ||
out << std::setw(index_width+1) << std::left << " "; | ||
out << std::setw(name_width+1) << std::left << "tables"; | ||
out << std::setw(rows_width) << std::left << "rows" << endl; | ||
|
||
// Print tables | ||
for (size_t i = 0; i < count; ++i) { | ||
StringData name = get_table_name(i); | ||
ConstTableRef table = get_table(name); | ||
size_t row_count = table->size(); | ||
|
||
out << i << " "; | ||
out.width(name_width); | ||
out.setf(ostream::left, ostream::adjustfield); | ||
out << name; | ||
out << " "; | ||
out.width(rows_width); | ||
out.unsetf(ostream::adjustfield); | ||
out << row_count << endl; | ||
out << std::setw(index_width) << std::right << i << " "; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Superfluous "std::". |
||
out << std::setw(name_width) << std::left << name.data() << " "; | ||
out << std::setw(rows_width) << std::left << row_count << endl; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -888,6 +888,21 @@ TEST(Group_toJSON) | |
CHECK(str.length() > 0); | ||
} | ||
|
||
TEST(Group_toString) | ||
{ | ||
Group g; | ||
TestTableGroup::Ref table = g.get_table<TestTableGroup>("test"); | ||
|
||
table->add("jeff", 1, true, Wed); | ||
table->add("jim", 1, true, Wed); | ||
std::ostringstream ss; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Superfluous "std::". |
||
ss.sync_with_stdio(false); // for performance | ||
g.to_string(ss); | ||
const std::string str = ss.str(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Superfluous "std::". |
||
CHECK(str.length() > 0); | ||
CHECK_EQUAL(" tables rows \n 0 test 2 \n", str.c_str()); | ||
} | ||
|
||
TEST(Group_Index_String) | ||
{ | ||
Group toMem; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know I have advocated a lot for "std::" lately, but here they are really superfluous due to the "using namespace std" at the beginning of the file. As a general rule, I suggest we only use "std::" in header files.