small changes in log_manager.cpp and add is_database_primitive type traits and test
This commit is contained in:
parent
018e27a22a
commit
c0e0499204
|
|
@ -161,13 +161,13 @@ template <class CollectionType>
|
|||
void query_result_impl::on_has_many(const char *id, CollectionType &cont, const char *join_column, const utils::foreign_attributes &attr, std::enable_if_t<!object::is_object_ptr<typename CollectionType::value_type>::value> *) {
|
||||
using value_type = typename CollectionType::value_type;
|
||||
auto object_resolver = resolver_->object_resolver<value_type>();
|
||||
auto resolver = resolver_->collection_resolver<typename CollectionType::value_type>(result_type_, join_column);
|
||||
auto resolver = resolver_->collection_resolver<value_type>(result_type_, join_column);
|
||||
|
||||
if (attr.fetch() == utils::fetch_type::Lazy) {
|
||||
cont.reset(std::make_shared<object::collection_proxy<typename CollectionType::value_type>>(resolver, current_pk_));
|
||||
cont.reset(std::make_shared<object::collection_proxy<value_type>>(resolver, current_pk_));
|
||||
} else {
|
||||
if (initialized_collections_.insert({result_type_, typeid(typename CollectionType::value_type), std::string{join_column}}).second) {
|
||||
cont.reset(std::make_shared<object::collection_proxy<typename CollectionType::value_type>>(resolver, std::vector<typename CollectionType::value_type>()));
|
||||
if (initialized_collections_.insert({result_type_, typeid(value_type), std::string{join_column}}).second) {
|
||||
cont.reset(std::make_shared<object::collection_proxy<value_type>>(resolver, std::vector<value_type>()));
|
||||
}
|
||||
|
||||
// read a single value
|
||||
|
|
|
|||
|
|
@ -46,6 +46,23 @@ struct time_type_t {
|
|||
uint32_t microsecond{};
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
template <typename T, typename Variant>
|
||||
struct is_in_variant;
|
||||
|
||||
template <typename T, typename... Alts>
|
||||
struct is_in_variant<T, std::variant<Alts...>>
|
||||
: std::bool_constant<(std::is_same_v<T, Alts> || ...)> {
|
||||
};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct is_database_primitive : detail::is_in_variant<std::remove_cv_t<std::remove_reference_t<T>>, database_type> {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline constexpr bool is_database_primitive_v = is_database_primitive<T>::value;
|
||||
|
||||
void initialize_by_basic_type(basic_type type, database_type &val);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ void log_manager::clear_all_sinks(const std::string &domain_name) {
|
|||
void log_manager::clear() {
|
||||
std::lock_guard lock(mutex_);
|
||||
log_domain_map_.clear();
|
||||
default_log_domain_->clear();
|
||||
}
|
||||
|
||||
void log_manager::max_default_log_level(const log_level max_level) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ add_executable(CoreTests
|
|||
utils/StringTest.cpp
|
||||
utils/ThreadPoolTest.cpp
|
||||
utils/VersionTest.cpp
|
||||
utils/IsDatabasePrimitiveTest.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(CoreTests matador-core Catch2::Catch2WithMain)
|
||||
|
|
|
|||
|
|
@ -15,15 +15,12 @@ struct person {
|
|||
virtual ~person() = default;
|
||||
|
||||
template<typename Operator>
|
||||
void process(Operator &/*op*/) {
|
||||
}
|
||||
static void process(Operator &/*op*/) {}
|
||||
};
|
||||
|
||||
struct student final : person {
|
||||
};
|
||||
struct student final : person {};
|
||||
|
||||
struct teacher final : person {
|
||||
};
|
||||
struct teacher final : person {};
|
||||
|
||||
struct names {
|
||||
unsigned int id{};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
// tests/test_is_database_primitive.cpp
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "matador/utils/types.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace matador::utils;
|
||||
|
||||
TEST_CASE("is_database_primitive: true for all database_type alternatives", "[type_traits]") {
|
||||
STATIC_REQUIRE(is_database_primitive_v<uint8_t>);
|
||||
STATIC_REQUIRE(is_database_primitive_v<uint16_t>);
|
||||
STATIC_REQUIRE(is_database_primitive_v<uint32_t>);
|
||||
STATIC_REQUIRE(is_database_primitive_v<uint64_t>);
|
||||
|
||||
STATIC_REQUIRE(is_database_primitive_v<int8_t>);
|
||||
STATIC_REQUIRE(is_database_primitive_v<int16_t>);
|
||||
STATIC_REQUIRE(is_database_primitive_v<int32_t>);
|
||||
STATIC_REQUIRE(is_database_primitive_v<int64_t>);
|
||||
|
||||
STATIC_REQUIRE(is_database_primitive_v<float>);
|
||||
STATIC_REQUIRE(is_database_primitive_v<double>);
|
||||
|
||||
STATIC_REQUIRE(is_database_primitive_v<bool>);
|
||||
|
||||
STATIC_REQUIRE(is_database_primitive_v<const char*>);
|
||||
STATIC_REQUIRE(is_database_primitive_v<std::string>);
|
||||
|
||||
STATIC_REQUIRE(is_database_primitive_v<blob_type_t>);
|
||||
STATIC_REQUIRE(is_database_primitive_v<timestamp_type_t>);
|
||||
STATIC_REQUIRE(is_database_primitive_v<date_type_t>);
|
||||
STATIC_REQUIRE(is_database_primitive_v<time_type_t>);
|
||||
|
||||
STATIC_REQUIRE(is_database_primitive_v<std::nullptr_t>);
|
||||
}
|
||||
|
||||
TEST_CASE("is_database_primitive: strips cv/ref qualifiers", "[type_traits]") {
|
||||
STATIC_REQUIRE(is_database_primitive_v<const std::string&>);
|
||||
STATIC_REQUIRE(is_database_primitive_v<volatile uint32_t>);
|
||||
STATIC_REQUIRE(is_database_primitive_v<const blob_type_t&&>);
|
||||
STATIC_REQUIRE(is_database_primitive_v<const date_type_t&>);
|
||||
STATIC_REQUIRE(is_database_primitive_v<const std::nullptr_t&>);
|
||||
}
|
||||
|
||||
TEST_CASE("is_database_primitive: false for non-alternatives (even if convertible)", "[type_traits]") {
|
||||
STATIC_REQUIRE_FALSE(is_database_primitive_v<char*>); // not const char*
|
||||
STATIC_REQUIRE_FALSE(is_database_primitive_v<char const[4]>); // array type != const char*
|
||||
STATIC_REQUIRE_FALSE(is_database_primitive_v<std::string_view>); // not in variant
|
||||
STATIC_REQUIRE_FALSE(is_database_primitive_v<long double>); // not in variant
|
||||
STATIC_REQUIRE_FALSE(is_database_primitive_v<void*>); // not in variant
|
||||
STATIC_REQUIRE_FALSE(is_database_primitive_v<null_type_t>); // your custom null wrapper isn't in variant
|
||||
}
|
||||
|
||||
TEST_CASE("is_database_primitive: works via ::value too", "[type_traits]") {
|
||||
STATIC_REQUIRE(is_database_primitive<int32_t>::value);
|
||||
// STATIC_REQUIRE(is_database_primitive<unsigned>::value); // assuming unsigned != uint32_t on your platform
|
||||
}
|
||||
Loading…
Reference in New Issue