From 592a35a69ecc34048fa024920c230dd3123292b6 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Mon, 16 May 2016 16:01:14 -0700 Subject: [PATCH] add isValid methods to results and list --- src/results.cpp | 18 +++++++++++++----- src/results.hpp | 3 +++ 2 files changed, 16 insertions(+), 5 deletions(-) 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;