19#ifndef CPPREALM_SCHEMA_HPP
20#define CPPRALM_SCHEMA_HPP
22#include <cpprealm/link.hpp>
23#include <cpprealm/internal/bridge/lnklst.hpp>
24#include <cpprealm/internal/bridge/object_schema.hpp>
25#include <cpprealm/internal/bridge/realm.hpp>
26#include <cpprealm/internal/bridge/table.hpp>
27#include <cpprealm/internal/type_info.hpp>
43 template <
typename 결과,
typename 클래스>
46 using class_type = Class;
47 using member_type = Result;
54 template<
typename... Typescript>
55 constexpr auto make_subpack_tuple(Ts&&... xs)
57 return std::tuple<Ts...>(std::forward<Ts>(xs)...);
69 템플릿 <auto Ptr,
bool IsPrimaryKey = false>
76 static constexpr 자동 ptr = Ptr;
78 internal::bridge::property::type type;
79 const char* name =
"";
84 명시적 constexpr 속성(
const char* real_name)
93 만약 constexpr (std::is_pointer_v<typename Result::value_type>) {
94 속성.set_object_link(
관리되는<std::remove_pointer_t<typename Result::value_type>,
oid>::schema.name);
97 만약 constexpr (std::is_pointer_v<typename Result::value_type>) {
98 속성.set_object_link(
관리되는<std::remove_pointer_t<typename Result::value_type>,
oid>::schema.name);
103 속성.set_object_link(
managed<std::remove_pointer_t<typename Result::
mapped_type ::value_type>, oid >:: 스키마.name);
104 속성.set_type(type | internal::bridge::property::type::Nullable);
106 }
다른 경우 if constexpr (std::is_pointer_v<typename Result::mapped_type>) {
107 속성.set_object_link(
managed<std::remove_pointer_t<typename Result::
mapped_type>, oid >:: 스키마.name);
108 속성.set_type(type | internal::bridge::property::type::Nullable);
110 }
다른 경우 if constexpr (std::is_pointer_v<Result>) {
111 속성.set_object_link (
관리<
유형 이름 std::remove_pointer_t<Result>,
oid>::schema.name);
112 속성.set_type(type | internal::bridge::property::type::Nullable);
121 template <
typename T,
typename ... types>
126 template <
template<
typename...>
typename Variant,
typename... VariantTypes,
typename NextType,
typename... RemainingTypes>
129 std::dis Junction< std::is_same<NextType, VariantTypes> ... >::value
130 , unique_variant<Variant<VariantTypes...>, RemainingTypes...>
131 , unique_variant<Variant<VariantTypes..., NextType>, RemainingTypes...>
135 템플릿 <
typename class,
typename 속성>
138 const char *names[
sizeof...(Properties)] = {};
139 const char *primary_key_name =
"";
141 static constexpr std::tuple<Properties...> properties{};
145 constexpr auto do_apply_name(
const std::tuple<Properties...> &tup) {
146 만약 constexpr (N + 1 ==
sizeof...(Properties)) {
147 이름[N] = std::get<N>(tup).name;
148 if (std::get<N>(tup).is_primary_key) {
149 primary_key_name = std::get<N>(tup).name;
153 이름[N] = std::get<N>(tup).name;
154 if (std::get<N>(tup).is_primary_key) {
155 primary_key_name = std::get<N>(tup).name;
157 return do_apply_name<N + 1>(tup);
161 constexpr auto apply_name(
const std::tuple<Properties...> &tup) {
162 return do_apply_name<0>(tup);
165 std::tuple<Properties...> ps;
167 명시적 constexpr schema(
const char *name_, 속성 &&... props)
170 auto tup = std::make_tuple(props...);
173 명시적 constexpr schema(
const char *name_, std::tuple<Properties...>&& props)
178 명시적 constexpr 스키마(
const char *name_, ObjectType object_type, std::tuple<Properties...>&& props)
180 , ps(props), m_object_type(object_type) {
183 템플릿<
size_t N,
typename P>
185 만약 constexpr (P::is_primary_key) {
188 만약 constexpr (N + 1 ==
sizeof...(Properties)) {
201 static constexpr bool HasPrimaryKeyProperty = !std::is_oid_v<PrimaryKeyProperty>;
203 bool is_embedded()
const {
204 return m_object_type == ObjectType::Embedded;
212 if (!p.name().empty()) {
216 std:: 적용([&](
const auto&... p) {
217 (add_property(p), ...);
220 만약 constexpr (HasPrimaryKeyProperty) {
221 schema.set_primary_key(primary_key_name);
223 if (m_object_type == ObjectType::Embedded) {
224 schema.set_object_type(internal::bridge::object_schema::object_type::Embedded);
226 if (m_object_type == ObjectType::Asymmetric) {
227 schema.set_object_type(internal::bridge::object_schema::object_type::TopLevelAsymmetric);
232 템플릿<
size_t N,
typename P>
233 constexpr auto set(Class &
object, P &
속성)
const {
234 만약 constexpr (N + 1 ==
sizeof...(Properties)) {
239 return 설정하다<N + 1>(
객체, std::get<N + 1>(properties));
243 템플릿<
size_t N,
typename P>
245 속성 값_for_name(std::string_view 속성 이름,
const 관리<클래스, 무효> &cls, P &
속성,
bool linking_collections =
true)
const {
246 bool is_array = 영역::internal::bridge::property_has_flag(
속성.type, 영역::internal::bridge:: 속성::type::Array);
247 bool is_dictionary = 영역::internal::bridge::property_has_flag(
속성.type, 영역::internal::bridge:: 속성::type::Dictionary);
248 bool is_set = 영역::internal::bridge::property_has_flag(
속성.type, 영역::internal::bridge:: 속성::type::Set);
249 bool is_collection = is_array || is_dictionary || is_set;
250 if (제외 컬렉션 && is_collection) {
251 return variant_t{std::monostate()};
254 만약 constexpr (N + 1 ==
sizeof...(Properties)) {
255 if (property_name == std::string_view(names[N])) {
257 만약 constexpr (std::is_pointer_v<typename P::Result>) {
260 return (cls.*ptr).detach();
265 if (property_name == std::string_view(names[N])) {
267 만약 constexpr (std::is_pointer_v<typename P::Result>) {
270 return (cls.*ptr).detach();
273 return Property_value_for_name<N + 1>(property_name, cls, std::get<N + 1>(properties), linking_collections);
276 constexpr 자동 속성 값_for_name(std::string_view 속성 이름,
const managed<클래스, 무효> &cls,
bool linking_collections =
true)
const {
277 return Property_value_for_name<0>(property_name, cls, std::get<0>(properties), linking_collections);
280 템플릿<
size_t N,
typename T,
typename P>
281 constexpr const char*
282 name_for_property(T ptr, P &
속성)
const {
283 만약 constexpr (N + 1 ==
sizeof...(Properties)) {
284 만약 constexpr (std::is_same_v<
decltype(ptr), std::remove_const_t<
decltype(
속성.ptr)>>) {
291 만약 constexpr (std::is_same_v<
decltype(ptr), std::remove_const_t<
decltype(
속성.ptr)>>) {
296 return name_for_property<N + 1>(ptr, std::get<N + 1>(ps));
300 constexpr const char* name_for_property()
const {
301 return name_for_property<0>(ptr, std::get<0>(ps));
304 constexpr const char* name_for_property(T ptr)
const {
305 return name_for_property<0>(ptr, std::get<0>(ps));
308 ObjectType m_object_type = ObjectType::None;
311 템플릿 <auto Ptr,
bool IsPrimaryKey = false>
312 static constexpr auto 속성(
const char* name)
318 static constexpr 자동 스키마(
const char * 이름,
320 auto tup = internal::make_subpack_tuple(props...);
321 auto i = std::get<0>(tup);
322 using Cls =
typename decltype(i)::Class;
323 return schemagen::schema<Cls, T...>(name, std::move(props)...);
327 static constexpr 자동 스키마(
const char * 이름,
328 std::tuple<T...>&& props) {
329 auto i = std::get<0>(props);
330 using Cls =
typename decltype(i)::Class;
331 return schemagen:: 스키마<Cls, T...>(name, std::move(props));
335 static constexpr 자동 스키마(
const char * 이름,
336 ObjectType object_type,
337 std::tuple<T...>&& props) {
338 auto i = std::get<0>(props);
339 using Cls =
typename decltype(i)::Class;
340 return schemagen:: 스키마<Cls, T...>(name, object_type, std::move(props));
정의: managed_primary_key.hpp:30