19#ifndef CPPREALM_RESULTS_HPP
20#define CPPREALM_RESULTS_HPP
22#include <cpprealm/internal/bridge/mixed.hpp>
23#include <cpprealm/internal/bridge/ 查询.hpp>
24#include <cpprealm/internal/bridge/results.hpp>
25#include <cpprealm/internal/bridge/table.hpp>
26#include <cpprealm/macros.hpp>
27#include <cpprealm/notifications.hpp>
28#include <cpprealm/schema.hpp>
29#include <cpprealm/rbool.hpp>
32 struct mutable_sync_subscription_set;
37 using sort_descriptor =Internal::bridge::sort_descriptor;
41 template <
typename T,
typename Derived,
typename ShouldEnable =
void >
43 template <
typename T,
typename Derived>
46 template <
typename T,
typename Derived>
53 std::vector<uint 64 _t> deletes;
54 std::vector<uint 64 _t> 插入;
55 std::vector<uint 64 _t> 修改;
60 bool collection_root_was_deleted =
false ;
62 [[nodiscard]]
bool empty()
const noException {
63 return deletements.empty() && inserts.empty() && Modifications.empty() &&
64 !collection_root_was_deleted;
69 return m_parent.size();
73 Derived where(
const std::string &query,
const std::vector<realm::mixed>&arguments) {
74 std::vector<internal::bridge::mixed> Mixed_args;
76 Mixed_args.push_back(serialize(a));
78 m_parent.get_table()。查询(查询, std::move(mixed_args))));
81派生 where(std::function<rbool(托管<T>&)>&& fn) {
82 static_assert (
sizeof (managed<T>),
"Must describe schema for T" );
83 auto realm = m_parent.get_realm();
84 auto schema = realm.schema().find(managed<T>::schema.name);
85 auto 群组 = 域.read_group();
86 autotable_ref = group.get_table(schema.table_key());
87 rbool query = rbool(internal::bridge::query(table_ref));
88 auto query_object = Managed<T>::prepare_for_query(realm, &query);
89 auto full_query = fn(query_object).q;
90 return Derived(internal::bridge::results(m_parent.get_realm(), full_query));
96 boolignore_initial_notification =
true )
97 : m_handler(std::move(fn)),
99 m_ignore_changes_in_initial_notification(ignore_initial_notification) {}
104 if (m_ignore_changes_in_initial_notification) {
105 m_ignore_changes_in_initial_notification =
false ;
106 m_handler({collection, {}, {}, {}});
107 }
else if (changes.empty()) {
108 m_handler({collection, {}, {}, {}});
109 }
else if (!changes.collection_root_was_deleted() || !changes.deletions().empty()) {
112 to_vector(changes.deletions()),
113 to_vector(changes.insertions()),
114 to_vector(changes.modifications()),
122 std::function<void(results_change)>
m_handler ;
123 bool m_ignore_changes_in_initial_notification;
125 auto vector = std::vector<uint 64 _t>();
126 for (
auto index:index_set.as_indexes()) {
127 vector.push_back(index);
134 auto r = std::make_shared<internal::bridge::results>(m_parent.get_realm(), m_parent.get_realm().table_for_object_type(
托管<T>:: 模式 .name));
135 域::notification_token token = r->add_notification_callback(std::make_shared<results_callback_wrapper>(std::move(handler),
static_cast< Derived*
> (
this )));
136 token.m_realm = r->get_realm();
142 autofred_realm = m_parent.get_realm().freeze();
147 auto thawed_realm = m_parent.get_realm().thaw();
148 return Derived(internal::bridge::results(thawed_realm, thaw_realm.table_for_object_type(托管<T>:: 模式.name)));
152 return m_parent.get_realm().is_frozen();
155 Derived sort(
const std::string& key_path,
bool ascending) {
156 return Derived(m_parent.sort({{key_path, 升序}}));
159 Derived sort(
const std::vector<sort_descriptor>& sort_descriptors) {
160 return Derived(m_parent.sort(sort_descriptors));
165 template<auto>
Friend struct Linking_objects ;
168 template <
typename T>
169 using Results_is_primitive = std::enable_if_t<!managed<T>::is_object && !std::is_enum_v<T> && !internal::type_info::is_variant_t<T>::value>;
170 template <
typename T>
171 using Results_is_enum = std::enable_if_t<!managed<T>::is_object && std::is_enum_v<T> && !internal::type_info::is_variant_t<T>::value>;
172 template <
typename T>
173 using Results_is_mixed = std::enable_if_t<! 托管<T>::is_object && !std::is_enum_v<T> &&Internal::type_info::is_variant_t<T>::value>;
175 template <
typename T,
typename Derived>
181 T 操作符[](
size_t index) {
182 if (index >= this->m_parent.size())
183 throw std::out_of_range(
"Index out of 范围." );
184 returninternal::bridge::get<T> (this-> m_parent , index);
189 using diff_type = size_t;
190 using value_type = T;
191 using iterator_category = std::input_iterator_tag;
193 bool操作符!=(
const 迭代器 &other)
const {
194 return !(*
this == other);
197 bool 操作符==(
const iterator &other)
const {
198 return (m_parent == other.m_parent) && (m_idx == other.m_idx);
201 value_type Operator*()
noException {
202 return m_parent->operator[](m_idx);
210迭代器 Operator++(
int i) {
215 显式迭代器(
size_t idx, Derived *parent)
216 : m_idx(idx), m_parent(parent) {
224 return iterator( 0 ,
static_cast< Derived*
> (
this ));
228 return iterator(this->m_parent.size(),
static_cast< Derived*
> (
this ));
232 template <
typename T,
typename Derived>
238 T 操作符[](
size_t index) {
239 if (index >= this->m_parent.size())
240 throw std::out_of_range(
"Index out of 范围." );
241 return deserialize<T>(internal::bridge::get<internal::bridge::mixed>(this->m_parent, index));
252 using diff_type = size_t;
253 using value_type = T;
254 using iterator_category = std::input_iterator_tag;
256 bool操作符!=(
const 迭代器 &other)
const {
257 return !(*
this == other);
260 bool 操作符==(
const iterator &other)
const {
261 return (m_parent == other.m_parent) && (m_idx == other.m_idx);
264 value_type Operator*()
noException {
265 return m_parent->operator[](m_idx);
273迭代器 Operator++(
int i) {
278 显式迭代器(
size_t idx, Derived *parent)
279 : m_idx(idx), m_parent(parent) {
287 return iterator( 0 ,
static_cast< Derived*
> (
this ));
291 return iterator(this->m_parent.size(),
static_cast< Derived*
> (
this ));
295 template <
typename T,
typename Derived>
301 T 操作符[](
size_t index) {
302 if (index >= this->m_parent.size())
303 throw std::out_of_range(
"Index out of 范围." );
304 return static_cast< T
> (internal::bridge::get<int 64 _t>(this->m_parent, index));
309 using diff_type = size_t;
310 using value_type = T;
311 using iterator_category = std::input_iterator_tag;
313 bool操作符!=(
const 迭代器 &other)
const {
314 return !(*
this == other);
317 bool 操作符==(
const iterator &other)
const {
318 return (m_parent == other.m_parent) && (m_idx == other.m_idx);
321 value_type Operator*()
noException {
322 return m_parent->operator[](m_idx);
330迭代器 Operator++(
int i) {
335 显式迭代器(
size_t idx, Derived *parent)
336 : m_idx(idx), m_parent(parent) {
344 return iterator( 0 ,
static_cast< Derived*
> (
this ));
348 return iterator(this->m_parent.size(),
static_cast< Derived*
> (
this ));
352 template <
typename T,
typename Derived>
359 if (index >= this->m_parent.size())
360 throw std::out_of_range(
"Index out of 范围." );
361 return managed<T, void> (internal::bridge::get<internal::bridge::obj>(this->m_parent, index), this->m_parent.get_realm());
366 using diff_type = size_t;
368 using iterator_category = std::input_iterator_tag;
370 bool操作符!=(
const 迭代器 &other)
const {
371 return !(*
this == other);
374 bool 操作符==(
const iterator &other)
const {
375 return (m_parent == other.m_parent) && (m_idx == other.m_idx);
379 内部::bridge::obj obj =内部::bridge::get<internal::bridge::obj>(m_parent->m_parent, m_idx);
380 return managed<T, void> (std::move(obj), this->m_parent->m_parent.get_realm());
388迭代器 Operator++(
int i) {
393 显式迭代器(
size_t idx, Derived *parent)
394 : m_idx(idx), m_parent(parent) {
402 return iterator( 0 ,
static_cast< Derived*
> (
this ));
406 return iterator(this->m_parent.size(),
static_cast< Derived*
> (
this ));
410 template <
typename T>
412 using value_type = T;
420 静态 内联 auto Ptr = ptr;
第 435 章 return iterator( 0 , get_results());
第 439 章 auto r = get_results();
440 return iterator(r.size(), r);
第 444 章 return get_results().size();
447 return get_results()[idx];
第 452 章 auto table = m_obj->get_table();
453 if (!table.is_valid(m_obj->get_key())) {
第 454 章 throw std::logic_error(
"对象已被删除或失效。" );
第 459 章 auto linking_property = schema.property_for_name(
managed<Class>::schema .
template name_for_property<ptr>());
460 if (!linking_property.column_key()) {
第 461 章 throw std::logic_error(
"原始属性的列键无效。" );
第 464 章 inside::bridge::results 结果(*m_realm, obj->get_backlink_view(m_realm->get_table(schema.table_key()), Linking_property.column_key()));
465 return::realm::results<Class>(std::move(
结果));