Skip to content

Commit

Permalink
Merge pull request #58 from Tightdb/group-get_table_count-rename
Browse files Browse the repository at this point in the history
BREAKING change: Group::get_table_count() rename
  • Loading branch information
bmunkholm committed Feb 25, 2013
2 parents 343f6bf + a325cab commit a550ee1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Format:
==================


2013-02-21 (Brian Munkholm
-+ Renamed Group::get_table_count() to Group::size()

2013-02-19 (Kristian Spangsege)
+ Type of Group::BufferSpec::m_data changed from <char*> to <const char*>.

Expand Down
5 changes: 3 additions & 2 deletions doc/ref_cpp/data/group_ref.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ CATEGORIES:
EXAMPLES:
- DESCR :
CODE : ex_cpp_group_operator_equal

- Table:
METHODS:
- g_group_table_count:
NAMES : get_table_count
- g_group_size:
NAMES : size
DESCR : >
A group can be a container for many tables, and this method counts
the number of tables currently stored in the group.
Expand Down
2 changes: 1 addition & 1 deletion doc/ref_cpp/examples/group_traverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TIGHTDB_TABLE_2(PeopleTable,
void traverse(const Group& group)
{
// @@EndFold@@
for (size_t i=0; i<group.get_table_count(); ++i) {
for (size_t i=0; i<group.size(); ++i) {
const char* table_name = group.get_table_name(i);
ConstTableRef table = group.get_table(table_name);
cout << table_name << " " << table->get_column_count() << "\n";
Expand Down
6 changes: 3 additions & 3 deletions src/tightdb/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ void Group::update_from_shared(size_t top_ref, size_t len)

bool Group::operator==(const Group& g) const
{
const size_t n = get_table_count();
if (n != g.get_table_count()) return false;
const size_t n = size();
if (n != g.size()) return false;
for (size_t i=0; i<n; ++i) {
const Table* t1 = get_table_ptr(i);
const Table* t2 = g.get_table_ptr(i);
Expand All @@ -519,7 +519,7 @@ bool Group::operator==(const Group& g) const

void Group::to_string(std::ostream& out) const
{
const size_t count = get_table_count();
const size_t count = size();

// Calculate widths
size_t name_width = 6;
Expand Down
4 changes: 2 additions & 2 deletions src/tightdb/group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Group: private Table::Parent {

bool is_empty() const TIGHTDB_NOEXCEPT;

size_t get_table_count() const;
size_t size() const;
const char* get_table_name(size_t table_ndx) const;
bool has_table(const char* name) const;

Expand Down Expand Up @@ -368,7 +368,7 @@ inline bool Group::in_initial_state() const
return !m_top.IsValid();
}

inline std::size_t Group::get_table_count() const
inline std::size_t Group::size() const
{
if (!m_top.IsValid()) return 0;
return m_tableNames.size();
Expand Down
16 changes: 16 additions & 0 deletions test/testgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ TIGHTDB_TABLE_4(TestTableGroup,

} // Anonymous namespace

TEST(Group_Size)
{
Group g;

CHECK_EQUAL(true, g.is_empty());

TableRef t = g.get_table("a");
CHECK_EQUAL(false, g.is_empty());
CHECK_EQUAL(1, g.size());

TableRef t1 = g.get_table("b");
CHECK_EQUAL(false, g.is_empty());
CHECK_EQUAL(2, g.size());

}

TEST(Group_GetTable)
{
Group g;
Expand Down

0 comments on commit a550ee1

Please sign in to comment.