merge latest from master

This commit is contained in:
Ari Lazier 2016-01-13 12:46:07 -08:00
commit 0147ea7880
4 changed files with 26 additions and 2 deletions

View File

@ -60,6 +60,11 @@ void List::remove(std::size_t row_ndx) {
m_link_view->remove(row_ndx);
}
Query List::get_query() {
verify_attached();
return m_link_view->get_target_table().where(m_link_view);
}
void List::verify_valid_row(std::size_t row_ndx, bool insertion) {
size_t size = m_link_view->size();
if (row_ndx > size || (!insertion && row_ndx == size)) {

View File

@ -47,6 +47,8 @@ namespace realm {
template<typename ValueType, typename ContextType>
void set(ContextType ctx, ValueType value, size_t list_ndx);
Query get_query();
void verify_valid_row(std::size_t row_ndx, bool insertion = false);
void verify_attached();
void verify_in_tranaction();

View File

@ -67,6 +67,17 @@ void Results::validate_write() const
throw InvalidTransactionException("Must be in a write transaction");
}
void Results::set_live(bool live)
{
if (!live && m_mode == Mode::Table) {
m_query = m_table->where();
m_mode = Mode::Query;
}
update_tableview();
m_live = live;
}
size_t Results::size()
{
validate_read();
@ -94,7 +105,7 @@ RowExpr Results::get(size_t row_ndx)
case Mode::TableView:
update_tableview();
if (row_ndx < m_table_view.size())
return m_table_view.get(row_ndx);
return (!m_live && !m_table_view.is_row_attached(row_ndx)) ? RowExpr() : m_table_view.get(row_ndx);
break;
}
@ -148,7 +159,9 @@ void Results::update_tableview()
m_mode = Mode::TableView;
break;
case Mode::TableView:
m_table_view.sync_if_needed();
if (m_live) {
m_table_view.sync_if_needed();
}
break;
}
}

View File

@ -74,6 +74,9 @@ public:
// Get the object type which will be returned by get()
StringData get_object_type() const noexcept { return get_object_schema().name; }
// Set whether the TableView should sync if needed before accessing results
void set_live(bool live);
// Get the size of this results
// Can be either O(1) or O(N) depending on the state of things
size_t size();
@ -168,6 +171,7 @@ private:
TableView m_table_view;
Table* m_table = nullptr;
SortOrder m_sort;
bool m_live = true;
Mode m_mode = Mode::Empty;