CaptureHelper(std::string const& path, SharedRealm const& r, LinkViewRef lv) : m_history(make_client_history(path)) , m_sg(*m_history, SharedGroup::durability_MemOnly) , m_realm(r) , m_group(m_sg.begin_read()) , m_linkview(lv) { m_realm->begin_transaction(); m_initial.reserve(lv->size()); for (size_t i = 0; i < lv->size(); ++i) m_initial.push_back(lv->get(i).get_int(0)); }
void validate(CollectionChangeSet const& info) { info.insertions.verify(); info.deletions.verify(); info.modifications.verify(); std::vector<size_t> move_sources; for (auto const& move : info.moves) move_sources.push_back(m_initial[move.from]); // Apply the changes from the transaction log to our copy of the // initial, using UITableView's batching rules (i.e. delete, then // insert, then update) auto it = util::make_reverse_iterator(info.deletions.end()); auto end = util::make_reverse_iterator(info.deletions.begin()); for (; it != end; ++it) { m_initial.erase(m_initial.begin() + it->first, m_initial.begin() + it->second); } for (auto const& range : info.insertions) { for (auto i = range.first; i < range.second; ++i) m_initial.insert(m_initial.begin() + i, m_linkview->get(i).get_int(0)); } for (auto const& range : info.modifications) { for (auto i = range.first; i < range.second; ++i) m_initial[i] = m_linkview->get(i).get_int(0); } REQUIRE(m_linkview->is_attached()); // and make sure we end up with the same end result REQUIRE(m_initial.size() == m_linkview->size()); for (size_t i = 0; i < m_initial.size(); ++i) CHECK(m_initial[i] == m_linkview->get(i).get_int(0)); // Verify that everything marked as a move actually is one for (size_t i = 0; i < move_sources.size(); ++i) { if (!info.modifications.contains(info.moves[i].to)) { CHECK(m_linkview->get(info.moves[i].to).get_int(0) == move_sources[i]); } } }
ListNotifier::ListNotifier(LinkViewRef lv, std::shared_ptr<Realm> realm) : CollectionNotifier(std::move(realm)) , m_prev_size(lv->size()) { // Find the lv's column, since that isn't tracked directly size_t row_ndx = lv->get_origin_row_index(); m_col_ndx = not_found; auto& table = lv->get_origin_table(); for (size_t i = 0, count = table.get_column_count(); i != count; ++i) { if (table.get_column_type(i) == type_LinkList && table.get_linklist(i, row_ndx) == lv) { m_col_ndx = i; break; } } REALM_ASSERT(m_col_ndx != not_found); set_table(lv->get_target_table()); auto& sg = Realm::Internal::get_shared_group(*get_realm()); m_lv_handover = sg.export_linkview_for_handover(lv); }