1 ////////////////////////////////////////////////////////////////////////////
3 // Copyright 2017 Realm Inc.
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 ////////////////////////////////////////////////////////////////////////////
19 #include "impl/object_notifier.hpp"
21 #include "shared_realm.hpp"
23 using namespace realm;
24 using namespace realm::_impl;
26 ObjectNotifier::ObjectNotifier(Row const& row, std::shared_ptr<Realm> realm)
27 : CollectionNotifier(std::move(realm))
29 REALM_ASSERT(row.get_table());
30 set_table(*row.get_table());
32 m_handover = source_shared_group().export_for_handover(row);
35 void ObjectNotifier::release_data() noexcept
40 void ObjectNotifier::do_attach_to(SharedGroup& sg)
42 REALM_ASSERT(m_handover);
44 m_row = sg.import_from_handover(std::move(m_handover));
47 void ObjectNotifier::do_detach_from(SharedGroup& sg)
49 REALM_ASSERT(!m_handover);
51 m_handover = sg.export_for_handover(*m_row);
56 bool ObjectNotifier::do_add_required_change_info(TransactionChangeInfo& info)
58 REALM_ASSERT(!m_handover);
60 if (m_row && m_row->is_attached()) {
61 size_t table_ndx = m_row->get_table()->get_index_in_group();
62 if (table_ndx >= info.table_modifications_needed.size())
63 info.table_modifications_needed.resize(table_ndx + 1);
64 info.table_modifications_needed[table_ndx] = true;
69 void ObjectNotifier::run()
73 if (!m_row->is_attached()) {
74 m_change.deletions.add(0);
79 size_t table_ndx = m_row->get_table()->get_index_in_group();
80 if (table_ndx >= m_info->tables.size())
82 auto& change = m_info->tables[table_ndx];
83 if (!change.modifications.contains(m_row->get_index()))
85 m_change.modifications.add(0);
86 m_change.columns.reserve(change.columns.size());
87 for (auto& col : change.columns) {
88 m_change.columns.emplace_back();
89 if (col.contains(m_row->get_index()))
90 m_change.columns.back().add(0);
94 void ObjectNotifier::do_prepare_handover(SharedGroup&)
96 add_changes(std::move(m_change));