Browse Source

* implemented modifier

master
bergmann 5 years ago
parent
commit
e0078fc669
16 changed files with 516 additions and 0 deletions
  1. +1
    -0
      include/cpphibernate.h
  2. +3
    -0
      include/cpphibernate/config.h
  3. +6
    -0
      include/cpphibernate/modifier.h
  4. +64
    -0
      include/cpphibernate/modifier/limit.h
  5. +31
    -0
      include/cpphibernate/modifier/modifier.h
  6. +64
    -0
      include/cpphibernate/modifier/offset.h
  7. +4
    -0
      include/cpphibernate/modifier/where.h
  8. +6
    -0
      include/cpphibernate/modifier/where/clauses.h
  9. +60
    -0
      include/cpphibernate/modifier/where/clauses/and.h
  10. +31
    -0
      include/cpphibernate/modifier/where/clauses/clause.h
  11. +64
    -0
      include/cpphibernate/modifier/where/clauses/equal.h
  12. +60
    -0
      include/cpphibernate/modifier/where/clauses/not.h
  13. +60
    -0
      include/cpphibernate/modifier/where/clauses/or.h
  14. +60
    -0
      include/cpphibernate/modifier/where/where.h
  15. +1
    -0
      include/cpphibernate/schema/field.h
  16. +1
    -0
      include/cpphibernate/schema/print.h

+ 1
- 0
include/cpphibernate.h View File

@@ -2,5 +2,6 @@

#include <cpphibernate/config.h>
#include <cpphibernate/misc.h>
#include <cpphibernate/modifier.h>
#include <cpphibernate/schema.h>
#include <cpphibernate/types.h>

+ 3
- 0
include/cpphibernate/config.h View File

@@ -46,6 +46,9 @@
#define beg_namespace_cpphibernate_misc cpphibernate_define_namespace_beg(beg_namespace_cpphibernate, misc)
#define end_namespace_cpphibernate_misc cpphibernate_define_namespace_end(end_namespace_cpphibernate)

#define beg_namespace_cpphibernate_modifier cpphibernate_define_namespace_beg(beg_namespace_cpphibernate, modifier)
#define end_namespace_cpphibernate_modifier cpphibernate_define_namespace_end(end_namespace_cpphibernate)

beg_namespace_cpphibernate
{



+ 6
- 0
include/cpphibernate/modifier.h View File

@@ -0,0 +1,6 @@
#pragma once

#include <cpphibernate/modifier/limit.h>
#include <cpphibernate/modifier/modifier.h>
#include <cpphibernate/modifier/offset.h>
#include <cpphibernate/modifier/where.h>

+ 64
- 0
include/cpphibernate/modifier/limit.h View File

@@ -0,0 +1,64 @@
#pragma once

#include <cpphibernate/misc.h>
#include <cpphibernate/config.h>
#include <cpphibernate/modifier/modifier.h>

beg_namespace_cpphibernate_modifier
{

namespace __impl
{

/* limit_t */

template<typename T_value>
struct limit_t
: public modifier_t
{
using value_type = T_value;

value_type value;

constexpr limit_t(T_value&& p_value)
: value(std::forward<T_value>(p_value))
{ }
};

/* limit_builder */

template<typename X, typename = void>
struct limit_builder
{
template<typename... T_args>
static constexpr decltype(auto) apply(T_args&... args)
{ static_assert(sizeof...(args) == -1, "Invalid parameters for hibernate::modifier::limit(...)!"); }
};

template<typename T_value>
struct limit_builder<
mp::list<T_value>,
mp::enable_if<mp::is_integral<T_value>>>
{
static constexpr decltype(auto) apply(T_value&& value)
{
using value_type = mp::integral_constant<T_value, value>;
return limit_t<value_type>(value_type { });
}
};

}

/* meta */

template<typename T>
struct is_limit_modifier
: public mp::is_specialization_of<T, __impl::limit_t>
{ };

/* make */

constexpr decltype(auto) limit = misc::make_generic_predicate<__impl::limit_builder> { };

}
end_namespace_cpphibernate_modifier

+ 31
- 0
include/cpphibernate/modifier/modifier.h View File

@@ -0,0 +1,31 @@
#pragma once

#include <cpphibernate/config.h>

beg_namespace_cpphibernate_modifier
{

namespace __impl
{

/* modifier_t */

struct modifier_t
{ };

}

/* meta */

template<typename T>
struct is_modifier
: public mp::is_base_of<__impl::modifier_t, T>
{ };

template<typename... T>
struct all_are_modifier
: public mp::all_true<is_modifier<T>::value...>
{ };

}
end_namespace_cpphibernate_modifier

+ 64
- 0
include/cpphibernate/modifier/offset.h View File

@@ -0,0 +1,64 @@
#pragma once

#include <cpphibernate/misc.h>
#include <cpphibernate/config.h>
#include <cpphibernate/modifier/modifier.h>

beg_namespace_cpphibernate_modifier
{

namespace __impl
{

/* offset_t */

template<typename T_value>
struct offset_t
: public modifier_t
{
using value_type = T_value;

value_type value;

constexpr offset_t(T_value&& p_value)
: value(std::forward<T_value>(p_value))
{ }
};

/* offset_builder */

template<typename X, typename = void>
struct offset_builder
{
template<typename... T_args>
static constexpr decltype(auto) apply(T_args&... args)
{ static_assert(sizeof...(args) == -1, "Invalid parameters for hibernate::modifier::offset(...)!"); }
};

template<typename T_value>
struct offset_builder<
mp::list<T_value>,
mp::enable_if<mp::is_integral<T_value>>>
{
static constexpr decltype(auto) apply(T_value&& value)
{
using value_type = mp::integral_constant<T_value, value>;
return offset_t<value_type>(value_type { });
}
};

}

/* meta */

template<typename T>
struct is_offset_modifier
: public mp::is_specialization_of<T, __impl::offset_t>
{ };

/* make */

constexpr decltype(auto) offset = misc::make_generic_predicate<__impl::offset_builder> { };

}
end_namespace_cpphibernate_modifier

+ 4
- 0
include/cpphibernate/modifier/where.h View File

@@ -0,0 +1,4 @@
#pragma once

#include <cpphibernate/modifier/where/clauses.h>
#include <cpphibernate/modifier/where/where.h>

+ 6
- 0
include/cpphibernate/modifier/where/clauses.h View File

@@ -0,0 +1,6 @@
#pragma once

#include <cpphibernate/modifier/where/clauses/and.h>
#include <cpphibernate/modifier/where/clauses/clause.h>
#include <cpphibernate/modifier/where/clauses/equal.h>
#include <cpphibernate/modifier/where/clauses/not.h>

+ 60
- 0
include/cpphibernate/modifier/where/clauses/and.h View File

@@ -0,0 +1,60 @@
#pragma once

#include <cpphibernate/config.h>
#include <cpphibernate/modifier/where/clauses/clause.h>

beg_namespace_cpphibernate_modifier
{

namespace __impl
{

/* where_clause_and_t */

template<typename... T_clauses>
struct where_clause_and_t
: public where_clause_t
{
using clauses_type = hana::basic_tuple<T_clauses...>;

clauses_type clauses;

constexpr where_clause_and_t(T_clauses&&... p_clauses)
: clauses(std::forward<T_clauses>(p_clauses)...)
{ }
};

/* where_clause_and_builder */

template<typename X, typename = void>
struct where_clause_and_builder
{
template<typename... T_args>
static constexpr decltype(auto) apply(T_args&&... args)
{ static_assert(sizeof...(args) == -1, "Invalid parameters for hibernate::modifier::and(...)!"); }
};

template<typename... T_clauses>
struct where_clause_and_builder<
mp::list<T_clauses...>,
mp::enable_if<all_are_where_clauses<mp::decay_t<T_clauses>...>>>
{
static constexpr decltype(auto) apply(T_clauses&&... clauses)
{ return where_clause_and_t<T_clauses...>(std::forward<T_clauses>(clauses)...); }
};

}

/* meta */

template<typename T>
struct is_where_clause_and
: public mp::is_specialization_of<T, __impl::where_clause_and_t>
{ };

/* make */

constexpr decltype(auto) and_ = misc::make_generic_predicate<__impl::where_clause_and_builder> { };

}
end_namespace_cpphibernate_modifier

+ 31
- 0
include/cpphibernate/modifier/where/clauses/clause.h View File

@@ -0,0 +1,31 @@
#pragma once

#include <cpphibernate/config.h>

beg_namespace_cpphibernate_modifier
{

namespace __impl
{

/* where_clause_t */

struct where_clause_t
{ };

}

/* meta */

template<typename T>
struct is_where_clause
: public mp::is_base_of<__impl::where_clause_t, T>
{ };

template<typename... T>
struct all_are_where_clauses
: public mp::all_true<is_where_clause<T>::value...>
{ };

}
end_namespace_cpphibernate_modifier

+ 64
- 0
include/cpphibernate/modifier/where/clauses/equal.h View File

@@ -0,0 +1,64 @@
#pragma once

#include <cpphibernate/config.h>
#include <cpphibernate/schema/field.h>
#include <cpphibernate/modifier/where/clauses/clause.h>

beg_namespace_cpphibernate_modifier
{

namespace __impl
{

/* where_clause_equal_t */

template<typename T_field, typename T_value>
struct where_clause_equal_t
: public where_clause_t
{
using field_type = T_field;
using value_type = T_value;

field_type field;
value_type value;

constexpr where_clause_equal_t(T_field&& p_field, T_value&& p_value)
: field(std::forward<T_field>(p_field))
, value(std::forward<T_value>(p_value))
{ }
};

/* where_clause_equal_builder */

template<typename X, typename = void>
struct where_clause_equal_builder
{
template<typename... T_args>
static constexpr decltype(auto) apply(T_args&&... args)
{ static_assert(sizeof...(args) == -1, "Invalid parameters for hibernate::modifier::equal(...)!"); }
};

template<typename T_field, typename T_value>
struct where_clause_equal_builder<
mp::list<T_field, T_value>,
mp::enable_if<schema::is_field<mp::decay_t<T_field>>>>
{
static constexpr decltype(auto) apply(T_field&& field, T_value&& value)
{ return where_clause_equal_t<T_field, T_value>(std::forward<T_field>(field), std::forward<T_value>(value)); }
};

}

/* meta */

template<typename T>
struct is_where_clause_equal
: public mp::is_specialization_of<T, __impl::where_clause_equal_t>
{ };

/* make */

constexpr decltype(auto) equal = misc::make_generic_predicate<__impl::where_clause_equal_builder> { };

}
end_namespace_cpphibernate_modifier

+ 60
- 0
include/cpphibernate/modifier/where/clauses/not.h View File

@@ -0,0 +1,60 @@
#pragma once

#include <cpphibernate/config.h>
#include <cpphibernate/modifier/where/clauses/clause.h>

beg_namespace_cpphibernate_modifier
{

namespace __impl
{

/* where_clause_not_t */

template<typename T_clause>
struct where_clause_not_t
: public where_clause_t
{
using clause_type = T_clause;

clause_type clause;

constexpr where_clause_not_t(T_clause&& p_clause)
: clause(std::forward<T_clause>(p_clause))
{ }
};

/* where_clause_not_builder */

template<typename X, typename = void>
struct where_clause_not_builder
{
template<typename... T_args>
static constexpr decltype(auto) apply(T_args&&... args)
{ static_assert(sizeof...(args) == -1, "Invalid parameters for hibernate::modifier::not(...)!"); }
};

template<typename T_clause>
struct where_clause_not_builder<
mp::list<T_clause>,
mp::enable_if<is_where_clause<mp::decay_t<T_clause>>>>
{
static constexpr decltype(auto) apply(T_clause&& clause)
{ return where_clause_not_t<T_clause>(std::forward<T_clause>(clause)); }
};

}

/* meta */

template<typename T>
struct is_where_clause_not
: public mp::is_specialization_of<T, __impl::where_clause_not_t>
{ };

/* make */

constexpr decltype(auto) not_ = misc::make_generic_predicate<__impl::where_clause_not_builder> { };

}
end_namespace_cpphibernate_modifier

+ 60
- 0
include/cpphibernate/modifier/where/clauses/or.h View File

@@ -0,0 +1,60 @@
#pragma once

#include <cpphibernate/config.h>
#include <cpphibernate/modifier/where/clauses/clause.h>

beg_namespace_cpphibernate_modifier
{

namespace __impl
{

/* where_clause_or_t */

template<typename... T_clauses>
struct where_clause_or_t
: public where_clause_t
{
using clauses_type = hana::basic_tuple<T_clauses...>;

clauses_type clauses;

constexpr where_clause_or_t(T_clauses&&... p_clauses)
: clauses(std::forward<T_clauses>(p_clauses)...)
{ }
};

/* where_clause_or_builder */

template<typename X, typename = void>
struct where_clause_or_builder
{
template<typename... T_args>
static constexpr decltype(auto) apply(T_args&&... args)
{ static_assert(sizeof...(args) == -1, "Invalid parameters for hibernate::modifier::or(...)!"); }
};

template<typename... T_clauses>
struct where_clause_or_builder<
mp::list<T_clauses...>,
mp::enable_if<all_are_where_clauses<mp::decay_t<T_clauses>...>>>
{
static constexpr decltype(auto) apply(T_clauses&&... clauses)
{ return where_clause_or_t<T_clauses...>(std::forward<T_clauses>(clauses)...); }
};

}

/* meta */

template<typename T>
struct is_where_clause_or
: public mp::is_specialization_of<T, __impl::where_clause_or_t>
{ };

/* make */

constexpr decltype(auto) or_ = misc::make_generic_predicate<__impl::where_clause_or_builder> { };

}
end_namespace_cpphibernate_modifier

+ 60
- 0
include/cpphibernate/modifier/where/where.h View File

@@ -0,0 +1,60 @@
#pragma once

#include <cpphibernate/misc.h>
#include <cpphibernate/config.h>
#include <cpphibernate/modifier/modifier.h>
#include <cpphibernate/modifier/where/clauses/clause.h>

beg_namespace_cpphibernate_modifier
{

namespace __impl
{

/* where_t */

template<typename T_clause>
struct where_t
: public modifier_t
{
using clause_type = T_clause;

clause_type clause;

constexpr where_t(T_clause&& p_clause)
: clause(std::forward<T_clause>(p_clause))
{ }
};

/* where_builder */

template<typename X, typename = void>
struct where_builder
{
template<typename... T_args>
static constexpr decltype(auto) apply(T_args&... args)
{ static_assert(sizeof...(args) == -1, "Invalid parameters for hibernate::modifier::where(...)!"); }
};

template<typename T_clause>
struct where_builder<mp::list<T_clause>, mp::enable_if<is_where_clause<T_clause>>>
{
static constexpr decltype(auto) apply(T_clause&& clause)
{ return where_t<T_clause>(std::forward<T_clause>(clause)); }
};

}

/* meta */

template<typename T>
struct is_where_modifier
: public mp::is_specialization_of<T, __impl::where_t>
{ };

/* make */

constexpr decltype(auto) where = misc::make_generic_predicate<__impl::where_builder> { };

}
end_namespace_cpphibernate_modifier

+ 1
- 0
include/cpphibernate/schema/field.h View File

@@ -4,6 +4,7 @@
#include <cpphibernate/config.h>
#include <cpphibernate/schema/getter.h>
#include <cpphibernate/schema/setter.h>
#include <cpphibernate/schema/attributes.h>

#include <cpputils/misc/indent.h>
#include <cpputils/misc/type_helper.h>


+ 1
- 0
include/cpphibernate/schema/print.h View File

@@ -1,5 +1,6 @@
#pragma once

#include <iostream>
#include <cpphibernate/config.h>

namespace std


Loading…
Cancel
Save