diff --git a/list.hpp b/list.hpp index ef84846a..e7c6465c 100644 --- a/list.hpp +++ b/list.hpp @@ -25,9 +25,9 @@ namespace realm { class List { public: - List(SharedRealm &r, const ObjectSchema &s, LinkViewRef l) : m_realm(r), object_schema(s), m_link_view(l) {} + List(SharedRealm &r, const ObjectSchema &s, LinkViewRef l) : m_realm(r), m_object_schema(&s), m_link_view(l) {} - const ObjectSchema &object_schema; + const ObjectSchema &object_schema() const { return *m_object_schema; } SharedRealm realm() { return m_realm; } size_t size(); @@ -53,6 +53,7 @@ namespace realm { private: SharedRealm m_realm; + const ObjectSchema *m_object_schema; LinkViewRef m_link_view; }; } diff --git a/object_accessor.hpp b/object_accessor.hpp index ae1025f0..eed939e1 100644 --- a/object_accessor.hpp +++ b/object_accessor.hpp @@ -308,19 +308,19 @@ namespace realm { template void List::add(ContextType ctx, ValueType value) { - add(NativeAccessor::to_object_index(ctx, m_realm, value, object_schema.name, false)); + add(NativeAccessor::to_object_index(ctx, m_realm, value, object_schema().name, false)); } template void List::insert(ContextType ctx, ValueType value, size_t list_ndx) { - insert(list_ndx, NativeAccessor::to_object_index(ctx, m_realm, value, object_schema.name, false)); + insert(list_ndx, NativeAccessor::to_object_index(ctx, m_realm, value, object_schema().name, false)); } template void List::set(ContextType ctx, ValueType value, size_t list_ndx) { - set(list_ndx, NativeAccessor::to_object_index(ctx, m_realm, value, object_schema.name, false)); + set(list_ndx, NativeAccessor::to_object_index(ctx, m_realm, value, object_schema().name, false)); } } diff --git a/results.cpp b/results.cpp index 32b00dda..e8d4bfd2 100644 --- a/results.cpp +++ b/results.cpp @@ -40,7 +40,7 @@ Results::Results(SharedRealm r, const ObjectSchema &o, Query q, SortOrder s) , m_table(m_query.get_table().get()) , m_sort(std::move(s)) , m_mode(Mode::Query) -, object_schema(o) +, m_object_schema(&o) { } @@ -48,21 +48,10 @@ Results::Results(SharedRealm r, const ObjectSchema &o, Table& table) : m_realm(std::move(r)) , m_table(&table) , m_mode(Mode::Table) -, object_schema(o) +, m_object_schema(&o) { } -Results& Results::operator=(Results const& r) -{ - m_realm = r.m_realm; - m_table = r.m_table; - m_sort = r.m_sort; - m_query = r.get_query(); - m_mode = Mode::Query; - const_cast(object_schema) = r.object_schema; - return *this; -} - void Results::validate_read() const { if (m_realm) @@ -171,7 +160,7 @@ size_t Results::index_of(Row const& row) throw DetatchedAccessorException{}; } if (m_table && row.get_table() != m_table) { - throw IncorrectTableException(object_schema.name, + throw IncorrectTableException(m_object_schema->name, ObjectStore::object_type_for_table_name(row.get_table()->get_name()), "Attempting to get the index of a Row of the wrong type" ); @@ -326,12 +315,12 @@ TableView Results::get_tableview() Results Results::sort(realm::SortOrder&& sort) const { - return Results(m_realm, object_schema, get_query(), std::move(sort)); + return Results(m_realm, object_schema(), get_query(), std::move(sort)); } Results Results::filter(Query&& q) const { - return Results(m_realm, object_schema, get_query().and_query(std::move(q)), get_sort()); + return Results(m_realm, object_schema(), get_query().and_query(std::move(q)), get_sort()); } Results::UnsupportedColumnTypeException::UnsupportedColumnTypeException(size_t column, const Table* table) diff --git a/results.hpp b/results.hpp index 9866cae8..42dbda8f 100644 --- a/results.hpp +++ b/results.hpp @@ -53,13 +53,13 @@ public: Results(Results const&) = default; Results(Results&&) = default; Results& operator=(Results&&) = default; - Results& operator=(Results const&); + Results& operator=(Results const&) = default; // Get the Realm SharedRealm get_realm() const { return m_realm; } // Object schema describing the vendored object type - const ObjectSchema &object_schema; + const ObjectSchema &object_schema() const { return *m_object_schema; } // Get a query which will match the same rows as is contained in this Results // Returned query will not be valid if the current mode is Empty @@ -72,7 +72,7 @@ public: TableView get_tableview(); // Get the object type which will be returned by get() - StringData get_object_type() const noexcept { return object_schema.name; } + StringData get_object_type() const noexcept { return object_schema().name; } // Get the size of this results // Can be either O(1) or O(N) depending on the state of things @@ -163,6 +163,7 @@ public: private: SharedRealm m_realm; + const ObjectSchema *m_object_schema; Query m_query; TableView m_table_view; Table* m_table = nullptr;