From 73829155528e2ebe70cb846664c193118b3936f8 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Fri, 26 Jan 2018 16:26:59 +0100 Subject: [PATCH 1/5] Add Table::get_link_type() --- cmake-build-debug/test/fuzzy/testcases/test0 | 1 + src/realm/table.cpp | 12 +++++++++++ src/realm/table.hpp | 4 ++++ test/test_table.cpp | 22 ++++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 cmake-build-debug/test/fuzzy/testcases/test0 diff --git a/cmake-build-debug/test/fuzzy/testcases/test0 b/cmake-build-debug/test/fuzzy/testcases/test0 new file mode 100644 index 00000000000..039727ec5a5 --- /dev/null +++ b/cmake-build-debug/test/fuzzy/testcases/test0 @@ -0,0 +1 @@ +lol diff --git a/src/realm/table.cpp b/src/realm/table.cpp index bd008c8c20c..99d5633af1e 100644 --- a/src/realm/table.cpp +++ b/src/realm/table.cpp @@ -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()); diff --git a/src/realm/table.hpp b/src/realm/table.hpp index 5f92a9db9c4..c85fec1918f 100644 --- a/src/realm/table.hpp +++ b/src/realm/table.hpp @@ -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. /// diff --git a/test/test_table.cpp b/test/test_table.cpp index fe0413b4702..52a95c9bdfa 100644 --- a/test/test_table.cpp +++ b/test/test_table.cpp @@ -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 From 90fb96fdf89a71da5f92872a1257a0d779c57d87 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Fri, 26 Jan 2018 16:37:28 +0100 Subject: [PATCH 2/5] Support accessing LinkType --- src/realm/data_type.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/realm/data_type.hpp b/src/realm/data_type.hpp index 0ba78c8bdc5..081c459992f 100644 --- a/src/realm/data_type.hpp +++ b/src/realm/data_type.hpp @@ -19,6 +19,8 @@ #ifndef REALM_DATA_TYPE_HPP #define REALM_DATA_TYPE_HPP +#include + namespace realm { class StringData; From 857c9036d711be42cc5d904f5b9a6f5a63f96b0a Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Fri, 26 Jan 2018 16:38:45 +0100 Subject: [PATCH 3/5] Add changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8698e8fb7d8..3f1d4410259 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ ### Enhancements -* None. +* Added `Tabe::get_link_type()` as a helper method for getting the link type from link columns. ----------- From 925c67f48a5bbc63b675fbf3cc2dc77bd0d80829 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Fri, 26 Jan 2018 16:45:55 +0100 Subject: [PATCH 4/5] Remove file commited by accident --- cmake-build-debug/test/fuzzy/testcases/test0 | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake-build-debug/test/fuzzy/testcases/test0 b/cmake-build-debug/test/fuzzy/testcases/test0 index 039727ec5a5..e69de29bb2d 100644 --- a/cmake-build-debug/test/fuzzy/testcases/test0 +++ b/cmake-build-debug/test/fuzzy/testcases/test0 @@ -1 +0,0 @@ -lol From f2fe89206143c71606dc4afb1df9e7d64c943c32 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Fri, 26 Jan 2018 21:04:56 +0100 Subject: [PATCH 5/5] PR feedback --- CHANGELOG.md | 2 +- cmake-build-debug/test/fuzzy/testcases/test0 | 0 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 cmake-build-debug/test/fuzzy/testcases/test0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f1d4410259..7e02a59cd4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ ### Enhancements -* Added `Tabe::get_link_type()` as a helper method for getting the link type from link columns. +* Added `Table::get_link_type()` as a helper method for getting the link type from link columns. PR [#2987](https://github.com/realm/realm-core/pull/2987). ----------- diff --git a/cmake-build-debug/test/fuzzy/testcases/test0 b/cmake-build-debug/test/fuzzy/testcases/test0 deleted file mode 100644 index e69de29bb2d..00000000000