19#ifndef CPPREALM_MANAGED_MIXED_HPP
20#define CPPREALM_MANAGED_MIXED_HPP
22#include <cpprealm/macros.hpp>
23#include <cpprealm/rbool.hpp>
24#include <cpprealm/types.hpp>
28 struct managed<T, std::enable_if_t<realm::internal::type_info::MixedPersistableConcept<T>::value>> :
public managed_base {
29 using managed<T>::managed_base::operator=;
49 managed& operator =(
const T& v) {
50 m_obj->set(m_key, std::visit([](
auto&& arg) {
58 managed& operator =(
const U& v) {
63 [[nodiscard]] stored_type get_stored_type()
const {
66 return stored_type::Null;
68 return static_cast<stored_type
>(val.type());
72 [[nodiscard]] T detach()
const {
76 [[nodiscard]] T operator *()
const {
81 rbool operator==(
const T& rhs)
const noexcept {
82 if (this->m_rbool_query) {
83 return this->m_rbool_query->mixed_equal(m_key, serialize(rhs));
85 return detach() == rhs;
88 rbool operator!=(
const T& rhs)
const noexcept {
89 if (this->m_rbool_query) {
90 return this->m_rbool_query->mixed_not_equal(m_key, serialize(rhs));
92 return detach() != rhs;
95 rbool operator==(
const std::nullopt_t&)
const noexcept {
96 if (this->m_rbool_query) {
99 return detach() == T(std::monostate());
102 rbool operator!=(
const std::nullopt_t&)
const noexcept {
103 if (this->m_rbool_query) {
106 return detach() != T(std::monostate());
109 bool has_link()
const {
110 return (get_stored_type() == stored_type::TypedLink);
115 m_realm->read_group();
119 uint32_t alternative_key = m_realm->table_for_object_type(
managed<std::remove_pointer_t<U>>::schema.name).get_key();
120 uint32_t stored_table = obj.get_obj().get_table().get_key();
122 if (alternative_key != stored_table) {
123 throw std::runtime_error(
"Different link type stored in mixed type. Stored type: " + obj.get_object_schema().get_name());
128 template <
typename U>
129 void set_link(U &&v) {
130 static_assert(
sizeof(
managed<U>),
"Must declare schema for T");
131 static_assert(
managed<U>::object_type == ObjectType::TopLevel,
"Mixed properties can only store Top Level objects.");
138 o = table.create_object();
141 std::apply([&o, &v,
this](
auto && ...p) {
142 (
accessor<
typename std::decay_t<
decltype(p)>::Result>::set(
143 o, o.get_table().get_column_key(p.name), *this->m_realm, v.*(std::decay_t<
decltype(p)>::ptr)
161 template<
typename,
typename>
165 template<
typename T,
typename Types>
167 auto val = v.get_stored_type();
170 if constexpr (std::is_same_v<T, int64_t>)
174 if constexpr (std::is_same_v<T, bool>)
178 if constexpr (std::is_same_v<T, std::string>)
182 if constexpr (std::is_same_v<T, std::vector<uint8_t>>)
186 if constexpr (std::is_same_v<T, Types>)
190 if constexpr (std::is_same_v<T, std::chrono::time_point<std::chrono::system_clock>>)
194 if constexpr (std::is_same_v<T, float>)
198 if constexpr (std::is_same_v<T, double>)
202 if constexpr (std::is_same_v<T, realm::decimal128>)
206 if constexpr (std::is_same_v<T, realm::object_id>)
211 if constexpr (std::is_same_v<T, realm::uuid>)
215 if constexpr (std::is_same_v<T, std::monostate>)
219 if constexpr (std::is_pointer_v<T>) {
220 auto m = v.m_obj->template get<internal::bridge::mixed>(v.m_key);
221 uint32_t alternative_key = v.m_realm->table_for_object_type(
managed<std::remove_pointer_t<T>>::schema.name).get_key();
223 return alternative_key == stored_key;
Definition: accessors.hpp:33
Definition: obj_key.hpp:53
Definition: object.hpp:154
Definition: macros.hpp:286