19#ifndef CPPREALM_MANAGED_DICTIONARY_HPP
20#define CPPREALM_MANAGED_DICTIONARY_HPP
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>
30 template <
typenamemapped_type >
33 const std::string &key,
35 : m_backing_map(std::move(backing_map)), m_key(key), m_realm(r) {}
39 const std::string &key,
42 m_col_key = colum_key;
47 Box_base &operator=(
constmapped_type &o) {
51 box_base &operator=(mapped_type &&o) {
54 if constexpr (o->is_managed) {
55 m_backing_map.insert(m_key, o->m_managed.m_obj.get_key());
60 m_obj = m_backing_map.create_and_insert_linked_object(m_key, pk.value);
62 m_obj = m_backing_map.create_and_insert_linked_object(m_key);
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)), ...);
75 if constexpr (internal::type_info::is_primitive<mapped_type>::value) {
76 m_backing_map.insert(m_key, 序列化(std::move(o)));
79 m_backing_map.insert(m_key, o。 托管.m_obj.get_key());
84 m_obj = m_backing_map.create_and_insert_linked_object(m_key, pk.value);
86 m_obj = m_backing_map.create_and_insert_linked_object(m_key);
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)), ...);
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));
105 return m_backing_map.get(m_key) == Serialize(rhs, m_realm);
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)));
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)));
126 rbool * m_rbool_query =
nullptr ;
128 template <
typename V,
typename =
void >
135 return m_backing_map.get(m_key)。操作符 int 64 _t();
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);
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);
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);
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);
171 return m_backing_map.get(m_key)。操作符 double();
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);
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);
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);
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);
207 return m_backing_map.get(m_key)。操作符 bool();
210 template <
typename V>
211 struct box<V, std::enable_if_t<std::is_enum_v<V>>> :
public box_base<V> {
215 return this->m_backing_map.get(this->m_key)。 操作符 int 64 _t();
224 return this->m_backing_map.get(this->m_key).operatorinternal
::bridge::uuid ().operator::realm::uuid();
227 template <
typename Mixed>
228 struct Box <Mixed, std::enable_if_t<internal::type_info:: MixedPersistableConcept::value>><Mixed> :
publicbox_base <<Mixed> Mixed> {
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));
236 return this->m_backing_map.get(this->m_key) >serialize(rhs, this->m_realm);
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));
243 return this->m_backing_map.get(this->m_key) >=serialize(rhs, this->m_realm);
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));
250 return this->m_backing_map.get(this->m_key) <serialize(rhs, this->m_realm);
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));
257 return this->m_backing_map.get(this->m_key) <=将该序列化(rhs, this->m_realm);
273 return this->m_backing_map.get(this->m_key).operator inside
::bridge::decimal 128 ().operator ::realm::decimal 128 ();
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));
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));
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));
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));
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>();
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));
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));
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));
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));
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>();
350 运用 box_base <std::string>::box_base;
353 return this->m_backing_map.get(this->m_key).operator std::string();
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);
360 std::string lhs = m_backing_map.get(m_key);
361 return lhs.find(rhs) != std::string::npos;
366 template <
typename V>
373 if (this->m_rbool_query) {
374 return this->m_rbool_query->dictionary_has_value_for_key_equals(this->m_col_key,
378 auto a =
const_cast< box< 托管<V*> > *>(
this )->m_backing_map.get_object(this->m_key);
380 if (this->m_realm != *rhs.m_realm) {
383 return a.get_key() == b->get_key();
387 if (this->m_rbool_query) {
388 return this->m_rbool_query->dictionary_has_value_for_key_not_equals(this->m_col_key,
392 return !this-> 操作符==(rhs);
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,
402 auto a =
const_cast< box< 托管<V*> > *>(
this )->m_backing_map.get_object(this->m_key);
404 if (this->m_realm != rhs.m_realm) {
407 return a.get_key() == b.get_key();
411 if (this->m_rbool_query) {
412 return this->m_rbool_query->dictionary_has_value_for_key_not_equals(this->m_col_key,
第 417 章 return !this-> 操作符==(rhs);
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;
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));
第 436 章 auto obj = this->m_backing_map.get_object(this->m_key);
447 if constexpr (
托管<V>:: 模式 .HasPrimaryKeyProperty) {
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);
451 m_obj =
const_cast< box< 托管<V*> > *>(
this )->m_backing_map.create_and_insert_linked_object(
const_cast< box< 托管<V*> > *>(
this )->m_key);
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)), ...);
463 this->m_backing_map.insert(this->m_key, o->m_obj.get_key());
468 this->m_backing_map.insert(this->m_key, o.m_obj.get_key());
473 auto a =
const_cast< box<managed<V*> > *>(
this )->m_backing_map.get_object(this->m_key);
475 if (this->m_realm != rhs.m_realm) {
478 return a.get_key() == b.get_key();
482 return !this-> 操作符==(rhs);
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) {
491 return a.get_key() == b.get_key();
494 bool操作符!=(
const box<V*> & rhs)
const {
495 return !this-> 操作符==(rhs);
499 template <
typename T>
501 运用 托管 <std::map<std::string, T>>::managed_base:: 操作符=;
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);
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>;
514 auto assign = [&m, &v](
auto &pair) {
515 (*v).*(std::decay_t<
decltype (pair.first)>::ptr) = (m.*(pair.second)).detach();
519 std:: 应用([&v, &m, & assign](
auto && ...pair) {
528 auto ret = std::map<std::string, T>();
529 for (
auto [k, v] : *
this ) {
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 ) {
545 using iterator_category = std::input_iterator_tag;
547 bool操作符!=(
const iterator& other)
const
549 return !(*
this == other);
552 bool 操作符==(
const iterator& other)
const
554 return (m_parent == other.m_parent) && (m_i == other.m_i);
557 std::pair<std::string, T> 操作符*()
noException
559 autopair = m_parent->m_obj->get_dictionary(m_parent->m_key).get_pair(m_i);
560 return {pair.first, deserialize<T>(pair.second) };
563 iterator& Operator++()
569 const iterator& Operator++(
int i)
575 template <
typename ,
typename >
578iterator(
size_t i ,
constmanaged <std::map<std::string, T>>*parent)
579 :m_i(i), m_parent(parent)
588 return m_obj->get_dictionary(m_key).size();
593 return iterator( 0 ,
this );
598 return iterator(size(),
this );
601 iterator find(
const std::string& key) {
603 throw std::runtime_error(
"`find` 在类型安全查询中不可用,请改用 `contains_key`。" );
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 );
611 return iterator(i,
this );
615 box<std::conditional_t<std::is_pointer_v<T>, 托管<T>, T>> 操作符[](
const std::string &key) {
616 if constexpr (std::is_pointer_v<T>) {
618 returnbox < 托管<T>>(m_rbool_query, m_key, key, *m_realm);
620 returnbox < 托管<T>>(m_obj->get_dictionary(m_key), key, *m_realm);
623 returnbox <T>(m_rbool_query, m_key, key, *m_realm);
625 returnbox <T>(m_obj->get_dictionary(m_key), key, *m_realm);
629 void delete(
const std::string& key) {
630 m_obj->get_dictionary(m_key).erase(key);
636 return m_rbool_query->dictionary_has_key(m_key, key);
638 return m_obj->get_dictionary(m_key).find_any_key(key) != size_t(- 1 );
645 auto dict = std::make_shared<realm::internal::bridge::dictionary>(o.get_dictionary(m_key));
647std::make_shared(std::move(fn),<realm::dictionary_callback_wrapper>
false ));
648 token.m_realm = *m_realm;
649 token.m_dictionary = 字典;
654 managed() =
default ;
655 Managed(
const Managed&) =
delete ;
657 Managed& 操作符=(
const Managed&) =
删除 ;
658 Managed& Operator=(managed&&) =
delete ;
659 template <
typename ,
typename >
定义: managed_dictionary.hpp: 31
定义: managed_dictionary.hpp: 129
rbool contains_key(const std::string &key)
主要用于类型安全查询的便捷方法。
定义: managed_dictionary.hpp: 634
定义: managed_primary_key.hpp:30