Realm C++ SDK版本 v 2.2.0

managed_dictionary.hpp

1
2//
3// 版权所有 2024 Realm Inc.
4//
5// 根据 Apache 许可证 2.0 版(“许可证”)获得许可;
6// 除非符合合规,否则不得使用此文件。
7// 您可以在以下网址获取许可证副本:
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// 除非适用法律要求或书面同意,否则软件
12// 根据许可证分发是按“原样”分发的,
13// 不提供任何类型的Express或暗示的保证或条件。
14// 请参阅管理权限的特定语言的许可证和
15// 许可证下的限制。
16//
18
19#ifndef CPPREALM_MANAGED_DICTIONARY_HPP
20#define CPPREALM_MANAGED_DICTIONARY_HPP
21
22#include <cpprealm/accessors.hpp>
23#include <cpprealm/macros.hpp>
24#include <cpprealm/notifications.hpp>
25#include <cpprealm/observation.hpp>
26#include <cpprealm/rbool.hpp>
27
28命名空间域 {
29
30 template < typenamemapped_type >
31 struct box_base {
33 const std::string &key,
35 : m_backing_map(std::move(backing_map)), m_key(key), m_realm(r) {}
36
37 Box_base ( rbool * 查询,
38 内部::桥::列键列键,
39 const std::string &key,
40 const Internal::bridge:: 域 &r) {
41 m_rbool_query = 查询;
42 m_col_key = colum_key;
43 m_key = key;
44 m_realm = r;
45 }
46
47 Box_base &operator=( constmapped_type &o) {
48 m_backing_map.insert(m_key, Internal::bridge::Mixed (std::move(o)));
49 return * this ;
50 }
51 box_base &operator=(mapped_type &&o) {
53 if (o) {
54 if constexpr (o->is_managed) {
55 m_backing_map.insert(m_key, o->m_managed.m_obj.get_key());
56 } else {
58 if constexpr ( managed<typename mapped_type::value_type::value_type>:: schema.HasPrimaryKeyProperty) {
60 m_obj = m_backing_map.create_and_insert_linked_object(m_key, pk.value);
61 } else {
62 m_obj = m_backing_map.create_and_insert_linked_object(m_key);
63 }
64
65 std:: 应用([&m_obj, &o]( auto && ...p) {
66 ( accessor < typename std::decay_t< decltype (p)>::Result>::set(
67 m_obj, m_obj.get_table().get_column_key(p.name),
68 (*o->unmanaged).*(std::decay_t< decltype (p)>::ptr)), ...);
70 }
71 } else {
72 m_backing_map.insert(m_key, Internal::bridge::Mixed ());
73 }
74 } else {
75 if constexpr (internal::type_info::is_primitive<mapped_type>::value) {
76 m_backing_map.insert(m_key, 序列化(std::move(o)));
77 } else {
78 if (o.is_managed) {
79 m_backing_map.insert(m_key, o。 托管.m_obj.get_key());
80 } else {
82 if constexpr ( managed<typename mapped_type::value_type>:: schema.HasPrimaryKeyProperty) {
83 auto pk = (*o->unmanaged).*( 托管<typename mapped_type::value_type> :: schema.primary_key ().ptr);
84 m_obj = m_backing_map.create_and_insert_linked_object(m_key, pk.value);
85 } else {
86 m_obj = m_backing_map.create_and_insert_linked_object(m_key);
87 }
88
89 std:: 应用([&m_obj, &o]( auto && ...p) {
90 ( accessor < typename std::decay_t< decltype (p)>::Result>::set(
91 m_obj, m_obj.get_table().get_column_key(p.name),
92 o.unmanaged.*(std::decay_t< decltype (p)>::ptr)), ...);
94 }
95 }
96 }
97 return * this ;
98 }
99
100 rbool 操作符==( constmapped_type &rhs) const{ {
101 if constexpr (域::internal::type_info::MixedPersistableConcept<mapped_type>::value) {
102 if (this->m_rbool_query) {
103 return this->m_rbool_query->dictionary_has_value_for_key_equals(this->m_col_key, m_key,serialize(rhs, m_realm));
104 }
105 return m_backing_map.get(m_key) == Serialize(rhs, m_realm);
106 } else {
107 if (this->m_rbool_query) {
108 return this->m_rbool_query->dictionary_has_value_for_key_equals(this->m_col_key, m_key, internal::bridge::mixed (serialize(rhs)));
109 }
110 return m_backing_map.get(m_key) == inside::bridge::mixed (serialize(rhs));
111 }
112 }
113
114 rbool操作符!=( const mapped_type &rhs) const {
115 if (this->m_rbool_query) {
116 return this->m_rbool_query->dictionary_has_value_for_key_not_equals(this->m_col_key, m_key, internal::bridge::mixed (serialize(rhs, m_realm)));
117 } else {
118 返回!操作符==(rhs);
119 }
120 }
121
122 Internal::bridge::core_dictionary m_backing_map;
123 Internal::bridge:: Realm m_realm;
124 std::string m_key;
126 rbool * m_rbool_query = nullptr ;
127 };
128 template < typename V, typename = void >
129 struct box;
130 template <>
131 struct Box <int64 _t>: publicbox_base < int64 _t> {
132 运用 box_base <int 64 _t>::box_base;
133 运用 box_base <int 64 _t>::operator=;
134 int 64 _t操作符*() {
135 return m_backing_map.get(m_key)。操作符 int 64 _t();
136 }
137
138 rbool 操作符>(int 64 _t rhs) const {
139 if (this->m_rbool_query) {
140 return this->m_rbool_query->dictionary_has_value_for_key_great_than(this->m_col_key, m_key, rhs);
141 }
142 return m_backing_map.get(m_key) > inside::bridge::mixed (rhs);
143 }
144
145 rbool 操作符>=(int 64 _t rhs) const {
146 if (this->m_rbool_query) {
147 return this->m_rbool_query->dictionary_has_value_for_key_great_than_equals(this->m_col_key, m_key, rhs);
148 }
149 return m_backing_map.get(m_key) >= inside::bridge::mixed (rhs);
150 }
151
152 rbool 操作符<(int 64 _t rhs) const {
153 if (this->m_rbool_query) {
154 return this->m_rbool_query->dictionary_has_value_for_key_less_than(this->m_col_key, m_key, rhs);
155 }
156 return m_backing_map.get(m_key) < internal::bridge::mixed (rhs);
157 }
158
159 rbool 操作符<=(int 64 _t rhs) const {
160 if (this->m_rbool_query) {
161 return this->m_rbool_query->dictionary_has_value_for_key_less_than_equals(this->m_col_key, m_key, rhs);
162 }
163 return m_backing_map.get(m_key) <= Internal::Bridge::Mixed (Rhs);
164 }
165 };
166 template <>
167 struct Box<double> : publicbox_base <<double> double > {
168 运用 box_base < double >::box_base;
169 运用 box_base < double >:: 操作符=;
170 double操作符*() {
171 return m_backing_map.get(m_key)。操作符 double();
172 }
173
174 rbool操作符>( double rhs) const {
175 if (this->m_rbool_query) {
176 return this->m_rbool_query->dictionary_has_value_for_key_great_than(this->m_col_key, m_key, rhs);
177 }
178 return m_backing_map.get(m_key) > inside::bridge::mixed (rhs);
179 }
180
181 rbool 操作符>=( double rhs) const {
182 if (this->m_rbool_query) {
183 return this->m_rbool_query->dictionary_has_value_for_key_great_than_equals(this->m_col_key, m_key, rhs);
184 }
185 return m_backing_map.get(m_key) >= inside::bridge::mixed (rhs);
186 }
187
188 rbool 操作符<( double rhs) const {
189 if (this->m_rbool_query) {
190 return this->m_rbool_query->dictionary_has_value_for_key_less_than(this->m_col_key, m_key, rhs);
191 }
192 return m_backing_map.get(m_key) < internal::bridge::mixed (rhs);
193 }
194
195 rbool 操作符<=( double rhs) const {
196 if (this->m_rbool_query) {
197 return this->m_rbool_query->dictionary_has_value_for_key_less_than_equals(this->m_col_key, m_key, rhs);
198 }
199 return m_backing_map.get(m_key) <= Internal::Bridge::Mixed (Rhs);
200 }
201 };
202 template <>
203 struct box:<bool> publicbox_base <<bool> bool> {
204 运用 box_base < bool >::box_base;
205 运用 Box_base < bool >:: 操作符=;
206 bool操作符*() {
207 return m_backing_map.get(m_key)。操作符 bool();
208 }
209 };
210 template < typename V>
211 struct box<V, std::enable_if_t<std::is_enum_v<V>>> : public box_base<V> {
212 运用 box_base <V>::box_base;
213 运用 Box_base <V>:: 操作符=;
214 V 操作符*() {
215 return this->m_backing_map.get(this->m_key)。 操作符 int 64 _t();
216 }
217 };
218
219 template <>
220 struct box<uuid> : public box_base<uuid> {
221 运用 box_base < uuid >::box_base;
222 运用 box_base < uuid >:: 操作符=;
223 uuid Operator*() {
224 return this->m_backing_map.get(this->m_key).operatorinternal ::bridge::uuid ().operator::realm::uuid();
225 }
226 };
227 template < typename Mixed>
228 struct Box <Mixed, std::enable_if_t<internal::type_info:: MixedPersistableConcept::value>><Mixed> : publicbox_base <<Mixed> Mixed> {
229 运用 box_base <Mixed>::box_base;
230 运用 Box_base <Mixed>:: 操作符=;
231
232 rbool操作符>(混合右轴) const {
233 if (this->m_rbool_query) {
234 return this->m_rbool_query->dictionary_has_value_for_key_great_than(this->m_col_key, this->m_key,serialize(rhs, this->m_realm));
235 }
236 return this->m_backing_map.get(this->m_key) >serialize(rhs, this->m_realm);
237 }
238
239 rbool 操作符>=(Mixed rhs) const {
240 if (this->m_rbool_query) {
241 return this->m_rbool_query->dictionary_has_value_for_key_great_than_equals(this->m_col_key, this->m_key,serialize(rhs, this->m_realm));
242 }
243 return this->m_backing_map.get(this->m_key) >=serialize(rhs, this->m_realm);
244 }
245
246 rbool 操作符<(混合右轴) const {
247 if (this->m_rbool_query) {
248 return this->m_rbool_query->dictionary_has_value_for_key_less_than(this->m_col_key, this->m_key,serialize(rhs, this->m_realm));
249 }
250 return this->m_backing_map.get(this->m_key) <serialize(rhs, this->m_realm);
251 }
252
253 rbool 操作符<=(Mixed rhs) const {
254 if (this->m_rbool_query) {
255 return this->m_rbool_query->dictionary_has_value_for_key_less_than_equals(this->m_col_key, this->m_key,serialize(rhs, this->m_realm));
256 }
257 return this->m_backing_map.get(this->m_key) <=将该序列化(rhs, this->m_realm);
258 }
259 };
260 template <>
261 struct box<object_id> : public box_base<object_id> {
262 运用 box_base < object_id >::box_base;
263 运用 Box_base < object_id >:: 操作符=;
264 object_id Operator*() {
265 return this->m_backing_map.get(this->m_key)。操作符内部::bridge::object_id ()。操作符 :: 域::object_id();
266 }
267 };
268 template <>
269 struct Box <十进制128 >:公共box_base <十进制128 > {
270 运用 Box_base <十进制128 >::box_base;
271 运用 Box_base <十进制128 >::operator=;
272 十进制128操作符*() {
273 return this->m_backing_map.get(this->m_key).operator inside ::bridge::decimal 128 ().operator ::realm::decimal 128 ();
274 }
275
276 rbool操作符>(十进制128 rhs) const {
277 if (this->m_rbool_query) {
278 return this->m_rbool_query->dictionary_has_value_for_key_great_than(this->m_col_key, m_key,serialize(rhs));
279 }
280 return m_backing_map.get(m_key) > inside::bridge::mixed (serialize(rhs));
281 }
282
283 rbool 操作符>=(十进制128 rhs) const {
284 if (this->m_rbool_query) {
285 return this->m_rbool_query->dictionary_has_value_for_key_great_than_equals(this->m_col_key, m_key,serialize(rhs));
286 }
287 return m_backing_map.get(m_key) >= inside::bridge::mixed (serialize(rhs));
288 }
289
290 rbool 操作符<(十进制128 rhs) const {
291 if (this->m_rbool_query) {
292 return this->m_rbool_query->dictionary_has_value_for_key_less_than(this->m_col_key, m_key,serialize(rhs));
293 }
294 return m_backing_map.get(m_key) < internal::bridge::mixed (serialize(rhs));
295 }
296
297 rbool 操作符<=(十进制128 rhs) const {
298 if (this->m_rbool_query) {
299 return this->m_rbool_query->dictionary_has_value_for_key_less_than_equals(this->m_col_key, m_key,serialize(rhs));
300 }
301 return m_backing_map.get(m_key) <= inside::bridge::mixed (serialize(rhs));
302 }
303 };
304 template <>
305 struct Box <std::chrono::time_point<std::chrono::system_clock>> : publicbox_base <std:: chrono ::time_point<std::chrono::system_clock>> {
306 运用 box_base<std::chrono::time_point<std::chrono::system_clock>>::box_base;
307 运用 box_base <std::chrono::time_point<std::chrono::system_clock>>::operator=;
308 std::chrono::time_point<std::chrono::system_clock>操作符*() {
309 return this->m_backing_map.get(this->m_key).operatorinternal ::bridge::timestamp ().operator std::chrono::time_point<std::chrono::system_clock>();
第 310
311
312 rbool 操作符>(std::chrono::time_point<std::chrono::system_clock> rhs) const {
313 if (this->m_rbool_query) {
314 return this->m_rbool_query->dictionary_has_value_for_key_great_than(this->m_col_key, m_key,serialize(rhs));
315 }
316 return m_backing_map.get(m_key) > inside::bridge::mixed (rhs);
317 }
318
319 rbool 操作符>=(std::chrono::time_point<std::chrono::system_clock> rhs) const {
320 if (this->m_rbool_query) {
321 return this->m_rbool_query->dictionary_has_value_for_key_great_than_equals(this->m_col_key, m_key,serialize(rhs));
322 }
323 return m_backing_map.get(m_key) >= inside::bridge::mixed (rhs);
324 }
325
326 rbool 操作符<(std::chrono::time_point<std::chrono::system_clock> rhs) const {
327 if (this->m_rbool_query) {
328 return this->m_rbool_query->dictionary_has_value_for_key_less_than(this->m_col_key, m_key,serialize(rhs));
329 }
330 return m_backing_map.get(m_key) < internal::bridge::mixed (rhs);
331 }
332
333 rbool 操作符<=(std::chrono::time_point<std::chrono::system_clock> rhs) const {
334 if (this->m_rbool_query) {
335 return this->m_rbool_query->dictionary_has_value_for_key_less_than_equals(this->m_col_key, m_key,serialize(rhs));
336 }
337 return m_backing_map.get(m_key) <= Internal::Bridge::Mixed (Rhs);
338 }
339 };
340 template <>
341 struct Box <std::vector<uint 8 _t>> : publicbox_base <std:: vector <uint 8 _t>> {
342 运用 box_base <std::vector<uint 8 _t>>::box_base;
343 运用 box_base <std::vector<uint 8 _t>>::operator=;
344 std::vector<uint 8 _t>操作符*() {
345 return this->m_backing_map.get(this->m_key).operatorinternal ::bridge::binary ().operator std::vector<uint 8 _t>();
346 }
347 };
348 template <>
349 struct <std::string>Box: publicbox_base < std::string><std::string> {
350 运用 box_base <std::string>::box_base;
351 运用 Box_base <std::string>:: 操作符=;
352 std::string操作符*() {
353 return this->m_backing_map.get(this->m_key).operator std::string();
354 }
355
356 rbool contains( const std::string& rhs) const {
357 if (this->m_rbool_query) {
358 return this->m_rbool_query->dictionary_contains_string_for_key(this->m_col_key, m_key, rhs);
359 }
360 std::string lhs = m_backing_map.get(m_key);
361 return lhs.find(rhs) != std::string::npos;
362 }
363 };
364
365 //MARK: - 盒装链接
366 template < typename V>
367 struct box<managed<V*>> : public box_base<managed<V*>> {
368 运用 Box_base < Managed<V*> >::box_base;
369 运用 Box_base < 托管<V*> >:: 操作符=;
370 运用 Box_base < 托管<V*> >:: 操作符==;
371
372 rbool 操作符==( constmanaged < V*> &rhs) const {
373 if (this->m_rbool_query) {
374 return this->m_rbool_query->dictionary_has_value_for_key_equals(this->m_col_key,
375 this->m_key,
376 rhs ? Internal::bridge::mixed ( Internal::bridge::obj_link (rhs.m_obj->get_table().get_key(), rhs.m_obj->get_key())) : Internal::bridge::mixed ()) ;
第 377 章
378 auto a = const_cast< box< 托管<V*> > *>( this )->m_backing_map.get_object(this->m_key);
379 auto &b = rhs.m_obj;
380 if (this->m_realm != *rhs.m_realm) {
381 return false
382 }
383 return a.get_key() == b->get_key();
384 }
385
386 rbool操作符!=( const 托管<V*> rhs) const {
387 if (this->m_rbool_query) {
388 return this->m_rbool_query->dictionary_has_value_for_key_not_equals(this->m_col_key,
389 this->m_key,
390 rhs ? Internal::bridge::mixed ( Internal::bridge::obj_link (rhs.m_obj->get_table().get_key(), rhs.m_obj->get_key())) : Internal::bridge::mixed ()) ;
391 }
392 return !this-> 操作符==(rhs);
393 }
394
395 rbool 操作符==( constmanaged <V>&rhs) const {
396 if (this->m_rbool_query) {
397 return this->m_rbool_query->dictionary_has_value_for_key_equals(this->m_col_key,
398 this->m_key,
399 Internal::bridge::obj_link (rhs.m_obj.get_table().get_key(), rhs.m_obj.get_key()));
400 }
401
402 auto a = const_cast< box< 托管<V*> > *>( this )->m_backing_map.get_object(this->m_key);
403 auto &b = rhs.m_obj;
404 if (this->m_realm != rhs.m_realm) {
405 return false
406 }
407 return a.get_key() == b.get_key();
408 }
409
410 rbool操作符!=( const 托管<V> rhs) const {
411 if (this->m_rbool_query) {
412 return this->m_rbool_query->dictionary_has_value_for_key_not_equals(this->m_col_key,
413 this->m_key,
414 Internal::bridge::obj_link (rhs.m_obj.get_table().get_key(), rhs.m_obj.get_key()));
415 }
416
第 417 章 return !this-> 操作符==(rhs);
418 }
419
420 std::Optional<typename 托管<V*>::ref_type> 操作符*() {
第 421 章 auto obj = this->m_backing_map.get_object(this->m_key);
第 422 章 if (!obj.is_valid()) {
第 423 章 return std::nullopt;
424 }
第 425 章 return typename 托管<V*>::ref_type ( 托管<V> (std::move(obj), this->m_realm));
第 426 章
第 427 章
428 typename 托管<V*>::ref_type 操作符->() {
429 if (this->m_rbool_query) {
431 ctx.m_key = this->m_key;
432 ctx.origin_col_key = this->m_col_key;
433 this->m_rbool_query->add_dictionary_link_chain(std::move(ctx));
第 434 章 return typename 托管<V*>::ref_type ( 托管<V>::prepare_for_query (this->m_realm, this->m_rbool_query));
435 }
第 436 章 auto obj = this->m_backing_map.get_object(this->m_key);
第 437 章 return typename 托管<V*>::ref_type ( 托管<V> (std::move(obj), this->m_realm));
438 }
第 439 章
440 Box & 操作符=(V* o) {
441 if (!o) {
第 442 章 // Insert null link for key.
443 this->m_backing_map.insert(this->m_key, 域::internal::bridge::mixed ());
第 444 章 return * this ;
445 }
第 446 章 Internal::bridge::obj m_obj;
447 if constexpr ( 托管<V>:: 模式 .HasPrimaryKeyProperty) {
第 448 章 auto pk = (*o).*( managed<V>::schema .primary_key().ptr);
449 m_obj = const_cast< box< 托管<V*> > *>( this )->m_backing_map.create_and_insert_linked_object( const_cast< box< 托管<V*> > *>( this )->m_key, pk.value);
450 } else {
451 m_obj = const_cast< box< 托管<V*> > *>( this )->m_backing_map.create_and_insert_linked_object( const_cast< box< 托管<V*> > *>( this )->m_key);
452 }
453
454 std:: 应用([&m_obj, &o, 域 = this->m_realm]( auto && ...p) {
455 ( accessor < typename std::decay_t< decltype (p)>::Result>::set(
456 m_obj, m_obj.get_table().get_column_key(p.name), Realm,
457 (*o).*(std::decay_t< decltype (p)>::ptr)), ...);
458 }, 托管<V>:: 模式 .ps);
第 459 章 return * this ;
460 }
第 461 章
第 462 章 Box & 操作符=( const 托管<V*> & o) {
463 this->m_backing_map.insert(this->m_key, o->m_obj.get_key());
第 464 章 return * this ;
465 }
第 466 章
第 467 章 Box & 操作符=( const 托管<V> & o) {
468 this->m_backing_map.insert(this->m_key, o.m_obj.get_key());
469 return * this ;
470 }
第 471 章
472 bool 操作符==( constbox < Managed < V*> > &rhs) const {
473 auto a = const_cast< box<managed<V*> > *>( this )->m_backing_map.get_object(this->m_key);
474 auto &b = static_cast<box<managed<V*>>>(rhs)->m_obj;
475 if (this->m_realm != rhs.m_realm) {
476 return false
477 }
478 return a.get_key() == b.get_key();
479 }
480
481 bool操作符!=( const Box < Managed<V*> > rhs) const {
482 return !this-> 操作符==(rhs);
483 }
484
485 bool 操作符==( constbox <V*> & rhs) {
486 auto a = const_cast< box< 托管<V*> > *>( this )->m_backing_map.get_object(this->m_key);
487 auto &b = (&rhs)->m_obj;
488 if (this->m_realm != rhs.m_realm) {
489 return false
490 }
491 return a.get_key() == b.get_key();
492 }
493
494 bool操作符!=( const box<V*> & rhs) const {
495 return !this-> 操作符==(rhs);
496 }
497 };
498
499 template < typename T>
500 struct 托管 <std::map<std::string, T>, void> : Managed_base {
501 运用 托管 <std::map<std::string, T>>::managed_base:: 操作符=;
502
503 [[nodiscard]] std::map<std::string, T> detach() const {
504 if constexpr (std::is_pointer_v<T>) {
505 auto d = external::bridge::get<internal::bridge::core_dictionary>(*m_obj, m_key);
506 size_t s = d.size();
507 std::map<std::string, T> ret;
508 for (size_t i = 0; i < s; i++) {
509 auto pair = d.get_pair(i);
510 using Type = std::remove_pointer_t<T>;
511 T v = new Type;
512 托管<Type, void> m(d.get_object(pair.first), *m_realm);
513
514 auto assign = [&m, &v]( auto &pair) {
515 (*v).*(std::decay_t< decltype (pair.first)>::ptr) = (m.*(pair.second)).detach();
516 };
517 auto zipped =Internal::zip_tuples( 托管<Type>:: 模式 .ps, 托管<Type>::managed_pointers ());
518
519 std:: 应用([&v, &m, & assign]( auto && ...pair) {
520 (分配(对), ...);
521 },已压缩);
522
523 ret[pair.first] = v;
524 }
525
526 return ret;
527 }
528 auto ret = std::map<std::string, T>();
529 for ( auto [k, v] : * this ) {
530 ret[k] = v;
531 }
532 return ret;
533 }
534
535 std::enable_if<std::is_pointer_v<T>, std::map<std::string, managed<T>>> to_map() const {
536 auto ret = std::map<std::string, T>();
537 for ( auto [k, v] : * this ) {
538 ret[k] = v;
539 }
540 return ret;
541 }
542
543 迭代器 {
544 public :
545 using iterator_category = std::input_iterator_tag;
546
547 bool操作符!=( const iterator& other) const
548 {
549 return !(* this == other);
550 }
551
552 bool 操作符==( const iterator& other) const
553 {
554 return (m_parent == other.m_parent) && (m_i == other.m_i);
555 }
556
557 std::pair<std::string, T> 操作符*() noException
558 {
559 autopair = m_parent->m_obj->get_dictionary(m_parent->m_key).get_pair(m_i);
560 return {pair.first, deserialize<T>(pair.second) };
561 }
562
563 iterator& Operator++()
564 {
565 this->m_i++;
566 return * this ;
567 }
568
569 const iterator& Operator++( int i)
570 {
571 this->m_i += i;
572 return * this ;
573 }
574 private :
575 template < typename , typename >
576 朋友 struct 托管
577
578iterator( size_t i , constmanaged <std::map<std::string, T>>*parent)
579 :m_i(i), m_parent(parent)
580 {
581 }
582 size_t m_i;
583 const 托管<std::map<std::string, T> >* m_parent;
584 };
585
586 size_t size() const
587 {
588 return m_obj->get_dictionary(m_key).size();
589 }
590
591迭代器 begin() const
592 {
593 return iterator( 0 , this );
594 }
595
596 iterator end() const
597 {
598 return iterator(size(), this );
599 }
600
601 iterator find( const std::string& key) {
602 if (m_rbool_query) {
603 throw std::runtime_error( "`find` 在类型安全查询中不可用,请改用 `contains_key`。" );
604 }
605 //Dictionary 的“find”搜索值的索引,而不是键。
606 auto d = m_obj->get_dictionary(m_key);
607 auto i = d.find_any_key(key);
608 if (i == size_t (- 1 )) {
609 return iterator(size(), this );
610 } else {
611 return iterator(i, this );
612 }
613 }
614
615 box<std::conditional_t<std::is_pointer_v<T>, 托管<T>, T>> 操作符[]( const std::string &key) {
616 if constexpr (std::is_pointer_v<T>) {
617 if (m_rbool_query) {
618 returnbox < 托管<T>>(m_rbool_query, m_key, key, *m_realm);
619 }
620 returnbox < 托管<T>>(m_obj->get_dictionary(m_key), key, *m_realm);
621 } else {
622 if (m_rbool_query) {
623 returnbox <T>(m_rbool_query, m_key, key, *m_realm);
624 }
625 returnbox <T>(m_obj->get_dictionary(m_key), key, *m_realm);
626 }
627 }
628
629 void delete( const std::string& key) {
630 m_obj->get_dictionary(m_key).erase(key);
631 }
632
634 rbool contains_key ( const std::string& key) {
635 if (m_rbool_query) {
636 return m_rbool_query->dictionary_has_key(m_key, key);
637 } else {
638 return m_obj->get_dictionary(m_key).find_any_key(key) != size_t(- 1 );
639 }
640 }
641
642 notification_token Watch(std::function< void ( 域::dictionary_collection_change )>&& fn)
643 {
644 auto o = Internal::bridge:: 对象 (*m_realm, *m_obj);
645 auto dict = std::make_shared<realm::internal::bridge::dictionary>(o.get_dictionary(m_key));
646 realm::notification_token token = dict->add_key_based_notification_callback(
647std::make_shared(std::move(fn),<realm::dictionary_callback_wrapper> false ));
648 token.m_realm = *m_realm;
649 token.m_dictionary = 字典;
650 返回令牌;
651 }
652
653 private :
654 managed() = default ;
655 Managed( const Managed&) = delete ;
656 托管(托管 &&) = 删除 ;
657 Managed& 操作符=( const Managed&) = 删除 ;
658 Managed& Operator=(managed&&) = delete ;
659 template < typename , typename >
660 朋友 struct 托管;
661 };
662
663 } // 命名空间 Realm
664
665#endif//CPREALM_MANAGED_DICTIONARY_HPP
定义: rbool.hpp:36
定义: accessors.hpp:33
定义: managed_dictionary.hpp: 31
定义: managed_dictionary.hpp: 129
定义: types.hpp: 75
定义: dictionary.hpp: 53
定义: binary.hpp: 30
定义: col_key.hpp: 28
定义: dictionary.hpp: 106
定义:十进制128 .hpp: 30
定义: mixed.hpp:69
定义: obj.hpp:123
定义: object_id.hpp:31
定义: object.hpp: 154
定义: realm.hpp: 67
定义: timestamp.hpp: 30
定义: uuid.hpp:32
rbool contains_key(const std::string &key)
主要用于类型安全查询的便捷方法。
定义: managed_dictionary.hpp: 634
定义: macros.hpp:286
定义: obj.hpp:62
定义: notifications.hpp:38
定义: types.hpp:56
定义: managed_primary_key.hpp:30
定义: rbool.hpp: 38
定义: types.hpp:35