19#ifndef CPPREALM_BRIDGE_LINK_HPP
20#define CPPREALM_BRIDGE_LINK_HPP
22#include <cpprealm/accessors.hpp>
23#include <cpprealm/macros.hpp>
24#include <cpprealm/rbool.hpp>
26#include <cpprealm/internal/type_info.hpp>
29 template <
typename ,
typename >
32 template <
typename T>
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 &pair) {
38 (*v).*(std::decay_t<
decltype (pair.first)>::ptr) = (m.*(pair.second)).detach();
41 std:: 应用([&v, &m, & assign](
auto && ...pair) {
48 显式ref_type(
托管<T> && value) : m_managed(std::move(value)) { }
49 const 托管<T> * 操作符 ->()
const {
56 const 托管<T> & 操作符 *()
const {
63 bool 操作符 ==(
constmanaged < T*> & rhs)
const {
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 ==(
constmanaged <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 this->m_managed.m_obj.get_key() == rhs.m_obj.get_key();
76 bool Operator ==(
const ref_type& rhs)
const {
77 if (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 this->m_managed.m_obj.get_key() == rhs.m_managed.m_obj.get_key();
83 bool 操作符 !=(
const 托管<T*> & rhs)
const {
84 return !this-> 操作符==(rhs);
86 bool Operator !=(
constmanaged <T> & rhs)
const {
87 return !this-> 操作符==(rhs);
89 bool 操作符 !=(
const ref_type& rhs)
const {
90 return !this-> 操作符==(rhs);
95 ref_type 操作符 ->()
const {
96 if (this->m_rbool_query) {
97 this->m_rbool_query->add_link_chain(m_key);
100 return ref_type(
managed<T> (m_obj->get_linked_object(m_key), *m_realm));
103 if (m_obj && m_key) {
104 return !m_obj->is_null(m_key);
108 托管 &operator=(
constmanaged <T>& 托管) {
109 m_obj->set(m_key, obj.m_obj.get_key());
112 托管 &operator=(
const 托管<T*> &obj) {
113 m_obj->set(m_key, obj.m_obj->get_key());
116 托管 &operator=(std::nullptr_t) {
117 m_obj->set_null(m_key);
120 Managed &operator=(T* o) {
121 auto class = m_realm->table_for_object_type(托管<T>:: 模式.name);
122 internal::bridge::obj obj;
124 m_obj->set_null(m_key);
126 }
else if constexpr (托管<T>:: 模式.HasPrimaryKeyProperty) {
127 auto pk = (*o).*(托管<T>:: 模式.primary_key().ptr);
129 m_obj->set(m_key, obj.get_key());
130 }
else if (托管<T>:: 模式.is_embedded()) {
131 obj = m_obj->create_and_set_linked_object(m_key);
133 obj = tab.create_object();
134 m_obj->set(m_key, obj.get_key());
137 std:: 应用([&obj, &o, 域 = *m_realm](
auto && ...p) {
138 (accessor<
typename std::decay_t<
decltype (p)>::Result>:: 设立(
139 obj, obj.get_table().get_column_key(p.name), 域, (*o).*(std::decay_t<
decltype (p)>::ptr)
145 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 托管 操作符 ==(
constmanaged <T>& rhs)
const {
153 return m_rbool_query->link_equal(m_key, rhs.m_obj);
155 if (*this->m_realm != rhs.m_realm)
157 return m_obj->get_linked_object(m_key).get_key() == rhs.m_obj.get_key();
160 rbool操作符==(
const 托管<T*>& rhs)
const {
162 return m_rbool_query->link_equal(m_key, *rhs.m_obj);
164 if (*this->m_realm != *rhs.m_realm)
166 return m_obj->get_linked_object(m_key).get_key() == rhs.m_obj->get_key();
169 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 rbool 操作符 !=(
const 托管<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 rbool 操作符 !=(
const 托管<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();
191 template <
typename ,
typename >