19#ifndef CPPREALM_MANAGED_SET_HPP
20#define CPPREALM_MANAGED_SET_HPP
22#include <cprealm/macros.hpp>
23#include <cprealm/notifications.hpp>
24#include <cprealm/observation.hpp>
25#include <cprealm/types.hpp>
32 estrutura, estrutura managed<std::set<T>, std::enable_if_t<internal::type_info::is_primitive<T>::value>> :
managed_base {
33 Usando gerenciado<std::set<T>>::managed_base::operator=;
34 usando value_type = T;
38 usando value_type = T;
40 usando change_type = std::ptrdiff_t;
42 usando reference = T&;
43 usando iterator_category = std::forward_iterator_tag;
45 operador de
bool !=(
const iterador e outros)
const
47 return !(*
isto == outro);
50 operador de
bool ==( iterador
const e outro)
const
52 return (m_parent == other.m_parent) && (m_i == other.m_i);
55 Operador T*()
const noexceto
58 return deserialize<T>(s.get_any(m_i));
61 iterador e operador++()
67 const iterador e operador++(
int i)
73 modelo<
typename,
typename>
74 amigo estrutura, estrutura managed;
76 iterador(
size_t i,
managed<std::set<T>>* pai)
77 : m_i(i), m_parent(parent)
85 retorna o iterador(0,
este);
90 return iterador(tamanho(),
isto);
92 [[nodiscard]] std::set<T> detach()
const {
94 auto ret = std::set<T>();
95 para(
size_t i = 0; i < set.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 std::make_shared<realm::collection_callback_wrapper>(
107 token.m_realm = *m_realm;
112 anular apagamento ( iterador
const e it)
114 auto set = internal::bridge::set(*m_realm, *m_obj, m_key);
115 set.remove(serialize(*it));
118 std::pair<iterator, bool> insert(
const T& v)
120 auto set = internal::bridge::set(*m_realm, *m_obj, m_key);
121 se constexpr (internal::type_info::MixedPersistableConcept<T>::value) {
122 std::pair<size_t, bool> res = set.insert(serialize<T>(v));
123 return std::pair<iterator, bool>(iterator(res.first,
esta), res.second);
125 std::pair<size_t, bool> res = set.insert(v);
126 return std::pair<iterator, bool>(iterator(res.first,
esta), res.second);
130 inserção do iterador( iterador
const &,
const T& v)
132 auto set = internal::bridge::set(*m_realm, *m_obj, m_key);
133 std::pair<size_t, bool> res = set.insert(v);
134 return iterator(res.first,
isto);
137 iterador find(
const T& v)
139 auto set = internal::bridge::set(*m_realm, *m_obj, m_key);
140 size_t idx = set.find(serialize(v));
141 se (idx == Realm::not_in_collection)
142 return iterador(tamanho(),
isto);
143 return iterador(idx,
isto);
146 internal::bridge::set(*m_realm, *m_obj, m_key).remove_all();
151 return internal::bridge::set(*m_realm, *m_obj, m_key.size();
156 managed(
const managed&) =
delete;
157 managed(managed &&) =
excluir;
158 managed& operator=(
const managed&) =
excluir;
159 managed& operator=(managed&&) =
excluir;
160 modelo<
typename,
typename>
161 amigo estrutura managed;
166 Usando gerenciado<std::set<T*>>::managed_base::operator=;
173 usando change_type = std::ptrdiff_t;
174 usando ponteiro = T*;
175 usando reference = T&;
176 usando iterator_category = std::forward_iterator_tag;
178 operador de
bool !=(
const iterador e outros)
const
180 return !(*
isto == outro);
183 operador de
bool ==( iterador
const e outro)
const
185 return (m_parent == other.m_parent) && (m_i == other.m_i);
191 managed<T> m(s.get_obj(m_i), *m_parent->m_realm);
192 return {std::move(m)};
195 iterador e operador++()
201 const iterador e operador++(
int i)
207 modelo<
typename,
typename>
208 amigo estrutura, estrutura managed;
210 iterador(
size_t i,
managed<std::set<T*>>* pai)
211 : m_i(i), m_parent(parent)
219 retorna o iterador(0,
este);
224 return iterador(tamanho(),
isto);
226 [[nodiscard]] std::set<T*> detach()
const {
228 contagem
size_t = s.size();
230 return std::set<T*>();
231 auto ret = std::set<T*>();
232 for(
size_t i = 0; i < count; i++) {
233 managed<T> m(s.get_obj(i), *m_realm);
235 auto assign = [&m, &v](
auto& emparelh) {
236 (*v).*(std::decay_t<
decltype(pair.first)>::ptr) = (m.*(pair.second)).detach();
238 auto zipped = internal::zip_tuples(managed<T>::schema.ps, managed<T>::managed_pointers());
239 std::apply([&v, &m, &assign](
auto && ...pair) {
249 auto set = std::make_shared<realm::internal::bridge::set>(*m_realm, *m_obj, m_key);
251 std::make_shared<realm::collection_callback_wrapper>(
254 token.m_realm = *m_realm;
259 anular apagamento ( iterador
const e it)
261 auto set = internal::bridge::set(*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 set = internal::bridge::set(*m_realm, *m_obj, m_key);
268 auto table = m_obj->get_target_table(m_key);
269 internal::bridge::obj m_obj;
270 se constexpr (managed<T>::schema.HasPrimaryKeyProperty) {
271 auto pk = (*value).*(managed<T>::schema.primary_key().ptr);
274 m_obj = table.create_object();
276 std::apply([&m_obj, &value, Realm = *m_realm](
auto && ...p) {
277 (acessador <
typename std::decay_t <
decltype(p)>::Result>::set(
278 m_obj, m_obj.get_table().get_column_key(p.name), domínio,
279 (*value).*(std::decay_t<
decltype(p)>::ptr)), ...);
280 }, managed<T, null>::schema.ps);
281 se (!managed<T>::schema.is_embedded()) {
282 set.insert(m_obj.get_key());
284 std::pair<size_t, bool> res = set.insert(m_obj.get_key());
285 return std::pair<iterator, bool>(iterator(res.first,
esta), res.second);
288 inserção do iterador( iterador
const &, valor T*)
290 auto set = internal::bridge::set(*m_realm, *m_obj, m_key);
291 auto table = m_obj->get_target_table(m_key);
292 internal::bridge::obj m_obj;
293 se constexpr (managed<T>::schema.HasPrimaryKeyProperty) {
294 auto pk = (*value).*(managed<T>::schema.primary_key().ptr);
297 m_obj = table.create_object();
299 std::apply([&m_obj, &value, Realm = *m_realm](
auto && ...p) {
300 (acessador <
typename std::decay_t <
decltype(p)>::Result>::set(
301 m_obj, m_obj.get_table().get_column_key(p.name), domínio,
302 (*value).*(std::decay_t<
decltype(p)>::ptr)), ...);
303 }, managed<T, null>::schema.ps);
304 std::pair<size_t, bool> res = set.insert(m_obj.get_key());
305 return iterator(res.first,
isto);
308 std::pair<iterator, bool> insert(
const managed<T>& value)
310 auto set = internal::bridge::set(*m_realm, *m_obj, m_key);
311 std::pair<size_t, bool> res = set.insert(value.m_obj.get_key());
312 return std::pair<iterator, bool>(iterator(res.first,
esta), res.second);
316 inserção do iterador(
const iterador&,
const gerenciado<T>& valor)
318 auto set = internal::bridge::set(*m_realm, *m_obj, m_key);
319 std::pair<size_t, bool> res = set.insert(value.m_obj.get_key());
320 return iterator(res.first,
isto);
323 std::pair<iterator, bool> insert(
const managed<T*>& value)
325 auto set = internal::bridge::set(*m_realm, *m_obj, m_key);
326 std::pair<size_t, bool> res = set.insert(value.m_obj.get_key());
327 return std::pair<iterator, bool>(iterator(res.first,
esta), res.second);
331 inserção do iterador(
const iterador&,
const gerenciado<T*>& valor)
333 auto set = internal::bridge::set(*m_realm, *m_obj, m_key);
334 std::pair<size_t, bool> res = set.insert(value.m_obj.get_key());
335 return iterator(res.first,
isto);
338 iterador find(
const managed<T>& v)
340 auto set = internal::bridge::set(*m_realm, *m_obj, m_key);
341 size_t idx = set.find(v.m_obj.get_key());
342 se (idx == Realm::not_in_collection)
343 return iterador(tamanho(),
isto);
344 return iterador(idx,
isto);
347 iterador find(
const managed<T*>& v)
349 auto set = internal::bridge::set(*m_realm, *m_obj, m_key);
350 size_t idx = set.find(v.m_obj->get_key());
351 se (idx == Realm::not_in_collection)
352 return iterador(tamanho(),
isto);
353 return iterador(idx,
isto);
356 internal::bridge::set(*m_realm, *m_obj, m_key).remove_all();
361 return internal::bridge::set(*m_realm, *m_obj, m_key.size();
366 managed(
const managed&) =
delete;
367 managed(managed &&) =
excluir;
368 managed& operator=(
const managed&) =
excluir;
369 managed& operator=(managed&&) =
excluir;
370 modelo<
typename,
typename>
371 amigo estrutura managed;
Definição: observação.hpp:176
Definição: macros.hpp:286
Definição: notificações.hpp:38