diff --git a/src/results.cpp b/src/results.cpp index f2961337..1daa32fc 100644 --- a/src/results.cpp +++ b/src/results.cpp @@ -90,15 +90,23 @@ Results::~Results() } } +bool Results::is_valid() const +{ + if (m_table && !m_table->is_attached()) + return false; + if (m_mode == Mode::TableView && (!m_table_view.is_attached() || m_table_view.depends_on_deleted_object())) + return false; + if (m_mode == Mode::LinkView && !m_link_view->is_attached()) + return false; + + return true; +} + void Results::validate_read() const { if (m_realm) m_realm->verify_thread(); - if (m_table && !m_table->is_attached()) - throw InvalidatedException(); - if (m_mode == Mode::TableView && (!m_table_view.is_attached() || m_table_view.depends_on_deleted_object())) - throw InvalidatedException(); - if (m_mode == Mode::LinkView && !m_link_view->is_attached()) + if (!is_valid()) throw InvalidatedException(); } diff --git a/src/results.hpp b/src/results.hpp index 6b25982a..c8a02f44 100644 --- a/src/results.hpp +++ b/src/results.hpp @@ -193,6 +193,9 @@ public: static void set_table_view(Results& results, TableView&& tv); }; + // Returns if this Results class is still valid + bool is_valid() const; + private: SharedRealm m_realm; const ObjectSchema *m_object_schema;