* fixed some small errors * added options.cmakemaster
@@ -0,0 +1,10 @@ | |||
Option ( CPPHIBERNATE_BUILD_SHARED | |||
"Build cpphibernate shared library" | |||
OFF ) | |||
Option ( CPPHIBERNATE_DEBUG_OUTPUT | |||
"Enable debug output" | |||
OFF ) | |||
If ( CPPHIBERNATE_DEBUG_OUTPUT ) | |||
Add_Definitions ( -DCPPHIBERNATE_DEBUG ) | |||
EndIf ( ) |
@@ -3,8 +3,7 @@ | |||
#include <boost/hana.hpp> | |||
#include <cpputils/mp/core.h> | |||
#define cpphibernate_debug | |||
#ifdef cpphibernate_debug | |||
#ifdef CPPHIBERNATE_DEBUG | |||
# include <cpputils/logging/global.h> | |||
# define cpphibernate_debug_log(...) log_global_message(debug) << __VA_ARGS__ | |||
#else | |||
@@ -7,7 +7,7 @@ | |||
#include <cpphibernate/schema/table.h> | |||
#include <cpphibernate/schema/tables.h> | |||
#include <cpphibernate/modifier/where.h> | |||
#include <cpphibernate/modifier/modifier.h> | |||
#include <cpphibernate/modifier/modifiers.h> | |||
beg_namespace_cpphibernate | |||
{ | |||
@@ -24,7 +24,7 @@ beg_namespace_cpphibernate_driver_mariadb | |||
private: | |||
using transaction_ptr_type = std::unique_ptr<::cppmariadb::transaction>; | |||
#ifdef cpphibernate_debug | |||
#ifdef CPPHIBERNATE_DEBUG | |||
# define debug_log(str) cpphibernate_debug_log( \ | |||
"transaction (id=" << std::setw(8) << std::setfill(' ') << lock.id << \ | |||
", counter=" << std::setw(2) << std::setfill(' ') << counter << ") " str) | |||
@@ -26,6 +26,20 @@ beg_namespace_cpphibernate_driver_mariadb | |||
cpphibernate_copyable(mariadb_driver_t, delete); | |||
cpphibernate_moveable(mariadb_driver_t, default); | |||
inline const ::cppmariadb::connection& connection() const | |||
{ return _connection; } | |||
template<typename... T_args> | |||
inline void set_filter_inclusive(T_args&&... args) | |||
{ _filter.set_inclusive(_schema, std::forward<T_args>(args)...); } | |||
template<typename... T_args> | |||
inline void set_filter_exclusive(T_args&&... args) | |||
{ _filter.set_exclusive(_schema, std::forward<T_args>(args)...); } | |||
inline void clear_filter() | |||
{ _filter.clear(); } | |||
protected: | |||
inline void init_impl(bool recreate) const | |||
{ | |||
@@ -10,6 +10,7 @@ | |||
#include <cpphibernate/driver/mariadb/schema/attributes.h> | |||
#include <cpphibernate/driver/mariadb/schema/field.h> | |||
#include <cpphibernate/driver/mariadb/schema/fields.h> | |||
#include <cpphibernate/driver/mariadb/schema/filter.h> | |||
#include <cpphibernate/driver/mariadb/schema/schema.h> | |||
#include <cpphibernate/driver/mariadb/schema/table.h> | |||
#include <cpphibernate/driver/mariadb/schema/tables.h> | |||
@@ -17,6 +18,7 @@ | |||
#include <cpphibernate/driver/mariadb/schema/attributes.inl> | |||
#include <cpphibernate/driver/mariadb/schema/field.inl> | |||
#include <cpphibernate/driver/mariadb/schema/fields.inl> | |||
#include <cpphibernate/driver/mariadb/schema/filter.inl> | |||
#include <cpphibernate/driver/mariadb/schema/schema.inl> | |||
#include <cpphibernate/driver/mariadb/schema/table.inl> | |||
#include <cpphibernate/driver/mariadb/schema/tables.inl> | |||
#include <cpphibernate/driver/mariadb/schema/schema.inl> | |||
#include <cpphibernate/driver/mariadb/schema/tables.inl> |
@@ -106,11 +106,11 @@ beg_namespace_cpphibernate_driver_mariadb | |||
: public field_t | |||
{ | |||
using base_type = field_t; | |||
using field_type = T_field; | |||
using getter_type = typename mp::decay_t<field_type>::getter_type; | |||
using dataset_type = typename getter_type::dataset_type; | |||
using field_type = mp::decay_t<T_field>; | |||
using getter_type = typename field_type::getter_type; | |||
using dataset_type = mp::decay_t<typename getter_type::dataset_type>; | |||
using real_dataset_type = misc::real_dataset_t<dataset_type>; | |||
using value_type = typename getter_type::value_type; | |||
using value_type = mp::decay_t<typename getter_type::value_type>; | |||
using real_value_type = misc::real_dataset_t<value_type>; | |||
using type_props = type_properties<value_type>; | |||
@@ -5,26 +5,49 @@ | |||
#include <cpphibernate/driver/mariadb/schema/field.fwd.h> | |||
#include <cpphibernate/driver/mariadb/schema/table.fwd.h> | |||
#include <cpphibernate/driver/mariadb/schema/filter.fwd.h> | |||
#include <cpphibernate/driver/mariadb/schema/schema.fwd.h> | |||
beg_namespace_cpphibernate_driver_mariadb | |||
{ | |||
namespace __impl | |||
{ | |||
/* filter_add_element */ | |||
template<typename T, typename = void> | |||
struct filter_add_element_impl; | |||
constexpr decltype(auto) filter_add_element = misc::make_generic_predicate<__impl::filter_add_element_impl> { }; | |||
} | |||
/* filter_t */ | |||
struct filter_t | |||
{ | |||
public: | |||
using field_set_type = std::set<const field_t*>; | |||
using table_set_type = std::set<const table_t*>; | |||
size_t cache_id { 0 }; | |||
bool exclusive; | |||
field_set_type fields; | |||
table_set_type tables; | |||
inline bool is_excluded(const table_t& table) const | |||
{ return tables.count(&table); } | |||
inline bool is_excluded(const table_t& table) const; | |||
inline bool is_excluded(const field_t& field) const; | |||
template<typename... T_args> | |||
inline void set_inclusive(const schema_t& schema, T_args&&... args); | |||
template<typename... T_args> | |||
inline void set_exclusive(const schema_t& schema, T_args&&... args); | |||
inline void clear(); | |||
inline bool is_excluded(const field_t& field) const | |||
{ return fields.count(&field); } | |||
private: | |||
void update_tables(); | |||
}; | |||
} |
@@ -0,0 +1,99 @@ | |||
#pragma once | |||
#include <cpphibernate/driver/mariadb/schema/filter.h> | |||
#include <cpphibernate/driver/mariadb/schema/schema.inl> | |||
beg_namespace_cpphibernate_driver_mariadb | |||
{ | |||
namespace __impl | |||
{ | |||
/* filter_add_element_impl */ | |||
template<typename T, typename> | |||
struct filter_add_element_impl | |||
{ | |||
template<typename... T_args> | |||
static constexpr decltype(auto) apply(T_args&&... args) | |||
{ static_assert(sizeof...(args) == -1, "Invalid parameters for mariadb::filter_add_element(...)!"); } | |||
}; | |||
template<typename T_table> | |||
struct filter_add_element_impl< | |||
mp::list<filter_t&, const schema_t&, T_table>, | |||
mp::enable_if_c< | |||
schema::is_table<mp::decay_t<T_table>>::value>> | |||
{ | |||
static constexpr decltype(auto) apply(filter_t& filter, const schema_t& schema, const T_table& table) | |||
{ | |||
auto dataset_id = misc::get_type_id(table.wrapped_dataset); | |||
auto& t = schema.table(dataset_id); | |||
filter.tables.emplace(&t); | |||
} | |||
}; | |||
template<typename T_field> | |||
struct filter_add_element_impl< | |||
mp::list<filter_t&, const schema_t&, T_field>, | |||
mp::enable_if_c< | |||
schema::is_field<mp::decay_t<T_field>>::value>> | |||
{ | |||
static constexpr decltype(auto) apply(filter_t& filter, const schema_t& schema, const T_field& field) | |||
{ | |||
auto field_id = misc::get_type_id(hana::type_c<mp::decay_t<T_field>>); | |||
auto& f = schema.field(field_id); | |||
filter.fields.emplace(&f); | |||
} | |||
}; | |||
} | |||
/* filter_t */ | |||
bool filter_t::is_excluded(const table_t& table) const | |||
{ | |||
auto ret = static_cast<bool>(tables.count(&table)); | |||
if (!exclusive) | |||
ret = !ret; | |||
return ret; | |||
} | |||
bool filter_t::is_excluded(const field_t& field) const | |||
{ | |||
auto ret = static_cast<bool>(fields.count(&field)); | |||
if (!exclusive) | |||
ret = !ret; | |||
return ret; | |||
} | |||
template<typename... T_args> | |||
void filter_t::set_inclusive(const schema_t& schema, T_args&&... args) | |||
{ | |||
clear(); | |||
exclusive = false; | |||
cache_id = static_cast<size_t>(utl::get_unique_id<filter_t, mp::decay_t<T_args>...>()); | |||
int dummy[] = { 0, (__impl::filter_add_element(*this, schema, std::forward<T_args>(args)), void(), 0)... }; | |||
(void)dummy; | |||
} | |||
template<typename... T_args> | |||
void filter_t::set_exclusive(const schema_t& schema, T_args&&... args) | |||
{ | |||
clear(); | |||
exclusive = true; | |||
cache_id = static_cast<size_t>(utl::get_unique_id<filter_t, mp::decay_t<T_args>...>()); | |||
int dummy[] = { 0, (__impl::filter_add_element(*this, schema, std::forward<T_args>(args)), void(), 0)... }; | |||
(void)dummy; | |||
} | |||
void filter_t::clear() | |||
{ | |||
cache_id = 0; | |||
exclusive = true; | |||
fields.clear(); | |||
tables.clear(); | |||
} | |||
} | |||
end_namespace_cpphibernate_driver_mariadb |
@@ -11,7 +11,17 @@ beg_namespace_cpphibernate_driver_mariadb | |||
template<typename T_schema, typename T_table, typename T_base_dataset> | |||
void table_polymorphic_t<T_schema, T_table, T_base_dataset> | |||
::emplace(const read_context& context) const | |||
{ context.emplace<real_dataset_type>(this); } | |||
{ | |||
hana::eval_if( | |||
std::is_abstract<real_dataset_type> { }, | |||
[](){ | |||
throw misc::hibernate_exception(std::string("can not create dataset of abstract type: ") | |||
+ utl::type_helper<real_dataset_type>::name()); | |||
}, | |||
[&context, this](auto _){ | |||
_(context).template emplace<real_dataset_type>(this); | |||
}); | |||
} | |||
template<typename T_schema, typename T_table, typename T_base_dataset> | |||
template<typename T_dataset, typename T_pred, typename T_include_self> | |||
@@ -1,7 +1,5 @@ | |||
#pragma once | |||
#include <iostream> // TODO debug! | |||
#include <cpphibernate/config.h> | |||
#include <cpputils/misc/type_helper.h> | |||
@@ -143,42 +143,23 @@ beg_namespace_cpphibernate_schema | |||
/* getter_make_impl */ | |||
template<typename X, typename = void> | |||
struct getter_make_impl | |||
{ | |||
template<typename... Args> | |||
static constexpr decltype(auto) apply(Args&&... args) | |||
{ static_assert(sizeof...(args) == -1, "Invalid arguments to schema::getter::make(...)!"); } | |||
}; | |||
template<typename T_dataset, typename T_value> | |||
struct getter_make_impl<mp::list<T_value T_dataset::*>, void> | |||
{ | |||
static constexpr decltype(auto) apply(T_value T_dataset::*member) | |||
template<typename T_dataset, typename T_value> | |||
constexpr decltype(auto) operator()(T_value T_dataset::*member) const | |||
{ return make_getter_member_var(member); } | |||
}; | |||
template<typename T_dataset, typename T_value> | |||
struct getter_make_impl<mp::list<T_value (T_dataset::*)(void)>, void> | |||
{ | |||
static constexpr decltype(auto) apply(T_value (T_dataset::*member)(void)) | |||
template<typename T_dataset, typename T_value> | |||
constexpr decltype(auto) operator()(T_value (T_dataset::*member)(void)) const | |||
{ return make_getter_member_func(member); } | |||
}; | |||
template<typename T_dataset, typename T_value> | |||
struct getter_make_impl<mp::list<T_value (T_dataset::*)(void) const>, void> | |||
{ | |||
static constexpr decltype(auto) apply(T_value (T_dataset::*member)(void) const) | |||
template<typename T_dataset, typename T_value> | |||
constexpr decltype(auto) operator()(T_value (T_dataset::*member)(void) const) const | |||
{ return make_getter_member_func(member); } | |||
}; | |||
template<typename T_func, typename T_wrapped_dataset, typename T_value_type> | |||
struct getter_make_impl<mp::list<T_func, T_wrapped_dataset, T_value_type>, mp::enable_if_c< | |||
hana::is_a<hana::type_tag, mp::decay_t<T_wrapped_dataset>> | |||
&& hana::is_a<hana::type_tag, mp::decay_t<T_value_type>>>> | |||
{ | |||
static constexpr decltype(auto) apply(T_func&& func, T_wrapped_dataset&& wrapped_dataset, T_value_type&& value_type) | |||
{ return make_getter_lambda(std::forward<T_func>(func), std::forward<T_wrapped_dataset>(wrapped_dataset), std::forward<T_value_type>(value_type)); } | |||
template<typename T_func, typename T_dataset, typename T_value> | |||
constexpr decltype(auto) operator()(T_func&& func, hana::type<T_dataset>&& wrapped_dataset, hana::type<T_value>&& wrapped_value) const | |||
{ return make_getter_lambda(std::forward<T_func>(func), std::forward<hana::type<T_dataset>>(wrapped_dataset), std::forward<hana::type<T_value>>(wrapped_value)); } | |||
}; | |||
} | |||
@@ -186,7 +167,7 @@ beg_namespace_cpphibernate_schema | |||
namespace getter | |||
{ | |||
constexpr decltype(auto) make = misc::make_generic_predicate<__impl::getter_make_impl> { }; | |||
constexpr decltype(auto) make = __impl::getter_make_impl { }; | |||
} | |||
@@ -159,42 +159,27 @@ beg_namespace_cpphibernate_schema | |||
/* setter_make_impl */ | |||
template<typename X, typename = void> | |||
struct setter_make_impl | |||
{ | |||
template<typename... Args> | |||
static constexpr decltype(auto) apply(Args&&...) | |||
{ return make_setter_none(); } | |||
}; | |||
template<typename T_dataset, typename T_value> | |||
struct setter_make_impl<mp::list<T_value T_dataset::*>, void> | |||
{ | |||
static constexpr decltype(auto) apply(T_value T_dataset::*member) | |||
template<typename T_dataset, typename T_value> | |||
constexpr decltype(auto) operator()(T_value T_dataset::*member) const | |||
{ return make_setter_member_var(member); } | |||
}; | |||
template<typename T_dataset, typename T_value> | |||
struct setter_make_impl<mp::list<T_value (T_dataset::*)(void)>, void> | |||
{ | |||
static constexpr decltype(auto) apply(T_value (T_dataset::*member)(void)) | |||
template<typename T_dataset, typename T_value> | |||
constexpr decltype(auto) operator()(void (T_dataset::*member)(T_value)) const | |||
{ return make_setter_member_func(member); } | |||
}; | |||
template<typename T_dataset, typename T_value> | |||
struct setter_make_impl<mp::list<T_value (T_dataset::*)(void) const>, void> | |||
{ | |||
static constexpr decltype(auto) apply(T_value (T_dataset::*member)(void) const) | |||
template<typename T_dataset, typename T_value> | |||
constexpr decltype(auto) operator()(void (T_dataset::*member)(T_value&)) const | |||
{ return make_setter_member_func(member); } | |||
}; | |||
template<typename T_func, typename T_wrapped_dataset, typename T_value_type> | |||
struct setter_make_impl<mp::list<T_func, T_wrapped_dataset, T_value_type>, mp::enable_if_c< | |||
hana::is_a<hana::type_tag, mp::decay_t<T_wrapped_dataset>> | |||
&& hana::is_a<hana::type_tag, mp::decay_t<T_value_type>>>> | |||
{ | |||
static constexpr decltype(auto) apply(T_func&& func, T_wrapped_dataset&& wrapped_dataset, T_value_type&& value_type) | |||
{ return make_setter_lambda(std::forward<T_func>(func), std::forward<T_wrapped_dataset>(wrapped_dataset), std::forward<T_value_type>(value_type)); } | |||
template<typename T_dataset, typename T_value> | |||
constexpr decltype(auto) operator()(void (T_dataset::*member)(T_value&&)) const | |||
{ return make_setter_member_func(member); } | |||
template<typename T_func, typename T_dataset, typename T_value> | |||
constexpr decltype(auto) operator()(T_func&& func, hana::type<T_dataset>&& wrapped_dataset, hana::type<T_value>&& wrapped_value) const | |||
{ return make_setter_lambda(std::forward<T_func>(func), std::forward<hana::type<T_dataset>>(wrapped_dataset), std::forward<hana::type<T_value>>(wrapped_value)); } | |||
}; | |||
} | |||
@@ -202,7 +187,7 @@ beg_namespace_cpphibernate_schema | |||
namespace setter | |||
{ | |||
constexpr decltype(auto) make = misc::make_generic_predicate<__impl::setter_make_impl> { }; | |||
constexpr decltype(auto) make = __impl::setter_make_impl { }; | |||
} | |||
@@ -4,9 +4,9 @@ Include ( cotire OPTIONAL ) | |||
Include ( pedantic OPTIONAL ) | |||
Include ( strip_symbols OPTIONAL ) | |||
Option ( BUILD_SHARED_CPPHIBERNATE "Build cpphibernate shared library" OFF ) | |||
Include ( ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/options.cmake ) | |||
Set ( BUILD_SHARED_LIBS ${BUILD_SHARED_CPPHIBERNATE} ) | |||
Set ( BUILD_SHARED_LIBS ${CPPHIBERNATE_BUILD_SHARED} ) | |||
Set ( CMAKE_CXX_STANDARD 17 ) | |||
Set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PEDANTIC_C_FLAGS}" ) | |||
Set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PEDANTIC_CXX_FLAGS}" ) | |||
@@ -7,7 +7,7 @@ | |||
#include <cpphibernate/misc.h> | |||
#include <cpphibernate/driver/mariadb/schema/table.h> | |||
#include <cpphibernate/driver/mariadb/schema/filter.h> | |||
#include <cpphibernate/driver/mariadb/schema/filter.inl> | |||
using namespace ::utl; | |||
using namespace ::cpphibernate; | |||
@@ -4,6 +4,8 @@ Include ( cotire OPTIONAL ) | |||
Include ( pedantic OPTIONAL ) | |||
Include ( cmake_tests OPTIONAL ) | |||
Include ( ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/options.cmake ) | |||
Set ( CMAKE_CXX_STANDARD 17 ) | |||
Set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PEDANTIC_C_FLAGS}" ) | |||
Set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PEDANTIC_CXX_FLAGS}" ) | |||
@@ -1,3 +1,5 @@ | |||
#pragma once | |||
#include <string> | |||
#include <gtest/gtest.h> | |||
#include <gmock/gmock.h> | |||
@@ -1,4 +1,7 @@ | |||
#pragma once | |||
#include <cpphibernate.h> | |||
#include <cpputils/misc/enum.h> | |||
enum class test_enum | |||
{ | |||