From e1e9cd8cd706b78ffdc8118c6b4b2cbde60cb22b Mon Sep 17 00:00:00 2001 From: JP Simard Date: Sun, 13 Sep 2015 15:11:54 +0200 Subject: [PATCH] Add ObjectStore::is_empty() --- object_store.cpp | 14 +++++++++++++- object_store.hpp | 5 ++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/object_store.cpp b/object_store.cpp index ba7a868b..d4ef716c 100644 --- a/object_store.cpp +++ b/object_store.cpp @@ -501,7 +501,19 @@ void ObjectStore::delete_data_for_object(Group *group, const StringData &object_ } } - +bool ObjectStore::is_empty(const Group *group) { + for (size_t i = 0; i < group->size(); i++) { + ConstTableRef table = group->get_table(i); + std::string object_type = object_type_for_table_name(table->get_name()); + if (!object_type.length()) { + continue; + } + if (!table->is_empty()) { + return false; + } + } + return true; +} InvalidSchemaVersionException::InvalidSchemaVersionException(uint64_t old_version, uint64_t new_version) : m_old_version(old_version), m_new_version(new_version) diff --git a/object_store.hpp b/object_store.hpp index f38524f8..3da680fb 100644 --- a/object_store.hpp +++ b/object_store.hpp @@ -70,7 +70,10 @@ namespace realm { // deletes the table for the given type static void delete_data_for_object(Group *group, const StringData &object_type); - private: + // indicates if this group contains any objects + static bool is_empty(const Group *group); + + private: // set a new schema version static void set_schema_version(Group *group, uint64_t version);