Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 14 additions & 138 deletions dev/column.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "tuple_helper.h"
#include "default_value_extractor.h"
#include "constraints.h"
#include "getter_traits.h"

namespace sqlite_orm {

Expand Down Expand Up @@ -64,8 +65,7 @@ namespace sqlite_orm {
setter_type setter_,
constraints_type constraints_) :
column_base{std::move(name)},
member_pointer(member_pointer_), getter(getter_), setter(setter_),
constraints(std::move(constraints_)) {}
member_pointer(member_pointer_), getter(getter_), setter(setter_), constraints(move(constraints_)) {}

/**
* Simplified interface for `NOT NULL` constraint
Expand Down Expand Up @@ -121,152 +121,26 @@ namespace sqlite_orm {
template<class O, class T, class... Op>
struct is_column<column_t<O, T, Op...>> : public std::true_type {};

template<class T, class SFINAE = void>
struct is_field_member_pointer : std::false_type {};

template<class T>
struct is_field_member_pointer<T,
typename std::enable_if<std::is_member_pointer<T>::value &&
!std::is_member_function_pointer<T>::value>::type>
: std::true_type {};

/**
* Getters aliases
*/
template<class O, class T>
using getter_by_value_const = T (O::*)() const;

template<class O, class T>
using getter_by_value = T (O::*)();

template<class O, class T>
using getter_by_ref_const = T &(O::*)() const;

template<class O, class T>
using getter_by_ref = T &(O::*)();

template<class O, class T>
using getter_by_const_ref_const = const T &(O::*)() const;

template<class O, class T>
using getter_by_const_ref = const T &(O::*)();

/**
* Setters aliases
*/
template<class O, class T>
using setter_by_value = void (O::*)(T);

template<class O, class T>
using setter_by_ref = void (O::*)(T &);

template<class O, class T>
using setter_by_const_ref = void (O::*)(const T &);

template<class T>
struct is_getter : std::false_type {};

template<class O, class T>
struct is_getter<getter_by_value_const<O, T>> : std::true_type {};

template<class O, class T>
struct is_getter<getter_by_value<O, T>> : std::true_type {};

template<class O, class T>
struct is_getter<getter_by_ref_const<O, T>> : std::true_type {};

template<class O, class T>
struct is_getter<getter_by_ref<O, T>> : std::true_type {};

template<class O, class T>
struct is_getter<getter_by_const_ref_const<O, T>> : std::true_type {};

template<class O, class T>
struct is_getter<getter_by_const_ref<O, T>> : std::true_type {};

template<class T>
struct is_setter : std::false_type {};

template<class O, class T>
struct is_setter<setter_by_value<O, T>> : std::true_type {};

template<class O, class T>
struct is_setter<setter_by_ref<O, T>> : std::true_type {};

template<class O, class T>
struct is_setter<setter_by_const_ref<O, T>> : std::true_type {};

template<class T>
struct getter_traits;

template<class O, class T>
struct getter_traits<getter_by_value_const<O, T>> {
using object_type = O;
using field_type = T;

static constexpr const bool returns_lvalue = false;
struct column_field_type {
using type = void;
};

template<class O, class T>
struct getter_traits<getter_by_value<O, T>> {
using object_type = O;
using field_type = T;

static constexpr const bool returns_lvalue = false;
};

template<class O, class T>
struct getter_traits<getter_by_ref_const<O, T>> {
using object_type = O;
using field_type = T;

static constexpr const bool returns_lvalue = true;
};

template<class O, class T>
struct getter_traits<getter_by_ref<O, T>> {
using object_type = O;
using field_type = T;

static constexpr const bool returns_lvalue = true;
};

template<class O, class T>
struct getter_traits<getter_by_const_ref_const<O, T>> {
using object_type = O;
using field_type = T;

static constexpr const bool returns_lvalue = true;
};

template<class O, class T>
struct getter_traits<getter_by_const_ref<O, T>> {
using object_type = O;
using field_type = T;

static constexpr const bool returns_lvalue = true;
template<class O, class T, class... Op>
struct column_field_type<column_t<O, T, Op...>> {
using type = typename column_t<O, T, Op...>::field_type;
};

template<class T>
struct setter_traits;

template<class O, class T>
struct setter_traits<setter_by_value<O, T>> {
using object_type = O;
using field_type = T;
struct column_constraints_type {
using type = std::tuple<>;
};

template<class O, class T>
struct setter_traits<setter_by_ref<O, T>> {
using object_type = O;
using field_type = T;
template<class O, class T, class... Op>
struct column_constraints_type<column_t<O, T, Op...>> {
using type = typename column_t<O, T, Op...>::constraints_type;
};

template<class O, class T>
struct setter_traits<setter_by_const_ref<O, T>> {
using object_type = O;
using field_type = T;
};
}

/**
Expand All @@ -280,6 +154,8 @@ namespace sqlite_orm {
make_column(const std::string &name, T O::*m, Op... constraints) {
static_assert(constraints::constraints_size<Op...>::value == std::tuple_size<std::tuple<Op...>>::value,
"Incorrect constraints pack");
static_assert(internal::is_field_member_pointer<T O::*>::value,
"second argument expected as a member field pointer, not member function pointer");
return {name, m, nullptr, nullptr, std::make_tuple(constraints...)};
}

Expand Down
34 changes: 26 additions & 8 deletions dev/constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ namespace sqlite_orm {
template<class... Cs>
struct primary_key_t : primary_key_base {
using order_by = primary_key_base::order_by;
using columns_tuple = std::tuple<Cs...>;

std::tuple<Cs...> columns;
columns_tuple columns;

primary_key_t(decltype(columns) c) : columns(std::move(c)) {}

using field_type = void; // for column iteration. Better be deleted
using constraints_type = std::tuple<>;
primary_key_t(decltype(columns) c) : columns(move(c)) {}

primary_key_t<Cs...> asc() const {
auto res = *this;
Expand Down Expand Up @@ -255,9 +253,6 @@ namespace sqlite_orm {
return *this;
}

using field_type = void; // for column iteration. Better be deleted
using constraints_type = std::tuple<>;

template<class L>
void for_each_column(const L &) {}

Expand Down Expand Up @@ -310,6 +305,21 @@ namespace sqlite_orm {
}
};

struct check_string {
operator std::string() const {
return "CHECK";
}
};

template<class T>
struct check_t : check_string {
using expression_type = T;

expression_type expression;

check_t(expression_type expression_) : expression(std::move(expression_)) {}
};

template<class T>
struct is_constraint : std::false_type {};

Expand All @@ -331,6 +341,9 @@ namespace sqlite_orm {
template<>
struct is_constraint<collate_t> : std::true_type {};

template<class T>
struct is_constraint<check_t<T>> : std::true_type {};

template<class... Args>
struct constraints_size;

Expand Down Expand Up @@ -391,6 +404,11 @@ namespace sqlite_orm {
return {internal::collate_argument::rtrim};
}

template<class T>
constraints::check_t<T> check(T t) {
return {std::move(t)};
}

namespace internal {

/**
Expand Down
4 changes: 3 additions & 1 deletion dev/default_value_extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <sstream> // std::stringstream

#include "constraints.h"
#include "serializator_context.h"

namespace sqlite_orm {

Expand All @@ -26,7 +27,8 @@ namespace sqlite_orm {

template<class T>
std::unique_ptr<std::string> operator()(const constraints::default_t<T> &t) {
return std::make_unique<std::string>(serialize(t.value));
serializator_context_base context;
return std::make_unique<std::string>(serialize(t.value, context));
}
};

Expand Down
3 changes: 3 additions & 0 deletions dev/error_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace sqlite_orm {
incorrect_journal_mode_string,
invalid_collate_argument_enum,
failed_to_init_a_backup,
unknown_member_value,
};

}
Expand Down Expand Up @@ -57,6 +58,8 @@ namespace sqlite_orm {
return "Invalid collate_argument enum";
case orm_error_code::failed_to_init_a_backup:
return "Failed to init a backup";
case orm_error_code::unknown_member_value:
return "Unknown member value";
default:
return "unknown error";
}
Expand Down
Loading