19#ifndef CPPREALM_OBSERVATION_HPP
20#define CPPREALM_OBSERVATION_HPP
22#include <cpprealm/internal/bridge/list.hpp>
23#include <cpprealm/internal/bridge/obj.hpp>
24#include <cpprealm/internal/bridge/ 对象.hpp>
25#include <cpprealm/internal/bridge/realm.hpp>
26#include <cpprealm/macros.hpp>
28#include <cpprealm/internal/bridge/table.hpp>
29#include <cpprealm/internal/bridge/thread_safe_reference.hpp>
36 template <
typename T>
57 template <
typename T>
61 std::shared_ptr<internal::bridge::object> 内部对象)
62 : block(std::move(b)),
object (*obj), m_object(internal_object) {
63 static_cast<void> (obj);
67 std::shared_ptr<internal::bridge::object> m_object;
69 std::Optional<std::vector<std::string>> property_names = std::nullopt;
70 std::Optional<std::vector<
typename decltype (T::schema)::variant_t>> old_values = std::nullopt;
71 bool Deleted =
false ;
77 if (!c.deletions().empty()) {
81 if (c.columns().empty()) {
85 auto properties = std::vector<std::string>();
86 auto tab = m_object->get_obj().get_table();
88 for (
auto i = 0 ; i < std::tuple_size<
decltype (T:: 模式.properties)>{}; i++) {
89 if (c.columns().count(table.get_column_key(T::schema.names[i]).value())) {
90 properties.push_back(T::schema.names[i]);
94 if (!properties.empty()) {
95 property_names = properties;
99 std::Optional<std::vector<
typename decltype (T:: 模式)::variant_t>>
104 populate_properties(c);
105 if (!property_names) {
109 std::vector<
typename decltype (T::schema)::variant_t> values;
110 for (
auto &name: *property_names) {
111 auto value = T::schema.property_value_for_name(name,
object ,
true );
112 values.push_back(value);
118 old_values = read_values(c);
122 auto new_values = read_values(c);
124 forward_change(
nullptr , {}, {}, {},
nullptr );
125 }
else if (new_values) {
126 forward_change(&
对象 ,
128 old_values ? *old_values : std::vector<
typename decltype (T::schema)::variant_t>{},
132 property_names = std::nullopt;
133 old_values = std::nullopt;
136 void error(std::Exception_ptr err) {
137 forward_change(
nullptr , {}, {}, {}, err);
140 voidforward_change (
const T *ptr,
141 std::vector<std::string> property_names,
142 std::vector<
typename decltype (T:: 模式)::variant_t> old_values,
143 std::vector<
typename decltype (T:: 模式)::variant_t> new_values,
144 const std::Exception_ptr &error) {
152 oc.is_deleted =
true ;
156 std::vector<PropertyChange<T>> property_changes;
157 for (
size_t i = 0 ; i < property_names.size(); i++) {
159 属性。
name = property_names[i];
160 if (!old_values.empty()) {
161 属性.old_value = old_values[i];
163 if (!new_values.empty()) {
164 属性.new_value = new_values[i];
166 property_changes.push_back(std::move(property));
170 oc.property_changes = property_changes;
177 std::vector<uint 64 _t> deletes;
178 std::vector<uint 64 _t> 插入;
179 std::vector<uint 64 _t> 修改;
184 bool collection_root_was_deleted =
false ;
186 [[nodiscard]]
bool empty()
const noException {
187 return deletements.empty() && inserts.empty() && Modifications.empty() &&
188 !collection_root_was_deleted;
194 boolignoreChangesInInitialNotification ;
197 boolignoreChangesInInitialNotification )
199 、ignoreChangesInInitialNotification(ignoreChangesInInitialNotification)
205 if (ignoreChangesInInitialNotification) {
206 ignoreChangesInInitialNotification =
false ;
209 else if (changes.empty()) {
213 else if (!changes.collection_root_was_deleted() || !changes.deletions().empty()) {
214 handler({to_vector(changes.deletions()),
215 to_vector(changes.insertions()),
216 to_vector(changes.modifications()),
223 auto vector = std::vector<uint 64 _t>();
224 for (
auto index : index_set.as_indexes()) {
225 vector.push_back(index);
233template <
typename T>
237 stream <<
"\tis_deleted: " <<
object .is_deleted <<
"\n" ;
238 stream <<
"\tchange_to: " <<
object .property.name <<
"\n" ;
240 stream <<
"\told_value: " ;
241 std::visit([&stream](
auto && arg) {
242 using M = std::decay_t<
decltype (arg)>;
243 stream << static_cast<M>(arg);
244 }, *
对象 .属性.old_value);
247 流 <<
"\tnew_value: " ;
248 std::visit([&stream](
auto && arg) {
249 using M = std::decay_t<
decltype (arg)>;
250 stream << static_cast<M>(arg);
251 }, *
object .property.new_value);
定义: notifications.hpp: 80
std::string name
定义: notifications.hpp: 84
bool is_deleted
该对象已从 Realm 中删除。
定义: observation.hpp: 42
std::vector< PropertyChange< T >> property_changes
定义: observation.hpp: 54
const T * 对象
被观察的对象。
定义: observation.hpp: 40
std::exception_ptr error
定义: observation.hpp: 50