Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

### Enhancements

* None.
* Added `Tabe::get_link_type()` as a helper method for getting the link type from link columns.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sp: Tabe->Table
A nice to have is also to include: PR [#2987](https://github.com/realm/realm-core/pull/2987).


-----------

Expand Down
Empty file.
2 changes: 2 additions & 0 deletions src/realm/data_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef REALM_DATA_TYPE_HPP
#define REALM_DATA_TYPE_HPP

#include <cstdint>

namespace realm {

class StringData;
Expand Down
12 changes: 12 additions & 0 deletions src/realm/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1841,6 +1841,18 @@ bool Table::is_nullable(size_t col_ndx) const
m_spec->get_column_type(col_ndx) == col_type_Link;
}

LinkType Table::get_link_type(size_t col_ndx) const
{
if (!is_attached()) {
throw LogicError{LogicError::detached_accessor};
}
if (!(m_spec->get_column_type(col_ndx) == col_type_Link) && !(m_spec->get_column_type(col_ndx) == col_type_LinkList)) {
throw LogicError{LogicError::illegal_type};
}
REALM_ASSERT_DEBUG(col_ndx < m_spec->get_column_count());
return (m_spec->get_column_attr(col_ndx) & col_attr_StrongLinks) ? LinkType::link_Strong : LinkType::link_Weak;
}

const ColumnBase& Table::get_column_base(size_t ndx) const noexcept
{
REALM_ASSERT_DEBUG(ndx < m_spec->get_column_count());
Expand Down
4 changes: 4 additions & 0 deletions src/realm/table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ class Table {
// Whether or not elements can be null.
bool is_nullable(size_t col_ndx) const;

// Returns the link type for the given column.
// Throws an LogicError if target column is not a link column.
LinkType get_link_type(size_t col_ndx) const;

//@{
/// Conventience functions for inspecting the dynamic table type.
///
Expand Down
22 changes: 22 additions & 0 deletions test/test_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8363,4 +8363,26 @@ TEST(Table_KeyRow)
CHECK_EQUAL(i, 1);
}

TEST(Table_getLinkType)
{
Group g;
TableRef table = g.add_table("table");

table->add_column(type_Int, "int");
table->add_column_link(type_Link, "weak_link", *table);
table->add_column_link(type_Link, "strong_link", *table, link_Strong);
table->add_column_link(type_LinkList, "weak_list", *table);
table->add_column_link(type_LinkList, "strong_list", *table, link_Strong);

CHECK(link_Weak == table->get_link_type(1));
CHECK(link_Strong == table->get_link_type(2));
CHECK(link_Weak == table->get_link_type(3));
CHECK(link_Strong == table->get_link_type(4));

CHECK_THROW(table->get_link_type(0), LogicError);

g.remove_table("table");
CHECK_THROW(table->get_link_type(1), LogicError);
}

#endif // TEST_TABLE