summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-11-19 13:34:39 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-11-19 13:44:32 +0100
commitd94d56bb395f64a819c72fe5d09228ec31e0dd93 (patch)
tree1c09f13b7a069d4a4c097a8f84b23e61bf782b5c
parent0474ef756cd7462b990da7b4703ad3cc6ea69419 (diff)
entity: wip constraints
-rw-r--r--entity/constraints.hpp2
-rw-r--r--entity/metadata.hpp23
2 files changed, 17 insertions, 8 deletions
diff --git a/entity/constraints.hpp b/entity/constraints.hpp
index f629b149..f8434bd7 100644
--- a/entity/constraints.hpp
+++ b/entity/constraints.hpp
@@ -50,7 +50,7 @@ template<typename T> constexpr std::pair<T, T> range::convert() const
}
struct length final {
- std::size_t value = (std::size_t)-1;
+ std::size_t value = std::numeric_limits<std::size_t>::max();
};
struct group final {
diff --git a/entity/metadata.hpp b/entity/metadata.hpp
index a402a2a3..8bd36cb8 100644
--- a/entity/metadata.hpp
+++ b/entity/metadata.hpp
@@ -65,6 +65,9 @@ template<typename Obj, typename Type, typename Default, std::size_t I, typename
requires FieldReader<F, Obj, Type>
struct find_reader<Obj, Type, Default, I, F, Fs...> { using type = F; static constexpr std::size_t index = I; };
+template<typename Obj, typename Type, typename... Fs>
+using find_reader2 = find_reader<Obj, Type, Type, 0, Fs...>;
+
template<typename Obj, auto constant>
constexpr auto constantly = [](const Obj&) constexpr { return constant; };
@@ -80,9 +83,9 @@ private:
static constexpr auto default_predicate = detail::constantly<Obj, field_status::enabled>;
using default_predicate_t = std::decay_t<decltype(default_predicate)>;
using c_predicate = detail::find_reader<Obj, field_status, default_predicate_t, 0, Ts...>;
- using c_range = detail::find_reader<Obj, constraints::range<Type>, constraints::range<Type>, 0, Ts...>;
- using c_length = detail::find_reader<Obj, constraints::length, constraints::length, 0, Ts...>;
- using c_group = detail::find_reader<Obj, constraints::group, constraints::group, 0, Ts...>;
+ using c_range = detail::find_reader2<Obj, constraints::range<Type>, Ts...>;
+ using c_length = detail::find_reader2<Obj, constraints::length, Ts...>;
+ using c_group = detail::find_reader2<Obj, constraints::group, Ts...>;
static constexpr std::size_t good_arguments =
unsigned(c_predicate::index != sizeof...(Ts)) +
unsigned(c_range::index != sizeof...(Ts)) +
@@ -96,14 +99,17 @@ public:
using Reader = R;
using Writer = W;
using Predicate = typename c_predicate::type;
+ using Range = typename c_range::type;
+ using Length = typename c_length::type;
+ using Group = typename c_group::type;
StringView name;
[[no_unique_address]] R reader;
[[no_unique_address]] W writer;
[[no_unique_address]] Predicate predicate;
- [[no_unique_address]] c_range range;
- [[no_unique_address]] c_length length;
- [[no_unique_address]] c_group group;
+ [[no_unique_address]] Range range;
+ [[no_unique_address]] Length length;
+ [[no_unique_address]] Group group;
constexpr entity_field(const entity_field&) = default;
constexpr entity_field& operator=(const entity_field&) = default;
@@ -115,7 +121,10 @@ public:
static constexpr field_status is_enabled(const Predicate & p, const Obj& x);
constexpr entity_field(StringView name, R r, W w, Ts&&... ts) noexcept :
name{name}, reader{r}, writer{w},
- predicate{std::get<c_predicate::index>(std::forward_as_tuple(ts..., default_predicate))}
+ predicate{std::get<c_predicate::index>(std::forward_as_tuple(ts..., default_predicate))},
+ range{std::get<c_range::index>(std::forward_as_tuple(ts..., constraints::range<Type>{}))},
+ length{std::get<c_length::index>(std::forward_as_tuple(ts..., constraints::length{}))},
+ group{std::get<c_length::index>(std::forward_as_tuple(ts..., constraints::group{}))}
{}
constexpr erased_accessor erased() const;
};