19#ifndef CPPREALM_MANAGED_DICTIONARY_HPP
20#define CPPREALM_MANAGED_DICTIONARY_HPP
22#include <cprealm/accessors.hpp>
23#include <cprealm/macros.hpp>
24#include <cprealm/notifications.hpp>
25#include <cprealm/observation.hpp>
26#include <cprealm/rbool.hpp>
30 modelo<
typename mapped_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,
41 m_rbool_query = consulta;
42 m_col_key = column_key;
47 box_base &operator=(
const mapped_type &o) {
51 box_base &operator=(mapped_type &&o) {
54 se 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::apply([&m_obj, &o](
auto && ...p) {
66 (
acessador<
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 se constexpr (internal::type_info::is_primitive<mapped_type>::value) {
76 m_backing_map.insert(m_key, serialize(std::move(o)));
79 m_backing_map.insert(m_key, o.managed.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::apply([&m_obj, &o](
auto && ...p) {
90 (
acessador<
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 operator==(
const mapped_type &rhs)
const {
101 se constexpr (Realm::internal::type_info::MixedPersistableConcept<mapped_type>::value) {
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);
108 return this->m_rbool_query->Dictionary_has_value_for_key_equals(This->m_col_key, m_key,
internal::bridge::mixed(serialize(rhs)));
114 operador de
rbool !=(
const mapped_type &rhs)
const {
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)));
118 return !operator==(rhs);
126 rbool* m_rbool_query =
nullptr;
128 template<
typename V,
typename =
null>
133 Usando box_base<int64_t>::operator=;
134 int64operador _t*() {
135 return m_backing_map.get(m_key).operator int64_t();
138 operador de
rbool >(int64_t rhs)
const {
140 return this->m_rbool_query->Dictionary_has_value_for_key_greter_than(This->m_col_key, m_key, rhs);
145 operador de
rbool >=(int64_t rhs)
const {
147 return this->m_rbool_query->Dictionary_has_value_for_key_greter_than_equals(This->m_col_key, m_key, rhs);
152 operador de
rbool <(int64_t rhs)
const {
154 return this->m_rbool_query->Dictionary_has_value_for_key_less_than(This->m_col_key, m_key, rhs);
159 operador de
rbool <=(int64_t rhs)
const {
161 return this->m_rbool_query->Dictionary_has_value_for_key_less_than_equals(This->m_col_key, m_key, rhs);
170 operador
double *() {
171 return m_backing_map.get(m_key).operator double();
174 operador de
rbool >( rhs
double )
const {
176 return this->m_rbool_query->Dictionary_has_value_for_key_greter_than(This->m_col_key, m_key, rhs);
181 operador de
rbool >=( rhs
double )
const {
183 return this->m_rbool_query->Dictionary_has_value_for_key_greter_than_equals(This->m_col_key, m_key, rhs);
188 operador de
rbool <( rhs
double )
const {
190 return this->m_rbool_query->Dictionary_has_value_for_key_less_than(This->m_col_key, m_key, rhs);
195 operador de
rbool <=( rhs
double )
const {
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).operator bool();
211 estrutura, estrutura 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).operator int64_t();
227 template<
typename mixed>
228 estrutura, estrutura box<Misto, std::enable_if_t<internal::type_info::MixedPersistableConcept<Mixed>::value>> :
public box_base<Mixed> {
230 Usando <Mixed>box_base::operator=;
232 Operador de
rbool >(Rs mistos)
const {
234 return this->m_rbool_query->Dictionary_has_value_for_key_greter_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 operador de
rbool >=(Rs mistos)
const {
241 return this->m_rbool_query->Dictionary_has_value_for_key_greter_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 operador de
rbool <(Rs mistos)
const {
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 operador de
rbool <=(Rs mistos)
const {
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) <= serialize(rhs, this->m_realm);
278 return this->m_rbool_query->Dictionary_has_value_for_key_greter_than(This->m_col_key, m_key, serialize(rhs));
285 return this->m_rbool_query->Dictionary_has_value_for_key_greter_than_equals(This->m_col_key, m_key, serialize(rhs));
292 return this->m_rbool_query->Dictionary_has_value_for_key_less_than(This->m_col_key, m_key, serialize(rhs));
299 return this->m_rbool_query->Dictionary_has_value_for_key_less_than_equals(This->m_col_key, m_key, serialize(rhs));
305 estrutura, estrutura box<std::chrono::time_point<std::chrono::system_clock>> :
public box_base<std::chrono::time_point<std::chrono::system_clock>> {
306 Usando box_base<std::chrono::time_point<std::chrono::system_clock>>::box_base;
307 Usando box_base<std::chrono::time_point<std::chrono::system_clock>>::operator=;
308 std::chrono::time_point<std::chrono::system_clock> operator*() {
309 return this->m_backing_map.get(This->m_key).operator
internal::bridge::timestamp().operator std::chrono::time_point<std::chrono::system_clock>();
312 Operador de
rbool <std::chrono::system_clock>
>(std::chrono::time_point rhs) const {
314 return this->m_rbool_query->Dictionary_has_value_for_key_greter_than(This->m_col_key, m_key, serialize(rhs));
319 operador de
rbool <std::chrono::system_clock> >=(std::chrono::time_point rhs)
const {
321 return this->m_rbool_query->Dictionary_has_value_for_key_greter_than_equals(This->m_col_key, m_key, serialize(rhs));
326 operador rbool <(std::chrono::time_point<std::chrono::system_clock> rhs)
const {
328 return this->m_rbool_query->Dictionary_has_value_for_key_less_than(This->m_col_key, m_key, serialize(rhs));
333 operador rbool <=(std::chrono::time_point<std::chrono::system_clock> rhs)
const {
335 return this->m_rbool_query->Dictionary_has_value_for_key_less_than_equals(This->m_col_key, m_key, serialize(rhs));
341 estrutura, estrutura box<std::vector<uint8_t>> :
public box_base<std::vector<uint8_t>> {
342 Usando box_base<std::vector<uint8_t>>::box_base;
343 Usando box_base<std::vector<uint8_t>>::operator=;
344 std::vector<uint8_t> operator*() {
349 estrutura, estrutura box<std::string> :
public box_base<std::string> {
350 Usando box_base<std::string>::box_base;
351 Usando box_base<std::string>::operator=;
352 std::operador de string*() {
353 return this->m_backing_map.get(This->m_key).operator std::string();
356 rbool contains(
const std::string& rhs)
const {
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;
374 return this->m_rbool_query->Dictionary_has_value_for_key_equals(This->m_col_key,
378 auto a =
const_cast<managed<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();
388 return this->m_rbool_query->Dictionary_has_value_for_key_not_equals(This->m_col_key,
392 return !This->operator==(rhs);
397 return this->m_rbool_query->Dictionary_has_value_for_key_equals(This->m_col_key,
402 auto a =
const_cast<managed<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();
412 return this->m_rbool_query->Dictionary_has_value_for_key_not_equals(This->m_col_key,
417 return !This->operator==(rhs);
420 std::optional <typename managed <V*>::ref_type> operator*() {
421 auto obj = this->m_backing_map.get_object(This->m_key);
422 if (!obj.is_valid()) {
431 ctx.m_key = this->m_key;
432 ctx.origin_col_key = this->m_col_key;
433 esta->m_rbool_query->add_Dictionary_link_chain(std::move(ctx));
436 auto obj = this->m_backing_map.get_object(This->m_key);
440 box& operator=(V* o) {
449 m_obj =
const_cast+
box<managed<V*>> *>(
this)->m_backing_map.create_and_insert_linked_object(
const_cast+box<managed<V*>> *>(
this)->m_key, pk.value);
454 std::apply([&m_obj, &o, Realm = this->m_realm](
auto && ...p) {
455 (
acessador<
typename std::decay_t<
decltype(p)>::Result>::set(
456 m_obj, m_obj.get_table().get_column_key(p.name), domínio,
457 (*o).*(std::decay_t<
decltype(p)>::ptr)), ...);
463 esta->m_backing_map.insert(isto->m_key, o->m_obj.get_key());
468 esta->m_backing_map.insert(isto->m_key, o.m_obj.get_key());
473 auto a =
const_cast<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->operator==(rhs);
485 operador de
bool ==( caixa
const <V*>& rhs) {
486 auto a =
const_cast<managed<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 operador de
bool !=(
const box<V*>e rhs)
const {
495 return !This->operator==(rhs);
501 Usando managed<std::map<std::string, T>>::managed_base::operator=;
503 [[nodiscard]] std::map<std::string, T> detach()
const {
504 se constexpr (std::is_pointer_v<T>) {
505 auto d = internal::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 usando Type = std::remove_pointer_t<T>;
514 auto assign = [&m, &v](
auto& emparelh) {
515 (*v).*(std::decay_t<
decltype(pair.first)>::ptr) = (m.*(pair.second)).detach();
519 std::apply([&v, &m, &assign](
auto && ...pair) {
528 auto ret = std::map<std::string, T>();
529 para (
auto [k, v] : *
isto) {
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 para (
auto [k, v] : *
isto) {
545 usando iterator_category = std::input_iterator_tag;
547 operador de
bool !=(
const iterador e outros)
const
549 return !(*
isto == outro);
552 operador de
bool ==( iterador
const e outro)
const
554 return (m_parent == other.m_parent) && (m_i == other.m_i);
557 std::pair<std::string, T> operator*()
noexceto
559 auto emparelh = m_parent->m_obj->get_ dictionary(m_parent->m_key).get_pair(m_i);
560 retornar { par.first, deserialize<T>(pair.second) };
563 iterador e operador++()
569 const iterador e operador++(
int i)
575 modelo<
typename,
typename>
576 amigo estrutura, estrutura managed;
578 iterador(
size_t i,
const managed<std::map<std::string, T>>* pai)
579 : m_i(i), m_parent(parent)
588 return m_obj->get_ dictionary(m_key).size();
591 iterador begin()
const
593 retorna o iterador(0,
este);
596 end() do iterador
const
598 return iterador(tamanho(),
isto);
601 iterador find(
const std::string& chave) {
603 lance std::runtime_error(
"'find' não está disponível em queries seguras de tipo, use `contains_key' em vez disso.");
606 auto d = m_obj->get_ dictionary(m_key);
607 auto i = d.find_any_key(key);
608 se (i ==
size_t(-1)) {
609 return iterador(tamanho(),
isto);
611 return iterador(i,
isto);
616 se constexpr (std::is_pointer_v<T>) {
618 return box<managed<T>>(m_rbool_query, m_key, key, *m_realm);
620 return box<managed<T>>(m_obj->get_ dictionary(m_key), key, *m_realm);
623 return box<T>(m_rbool_query, m_key, key, *m_realm);
625 return box<T>(m_obj->get_Dictionary(m_key), key, *m_realm);
629 vazio apaga(
const std::string& chave) {
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 dic = std::make_shared<realm::internal::bridge::dictionary>(o.get_ditionary(m_key));
647 std::make_shared<realm::dictionary_callback_wrapper>(std::move(fn),
false));
648 token.m_realm = *m_realm;
649 token.m_Dictionary = ditam;
655 managed(
const managed&) =
delete;
656 managed(managed &&) =
excluir;
657 managed& operator=(
const managed&) =
excluir;
658 managed& operator=(managed&&) =
excluir;
659 modelo<
typename,
typename>
660 amigo estrutura managed;
Definição: accessors.hpp:33
Definição: managed_Dictionary.hpp:31
Definição: managed_Dictionary.hpp:129
Definição: dictionary.hpp:53
Definição: col_key.hpp:28
Definição: dictionary.hpp:106
Definição: decimal128.hpp:30
Definição: obj_key.hpp:53
Definição: object_id.hpp:31
Definição: object.hpp:154
Definição: timestamp.hpp:30
Definição: type_info.hpp:145
rbool contains_key(const std::string &key)
Método de conveniência a ser usado principalmente em queries seguras por tipo.
Definição: managed_Dictionary.hpp:634
Definição: macros.hpp:286
Definição: notificações.hpp:38
Definição: managed_primary_key.hpp:30