19#ifndef CPPREALM_BRIDGE_LINK_HPP
20#define CPPREALM_BRIDGE_Link_HPP
22#include <cprealm/accessors.hpp>
23#include <cprealm/macros.hpp>
24#include <cprealm/rbool.hpp>
26#include <cpprealm/internal/type_info.hpp>
29 modelo <
typename,
typename>
36 managed<T> m(m_obj->is_null(m_key) ? *m_obj : m_obj->get_linked_object(m_key), *m_realm);
37 auto assign = [&m, &v](
auto& emparelh) {
38 (*v).*(std::decay_t<
decltype(pair.first)>::ptr) = (m.*(pair.second)).detach();
41 std::apply([&v, &m, &assign](
auto && ...pair) {
47 estruturado ref_type {
48 ref_type
explícito (
managed<T>&& value) : m_managed(std::move(value)) { }
64 if (This->m_managed.m_realm != *rhs.m_realm) {
67 return this->m_managed.m_obj.get_key() == rhs.m_obj->get_key();
69 bool operator ==(
const managed<T>& rhs)
const {
70 if (This->m_managed.m_realm != rhs.m_realm) {
73 return this->m_managed.m_obj.get_table() == rhs.m_obj.get_table() &&
74 isto->m_managed.m_obj.get_key() == rhs.m_obj.get_key();
76 bool operator ==(
const ref_type& rhs)
const {
77 se (This->m_managed.m_realm != rhs.m_managed.m_realm) {
80 return this->m_managed.m_obj.get_table() == rhs.m_managed.m_obj.get_table() &&
81 isto->m_managed.m_obj.get_key() == rhs.m_managed.m_obj.get_key();
84 return !This->operator==(rhs);
86 operador de
bool !=(
const managed<T>& rhs)
const {
87 return !This->operator==(rhs);
89 operador de
bool !=(
const ref_type& rhs)
const {
90 return !This->operator==(rhs);
95 operador ref_type ->()
const {
97 esta->m_rbool_query->add_link_chain(m_key);
100 return ref_type(
managed<T>(m_obj->get_linked_object(m_key), *m_realm));
102 operador bool()
const {
103 if (m_obj && m_key) {
104 return !m_obj->is_null(m_key);
108 managed &operator=(
const managed<T>& obj) {
109 m_obj->set(m_key, obj.m_obj.get_key());
112 managed &operator=(
const managed<T*> &obj) {
113 m_obj->set(m_key, obj.m_obj->get_key());
116 managed &operator=(std::nullptr_t) {
117 m_obj->set_null(m_key);
120 managed &operator=(T* o) {
121 auto table = m_realm->table_for_object_type(managed<T>::schema.name);
122 internal::bridge::obj obj;
124 m_obj->set_null(m_key);
126 }
outra forma
se constexpr (managed<T>::schema.HasPrimaryKeyProperty) {
127 auto pk = (*o).*(managed<T>::schema.primary_key().ptr);
129 m_obj->set(m_key, obj.get_key());
130 }
mais se (gerenciado<T>::schema.is_embedded()) {
131 obj = m_obj->create_and_set_linked_object(m_key);
133 obj = table.create_object();
134 m_obj->set(m_key, obj.get_key());
137 std::apply([&obj, &o, Realm = *m_realm](
auto && ...p) {
138 (acessador <
typename std::decay_t <
decltype(p)>::Result>::set(
139 obj, obj.get_table().get_column_key(p.name), Realm, (*o).*(std::decay_t<
decltype(p)>::ptr)
141 }, managed<T>::schema.ps);
145 operador de rbool ==(std::nullptr_t)
const {
147 return m_rbool_query->link_equal(m_key, std::nullopt);
149 return !m_obj->get_linked_object(m_key).is_valid();
151 rbool operator ==(
const managed<T>& rhs)
const {
153 return m_rbool_query->link_equal(m_key, rhs.m_obj);
155 se (*This->m_realm != rhs.m_realm)
157 return m_obj->get_linked_object(m_key).get_key() == rhs.m_obj.get_key();
160 rbool operator ==(
const managed<T*>& rhs)
const {
162 return m_rbool_query->link_equal(m_key, *rhs.m_obj);
164 se (*This->m_realm != *rhs.m_realm)
166 return m_obj->get_linked_object(m_key).get_key() == rhs.m_obj->get_key();
169 operador de rbool !=(std::nullptr_t)
const {
171 return m_rbool_query->link_not_equal(m_key, std::nullopt);
173 return m_obj->get_linked_object(m_key).is_valid();
175 operador rbool !=(
const managed<T>& rhs)
const {
177 return m_rbool_query->link_not_equal(m_key, rhs.m_obj);
179 return m_obj->get_linked_object(m_key).is_valid();
182 operador rbool !=(
const managed<T*>& rhs)
const {
184 return m_rbool_query->link_not_equal(m_key, *rhs.m_obj);
186 return m_obj->get_linked_object(m_key).is_valid();
190 managed<T*>() =
default;
191 modelo<
typename,
typename>
192 amigo estrutura managed;
Definição: macros.hpp:286