19#ifndef CPPREALM_TYPE_INFO_HPP
20#define CPPREALM_TYPE_INFO_HPP
22#include <cpprealm/internal/bridge/property.hpp>
23#include <cpprealm/internal/bridge/uuid.hpp>
24#include <cpprealm/internal/bridge/binary.hpp>
25#include <cpprealm/internal/bridge/timestamp.hpp>
26#include <cpprealm/internal/bridge/mixed.hpp>
27#include <cpprealm/internal/bridge/obj_key.hpp>
28#include <cpprealm/internal/bridge/list.hpp>
29#include <cpprealm/internal/bridge/dictionary.hpp>
30#include <cpprealm/internal/bridge/object_id.hpp>
31#include <cpprealm/internal/bridge/decimal128.hpp>
32#include <cpprealm/internal/bridge/set.hpp>
39 struct linking_objects;
43namespace realm::internal::type_info {
44 template <
typename T,
typename =
void>
48 template <
template <
typename>
typename Optional,
typename T>
50 std::enable_if_t<std::is_same_v<std::optional<T>, Optional<T>>>> : std::true_type {
53 template <
typename T,
typename =
void>
55 static constexpr auto value =
false;
59 static constexpr auto value =
true;
61 template <
typename T,
typename =
void>
63 static constexpr auto value =
false;
66 struct is_set<std::set<T>> : std::true_type {
67 static constexpr auto value =
true;
69 template <
typename T,
typename =
void>
74 struct is_map<std::map<std::string, T>> : std::true_type {
77 template <
typename,
typename>
79 template <
typename T,
typename =
void>
84 using is_primitive = std::negation<std::disjunction<
85 std::is_same<typename type_info<T>::internal_type, std::optional<bridge::obj_key>>,
87 std::is_same<typename type_info<T>::internal_type,
bridge::list>,
91 template <
typename T,
typename =
void>
92 struct is_variant_t : std::false_type {};
93 template <
template <
typename ...>
typename Variant,
typename ...Ts>
94 struct is_variant_t<Variant<Ts...>, std::enable_if_t<std::is_same_v<std::variant<Ts...>, Variant<Ts...>>>>
98 template<
size_t N,
typename Variant>
99 constexpr bool check_variant_types() {
100 if constexpr (!is_variant_t<Variant>::value) {
102 }
else if constexpr (N >= std::variant_size_v<Variant>) {
105 if constexpr (std::is_same_v<std::variant_alternative_t<N, Variant>, std::monostate>) {
106 return check_variant_types<N + 1, Variant>();
107 }
else if constexpr (is_primitive<std::variant_alternative_t<N, Variant>>::value) {
108 return check_variant_types<N + 1, Variant>();
116 using MixedPersistableConcept =
117 std::conjunction<is_variant_t<T>,
118 std::conditional_t<check_variant_types<0, T>(), std::true_type, std::false_type>
122 static_assert(std::conjunction<
123 std::is_convertible<int, int64_t>,
124 std::is_constructible<int, int64_t>>::value);
125 static_assert(std::conjunction<
126 std::is_convertible<const char*, std::string>,
127 std::is_constructible<std::string, const char*>>::value);
130 template <
typename T>
133 static constexpr bridge::property::type type() {
134 return bridge::property::type::Object;
140 static constexpr bridge::property::type type() {
141 return bridge::property::type::LinkingObjects | bridge::property::type::Array;
144 template <
typename T>
146 static constexpr auto value =
false;
147 static constexpr auto is_managed =
false;
149 template <
typename T>
151 static constexpr auto value =
true;
152 static constexpr auto is_managed =
true;
154 template <
typename T>
156 static constexpr auto value =
true;
157 static constexpr auto is_managed =
false;
160 template <
typename T>
162 static constexpr auto value =
false;
166 static constexpr auto value =
true;
170 using internal_type = std::monostate;
171 static constexpr bridge::property::type type() {
172 return bridge::property::type::Mixed;
177 using internal_type = std::string;
178 static constexpr bridge::property::type type() {
179 return bridge::property::type::String;
184 using internal_type = std::string;
185 static constexpr bridge::property::type type() {
186 return bridge::property::type::String;
191 using internal_type = int64_t;
192 static constexpr bridge::property::type type() {
193 return bridge::property::type::Int;
198 using internal_type = int64_t;
199 static constexpr bridge::property::type type() {
200 return bridge::property::type::Int;
205 using internal_type = double;
206 static constexpr bridge::property::type type() {
207 return bridge::property::type::Double;
212 using internal_type = bool;
213 static constexpr bridge::property::type type() {
214 return bridge::property::type::Bool;
220 static constexpr bridge::property::type type() {
221 return bridge::property::type::UUID;
227 static constexpr bridge::property::type type() {
228 return bridge::property::type::ObjectId;
234 static constexpr bridge::property::type type() {
235 return bridge::property::type::Decimal;
241 static constexpr bridge::property::type type() {
242 return bridge::property::type::Data;
245 template <
typename E>
246 struct type_info<E, std::enable_if_t<std::is_enum_v<E>>> {
247 using internal_type = int64_t;
248 static constexpr bridge::property::type type() {
249 return bridge::property::type::Int;
252 template <
typename ValueType>
255 static constexpr bridge::property::type type() {
259 template <
typename ValueType>
262 static constexpr bridge::property::type type() {
266 template <
typename T>
267 struct type_info<T, std::enable_if_t<MixedPersistableConcept<T>::value>> {
270 static constexpr auto type() {
271 return bridge::property::type::Mixed | bridge::property::type::Nullable;
274 template <
typename T>
276 using internal_type = std::optional<typename type_info<T>::internal_type>;
277 static constexpr auto type() {
281 template <
typename C,
typename D>
284 static constexpr auto type() {
285 return bridge::property::type::Date;
288 template <
typename V>
289 struct type_info<std::vector<V>, std::enable_if_t<std::negation_v<std::is_same<V, uint8_t>>>> {
291 static constexpr auto type() {
296 template <
typename T>
298 static constexpr auto value =
false;
300 template <
typename T>
302 static constexpr auto value =
true;
305 template <
typename T>
308 static constexpr bridge::property::type type() {
Definition: binary.hpp:30
Definition: decimal128.hpp:30
Definition: dictionary.hpp:138
Definition: obj_key.hpp:33
Definition: object_id.hpp:31
Definition: timestamp.hpp:30
Definition: type_info.hpp:161
Definition: type_info.hpp:145
Definition: type_info.hpp:70
Definition: type_info.hpp:45
Definition: type_info.hpp:297
Definition: type_info.hpp:62
Definition: type_info.hpp:54
Definition: type_info.hpp:78
Definition: results.hpp:419
Definition: managed_primary_key.hpp:30