19#ifndef CPPREALM_ACCESSORS_HPP
20#define CPPREALM_ACCESSORS_HPP
22#include <cpprealm/internal/bridge/lnklst.hpp>
23#include <cpprealm/internal/bridge/obj.hpp>
24#include <cpprealm/internal/bridge/realm.hpp>
25#include <cpprealm/internal/bridge/table.hpp>
26#include <cpprealm/types.hpp>
32 template <
typename T,
typename =
void >
45 const int 64 _t& value) {
50 struct 访问器<std::Optional<int 64 _t>> {
54 const std::Optional<int 64 _t>& value) {
67 const double & value) {
76 const std::Optional<double>& value) {
98 const std::Optional<bool>& value) {
100 obj.set(key, *value);
108 template <
typename T>
109 struct accessor <T, std::enable_if_t<std::is_enum_v<T>>> {
114对象。 设立(key,
static_cast< int 64 _t
> (value));
117 template <
typename T>
118 struct accessor <T, std::enable_if_t<std::conjunction_v<internal::type_info::is_Optional<T>, std::is_enum<typename T::value_type>>>> {
124 obj.set(key,
static_cast< int 64 _t
> (*value));
131 template <
typename T>
132 struct accessor <T, std::enable_if_t<internal::type_info::MixedPersistableConcept<T>::value>> {
137对象。 设立(key,serialize(value));
156 const std::Optional<uuid>& value) {
158 obj.set(key, *value);
178 const std::Optional<object_id>& value) {
180 obj.set(key, *value);
197 struct 访问器<std::Optional<decimal 128 >> {
201 const std::Optional<decimal 128 >& value) {
203 obj.set(key, *value);
211 struct accessor <std::chrono::time_point<std::chrono::system_clock>> {
215 const std::chrono::time_point<std::chrono::system_clock>& value) {
220 struct accessor <std::Optional<std::chrono::time_point<std::chrono::system_clock>>> {
224 const std::Optional<std::chrono::time_point<std::chrono::system_clock>>& value) {
226 obj.set(key, *value);
238 const std::string& value) {
247 const std::Optional<std::string>& value) {
249 obj.set(key, *value);
257 struct 访问器<std::vector<uint 8 _t>> {
261 const std::vector<uint 8 _t>& value) {
266 struct 访问器<std::Optional<std::vector<uint 8 _t>>> {
270 const std::Optional<std::vector<uint 8 _t>>& value) {
272 obj.set(key, *value);
278 template <
typename T>
283 const std::vector<T>& value) {
284 obj.set_list_values(key, value);
287 template <
typename T>
292 const std::vector<T*>& value) {
293 auto list = obj.get_linklist(key);
294 for (
size_t i = 0 ; i < value.size(); i++) {
295 auto & lnk = value[i];
299 auto tab = obj.get_target_table(key);
305 m_obj = list.create_and_insert_linked_object(i);
307 m_obj = table.create_object();
309 std::apply([&m_obj, &lnk, &realm](
auto && ...p) {
310 (
accessor <
typename std::decay_t<
decltype (p)>::Result>::set(
311 m_obj, m_obj.get_table().get_column_key(p.name), Realm,
312 (*lnk).*(std::decay_t<
decltype (p)>::ptr)), ...);
315 list.add(m_obj.get_key());
320 template <
typename T>
325 const std::set<T>& value) {
327 for (
const auto & v : value) {
328 设立.insert(serialize(v));
332 template <
typename T>
337 const std::set<T*>& value) {
339 for (
const auto & lnk : value) {
343 auto tab = obj.get_target_table(key);
349 m_obj = table.create_object();
351 std::apply([&m_obj, &lnk, &realm](
auto && ...p) {
352 (
accessor <
typename std::decay_t<
decltype (p)>::Result>::set(
353 m_obj, m_obj.get_table().get_column_key(p.name), Realm,
354 (*lnk).*(std::decay_t<
decltype (p)>::ptr)), ...);
357 set.insert(m_obj.get_key());
362 template <
typename T>
367 const std::map<std::string, T>& value) {
368 auto d = obj.get_dictionary(key);
369 for (
auto & [k, v] : value) {
370 if constexpr (internal::type_info::MixedPersistableConcept<T>::value) {
371 d.insert(k, std::visit([](
auto && arg) {
377 if constexpr (std::is_enum_v<typename T::value_type>) {
379 d.insert(k,
static_cast< typename std::underlying_type<typename T::value_type>::type
> (*v));
395 template <
typename T>
400 const std::map<std::string, T*>& value) {
401 auto d = obj.get_dictionary(key);
402 for (
auto & [k, v] : value) {
407 m_obj = d.create_and_insert_linked_object(k, pk.value);
409 m_obj = d.create_and_insert_linked_object(k);
411 std:: 应用([&m_obj, &realm, o = *v](
auto && ...p) {
412 (
accessor <
typename std::decay_t<
decltype (p)>::Result>::set(
413 m_obj, m_obj.get_table().get_column_key(p.name), Realm,
414 o.*(std::decay_t<
decltype (p)>::ptr)), ...);
416 d.insert(k, m_obj.get_key());
第 425 章 template <
typename T>
第 434 章 auto tab = obj.get_target_table(key);
439 obj.set(key, m_obj.get_key());
441 m_obj = obj.create_and_set_linked_object(key);
443 m_obj = table.create_object();
444 obj.set(key, m_obj.get_key());
446 std::apply([&m_obj, &realm, &value](
auto && ...p) {
447 (
accessor <
typename std::decay_t<
decltype (p)>::Result>::set(
448 m_obj, m_obj.get_table().get_column_key(p.name), Realm,
449 (*value).*(std::decay_t<
decltype (p)>::ptr)), ...);
第 454 章 template <auto T>
第 463 章 template <
typename T>
469 if constexpr (std::is_enum_v<T>) {
470 obj.set(key,
static_cast< int 64 _t
> (value.value));
472 obj.set(key, value.value);
定义: managed_primary_key.hpp:30