store ObjectSchema as a pointer rather than a reference
This commit is contained in:
parent
b8d40950a7
commit
c25d08eb34
5
list.hpp
5
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;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -308,19 +308,19 @@ namespace realm {
|
|||
template<typename ValueType, typename ContextType>
|
||||
void List::add(ContextType ctx, ValueType value)
|
||||
{
|
||||
add(NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema.name, false));
|
||||
add(NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema().name, false));
|
||||
}
|
||||
|
||||
template<typename ValueType, typename ContextType>
|
||||
void List::insert(ContextType ctx, ValueType value, size_t list_ndx)
|
||||
{
|
||||
insert(list_ndx, NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema.name, false));
|
||||
insert(list_ndx, NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema().name, false));
|
||||
}
|
||||
|
||||
template<typename ValueType, typename ContextType>
|
||||
void List::set(ContextType ctx, ValueType value, size_t list_ndx)
|
||||
{
|
||||
set(list_ndx, NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema.name, false));
|
||||
set(list_ndx, NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema().name, false));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
21
results.cpp
21
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<ObjectSchema &>(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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue