#pragma once #include #include "context.h" namespace cpphibernate { namespace __impl { /* init_builder */ template struct init_builder { template static constexpr decltype(auto) apply(T_args&&...) { static_assert(sizeof...(T_args) == -1, "Invalid parameters for context::init(...)!"); } }; constexpr decltype(auto) init = mp::generic_predicate { }; template struct init_builder< mp::list, mp::enable_if_t< mp::is_valid_v().init(std::declval()))> && mp::is_same_v> >> { static constexpr decltype(auto) apply(T_impl& impl, bool recreate) { return impl.init(recreate); } }; /* create_builder */ template struct create_builder { template static constexpr decltype(auto) apply(T_args&&...) { static_assert(sizeof...(T_args) == -1, "Invalid parameters for context::create(...)!"); } }; constexpr decltype(auto) create = mp::generic_predicate { }; template struct create_builder< mp::list, mp::enable_if_t< mp::is_valid_v().create(std::declval()))> >> { static constexpr decltype(auto) apply(T_impl& impl, T_dataset& dataset) { return impl.create(dataset); } }; /* read_builder */ template struct read_builder { template static constexpr decltype(auto) apply(T_args&&...) { static_assert(sizeof...(T_args) == -1, "Invalid parameters for context::read(...)!"); } }; constexpr decltype(auto) read = mp::generic_predicate { }; template struct read_builder< mp::list, mp::enable_if_t< schema::is_schema_v> && is_modifiers_v> && mp::is_valid_v().read( std::declval(), std::declval()))> >> { static constexpr decltype(auto) apply(const T_schema& schema, T_impl& impl, T_dataset& dataset, T_modifiers&& modifiers) { return impl.read(dataset, std::forward(modifiers)); } }; template struct read_builder< mp::list, mp::enable_if_t< schema::is_schema_v> && !is_container_v> && !is_nullable_v> >> { static constexpr decltype(auto) apply(const T_schema& schema, T_impl& impl, T_dataset& dataset) { using real_dataset_type = real_dataset_t>; auto& table = schema::find_table(schema.tables, hana::type_c); auto& primary_key = schema::get_primary_key_field(table); return impl.read(dataset, make_modifiers(where(equal(primary_key, primary_key.getter(dataset))))); } }; template struct read_builder< mp::list, mp::enable_if_t< schema::is_schema_v> && mp::is_true_v...> && ( is_container_v> || is_nullable_v>) >> { static constexpr decltype(auto) apply(const T_schema& schema, T_impl& impl, T_dataset& dataset, T_modifier&&... modifier) { return impl.read(dataset, make_modifiers(std::forward(modifier)...)); } }; template struct read_builder< mp::list, mp::enable_if_t< schema::is_schema_v> && mp::is_true_v...> && !is_container_v> && !is_nullable_v> && sizeof...(T_modifier) >> { static constexpr decltype(auto) apply(const T_schema& schema, T_impl& impl, T_dataset& dataset, T_modifier&&... modifier) { return impl.read(dataset, make_modifiers(std::forward(modifier)...)); } }; /* update_builder */ template struct update_builder { template static constexpr decltype(auto) apply(T_args&&...) { static_assert(sizeof...(T_args) == -1, "Invalid parameters for context::update(...)!"); } }; constexpr decltype(auto) update = mp::generic_predicate { }; template struct update_builder< mp::list, mp::enable_if_t< mp::is_valid_v().update(std::declval()))>>> { static constexpr decltype(auto) apply(T_impl& impl, T_dataset& dataset) { return impl.update(dataset); } }; /* destroy_builder */ template struct destroy_builder { template static constexpr decltype(auto) apply(T_args&&...) { static_assert(sizeof...(T_args) == -1, "Invalid parameters for context::destroy(...)!"); } }; constexpr decltype(auto) destroy = mp::generic_predicate { }; template struct destroy_builder< mp::list, mp::enable_if_t< mp::is_valid_v().destroy(std::declval()))>>> { static constexpr decltype(auto) apply(T_impl& impl, T_dataset& dataset) { return impl.destroy(dataset); } }; } /* context */ template template constexpr context::context(const schema_type& p_schema, T_args&&... p_args) : base_type (p_schema, std::forward(p_args)...) , _schema (p_schema) { } template template constexpr decltype(auto) context::init(T_args&&... args) { return __impl::init(this->impl(), std::forward(args)...); } template template constexpr decltype(auto) context::create(T_args&&... args) { return __impl::create(this->impl(), std::forward(args)...); } template template constexpr decltype(auto) context::read(T_args&&... args) { return __impl::read(_schema, this->impl(), std::forward(args)...); } template template constexpr decltype(auto) context::update(T_args&&... args) { return __impl::update(this->impl(), std::forward(args)...); } template template constexpr decltype(auto) context::destroy(T_args&&... args) { return __impl::destroy(this->impl(), std::forward(args)...); } /* make_context */ template constexpr decltype(auto) make_context(T_schema&& schema, T_args&&... args) { using context_type = context; return context_type(std::forward(schema), std::forward(args)...); } /* make_context_ptr */ template constexpr decltype(auto) make_context_ptr(T_schema&& schema, T_args&&... args) { using context_type = context; using pointer_type = std::unique_ptr; return pointer_type(new context_type(std::forward(schema), std::forward(args)...)); } }