19#ifndef CPPREALM_MANAGED_SET_HPP
20#define CPPREALM_MANAGED_SET_HPP
22#include <cpprealm/macros.hpp>
23#include <cpprealm/notifications.hpp>
24#include <cpprealm/observation.hpp>
25#include <cpprealm/types.hpp>
31 template <
typename T>
32 struct 托管 <std:: 设立<T>, std::enable_if_t<internal::type_info::is_primitive<T>::value>> :
Managed_base {
33 运用 托管 <std:: 设立<T>>::managed_base:: 操作符=;
40 using different_type = std::ptrdiff_t;
43 using iterator_category = std::forward_iterator_tag;
45 bool操作符!=(
const iterator& other)
const
47 return !(*
this == other);
50 bool 操作符==(
const iterator& other)
const
52 return (m_parent == other.m_parent) && (m_i == other.m_i);
55 T操作符*()
const noException
58 return deserialize<T>(s.get_any(m_i));
61 iterator& Operator++()
67 const iterator& Operator++(
int i)
73 template <
typename ,
typename >
76 iterator(
size_t i,
Managed <std::set<T>>*parent)
77 :m_i(i), m_parent(parent)
85 return iterator( 0 ,
this );
90 return iterator(size(),
this );
92 [[nodiscard]] std:: 设立<T> detach()
const {
94 auto ret = std::set<T>();
95 for (
size_t i = 0 ; i < 设立.size(); i++) {
96 ret.insert(deserialize<T>(set.get_any(i)));
102 auto set = std::make_shared<realm::internal::bridge::set>(*m_realm, *m_obj, m_key);
104<realm::collection_callback_wrapper>std::make_shared(
107 token.m_realm = *m_realm;
112 void delete(
const iterator& it)
114 auto 设立 = external::bridge:: 设立(*m_realm, *m_obj, m_key);
115设立。删除(serialize(*it));
118 std::pair<iterator, bool> insert(
const T& v)
120 auto 设立 = external::bridge:: 设立(*m_realm, *m_obj, m_key);
121 if constexpr (internal::type_info::MixedPersistableConcept<T>::value) {
122 std::pair<size_t, bool> res = 设立.insert(serialize<T>(v));
123 return std::pair<iterator, bool>(iterator(res.first,
this ), res.second);
125 std::pair<size_t, bool> res = 设立.insert(v);
126 return std::pair<iterator, bool>(iterator(res.first,
this ), res.second);
130 iterator insert(
const iterator&,
const T& v)
132 auto 设立 = external::bridge:: 设立(*m_realm, *m_obj, m_key);
133 std::pair<size_t, bool> res = 设立.insert(v);
134 return iterator(res.first,
this );
137 iterator find(
const T& v)
139 auto 设立 = external::bridge:: 设立(*m_realm, *m_obj, m_key);
140 size_t idx = 设立.find(serialize(v));
141 if (idx == 域::not_in_collection)
142 return iterator(size(),
this );
143 return iterator(idx,
this );
146 Internal::bridge::set(*m_realm, *m_obj, m_key).remove_all();
151 returninternal::bridge:: 设立(*
m_realm , *m_obj, m_key).size();
155 managed() =
default ;
156 Managed(
const Managed&) =
delete ;
158 Managed& 操作符=(
const Managed&) =
删除 ;
159 Managed& Operator=(managed&&) =
delete ;
160 template <
typename ,
typename >
164 template <
typename T>
166 运用 托管 <std:: 设立<T*>>::managed_base:: 操作符=;
173 using different_type = std::ptrdiff_t;
175 using reference = T&;
176 using iterator_category = std::forward_iterator_tag;
178 bool操作符!=(
const iterator& other)
const
180 return !(*
this == other);
183 bool 操作符==(
const iterator& other)
const
185 return (m_parent == other.m_parent) && (m_i == other.m_i);
188 托管<T>操作符*()
const noException
191 托管<T> m(s.get_obj(m_i), *m_parent->m_realm);
192 return {std::move(m)};
195 iterator& Operator++()
201 const iterator& Operator++(
int i)
207 template <
typename ,
typename >
210 iterator(
size_t i,
Managed <std::set<T*>>*parent)
211 :m_i(i), m_parent(parent)
219 return iterator( 0 ,
this );
224 return iterator(size(),
this );
226 [[nodiscard]] std:: 设立<T*> detach()
const {
228 size_t count = s.size();
230 return std:: 设立<T*>();
231 auto ret = std::set<T*>();
232 for(
size_t i = 0; i < count; i++) {
233 托管<T> m(s.get_obj(i), *m_realm);
235 auto assign = [&m, &v](
auto &pair) {
236 (*v).*(std::decay_t<
decltype (pair.first)>::ptr) = (m.*(pair.second)).detach();
238 auto zipped =Internal::zip_tuples(托管<T>:: 模式.ps, 托管<T>::managed_pointers());
239 std:: 应用([&v, &m, & assign](
auto && ...pair) {
249 auto set = std::make_shared<realm::internal::bridge::set>(*m_realm, *m_obj, m_key);
251<realm::collection_callback_wrapper>std::make_shared(
254 token.m_realm = *m_realm;
259 void delete(
const iterator& it)
261 auto 设立 = external::bridge:: 设立(*m_realm, *m_obj, m_key);
262 set.remove(it.operator*().m_obj.get_key());
265 std::pair<iterator, bool> insert(T* value)
267 auto 设立 = external::bridge:: 设立(*m_realm, *m_obj, m_key);
268 auto table = m_obj->get_target_table(m_key);
270 if constexpr (托管<T>:: 模式.HasPrimaryKeyProperty) {
271 auto pk = (*value).*(managed<T>::schema.primary_key().ptr);
274 m_obj = table.create_object();
276 std:: 应用([&m_obj, &value, 域 = *m_realm](
auto && ...p) {
277 (accessor<
typename std::decay_t<
decltype (p)>::Result>:: 设立(
278 m_obj, m_obj.get_table().get_column_key(p.name), Realm,
279 (*value).*(std::decay_t<
decltype (p)>::ptr)), ...);
280 }, 托管<T, void>:: 模式.ps);
281 if (!managed<T>::schema.is_embedded()) {
282 set.insert(m_obj.get_key());
284 std::pair<size_t, bool> res = 设立.insert(m_obj.get_key());
285 return std::pair<iterator, bool>(iterator(res.first,
this ), res.second);
288 iterator insert(
const iterator&, T* value)
290 auto 设立 = external::bridge:: 设立(*m_realm, *m_obj, m_key);
291 auto table = m_obj->get_target_table(m_key);
293 if constexpr (托管<T>:: 模式.HasPrimaryKeyProperty) {
294 auto pk = (*value).*(managed<T>::schema.primary_key().ptr);
297 m_obj = table.create_object();
299 std:: 应用([&m_obj, &value, 域 = *m_realm](
auto && ...p) {
300 (accessor<
typename std::decay_t<
decltype (p)>::Result>:: 设立(
301 m_obj, m_obj.get_table().get_column_key(p.name), Realm,
302 (*value).*(std::decay_t<
decltype (p)>::ptr)), ...);
303 }, 托管<T, void>:: 模式.ps);
304 std::pair<size_t, bool> res = 设立.insert(m_obj.get_key());
305 return iterator(res.first,
this );
308 std::pair<iterator , bool> insert(
constmanaged <T>& value)
310 auto 设立 = external::bridge:: 设立(*m_realm, *m_obj, m_key);
311 std::pair<size_t, bool> res = 设立.insert(value.m_obj.get_key());
312 return std::pair<iterator, bool>(iterator(res.first,
this ), res.second);
316 iterator insert(
const 托管&,
constmanaged <T>& value)
318 auto 设立 = external::bridge:: 设立(*m_realm, *m_obj, m_key);
319 std::pair<size_t, bool> res = 设立.insert(value.m_obj.get_key());
320 return iterator(res.first,
this );
323 std::pair<iterator, bool> insert(
constmanaged <T*>& value)
325 auto 设立 = external::bridge:: 设立(*m_realm, *m_obj, m_key);
326 std::pair<size_t, bool> res = 设立.insert(value.m_obj.get_key());
327 return std::pair<iterator, bool>(iterator(res.first,
this ), res.second);
331 iterator insert(
const iterator&,
constmanaged <T*>& value)
333 auto 设立 = external::bridge:: 设立(*m_realm, *m_obj, m_key);
334 std::pair<size_t, bool> res = 设立.insert(value.m_obj.get_key());
335 return iterator(res.first,
this );
338 iterator find(
constmanaged <T>& v)
340 auto 设立 = external::bridge:: 设立(*m_realm, *m_obj, m_key);
341 size_t idx = 设立.find(v.m_obj.get_key());
342 if (idx == 域::not_in_collection)
343 return iterator(size(),
this );
344 return iterator(idx,
this );
347 iterator find(
constmanaged <T*>& v)
349 auto 设立 = external::bridge:: 设立(*m_realm, *m_obj, m_key);
350 size_t idx = 设立.find(v.m_obj->get_key());
351 if (idx == 域::not_in_collection)
352 return iterator(size(),
this );
353 return iterator(idx,
this );
356 Internal::bridge::set(*m_realm, *m_obj, m_key).remove_all();
361 returninternal::bridge:: 设立(*
m_realm , *m_obj, m_key).size();
365 managed() =
default ;
366 Managed(
const Managed&) =
delete ;
368 Managed& 操作符=(
const Managed&) =
删除 ;
369 Managed& Operator=(managed&&) =
delete ;
370 template <
typename ,
typename >