diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2023-02-22 17:14:48 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-02-22 17:14:48 +0100 |
| commit | 384d5c20d85a8ed9a4ccd0ede4457381c7458549 (patch) | |
| tree | 3c2a08bd1060b03ee981d6c25c3d4bf51b76f3ba /entity | |
| parent | 19652b004e83ca7d460c87a7666ba46083b9222a (diff) | |
wip
Diffstat (limited to 'entity')
| -rw-r--r-- | entity/accessor.hpp | 8 | ||||
| -rw-r--r-- | entity/erased-constraints.hpp | 36 |
2 files changed, 21 insertions, 23 deletions
diff --git a/entity/accessor.hpp b/entity/accessor.hpp index 3b979a16..f70dee72 100644 --- a/entity/accessor.hpp +++ b/entity/accessor.hpp @@ -16,7 +16,7 @@ struct group; namespace floormat::entities { -enum class field_status : unsigned char { enabled, hidden, readonly, }; +enum class field_status : unsigned char { hidden, readonly, enabled, }; struct erased_accessor final { using reader_t = void; @@ -170,11 +170,7 @@ void erased_accessor::write(Obj& x, move_qualified<FieldType> value) const noexc write_unchecked<Obj, FieldType>(x, value); } -field_status erased_accessor::is_enabled(const void* x) const noexcept -{ - return predicate_fun(&x, predicate); -} - +field_status erased_accessor::is_enabled(const void* x) const noexcept { return predicate_fun(&x, predicate); } erased_constraints::range erased_accessor::get_range(const void* x) const noexcept { return range_fun(x,range); } erased_constraints::max_length erased_accessor::get_max_length(const void* x) const noexcept { return length_fun(x,length); } erased_constraints::group erased_accessor::get_group(const void* x) const noexcept { return group_fun(x, group); } diff --git a/entity/erased-constraints.hpp b/entity/erased-constraints.hpp index c0ff3e9f..4fe5c853 100644 --- a/entity/erased-constraints.hpp +++ b/entity/erased-constraints.hpp @@ -29,26 +29,28 @@ struct range final template<typename T> constexpr std::pair<T, T> range::convert() const { - if constexpr (!std::is_floating_point_v<T> && !std::is_integral_v<T>) - return {{}, {}}; - - using std::size_t; - static_assert(sizeof(T) <= sizeof(size_t) || !std::is_integral_v<T>); - - constexpr auto min_ = []<typename V>(V a, V b) { return a < b ? a : b; }; - constexpr auto max_ = []<typename V>(V a, V b) { return a > b ? a : b; }; + static_assert(sizeof(T) <= sizeof(std::size_t)); using limits = std::numeric_limits<T>; - constexpr auto lmin = limits::min(), lmax = limits::max(); - switch (type) { - case type_float: - if constexpr (limits::is_integer) - return { T(std::floor(min.f)), T(std::ceil(max.f)) }; + if (type == type_none) + return { limits::min(), limits::max() }; + else + { + if constexpr (std::is_integral_v<T> && std::is_signed_v<T>) + { + fm_assert(type == type_int); + return { T(min.i), T(max.i) }; + } + else if constexpr (std::is_integral_v<T> && std::is_unsigned_v<T>) + { + fm_assert(type == type_uint); + return { T(min.u), T(max.u) }; + } else - return { T(min.f), T(max.f) }; - case type_uint: return { max_(T(min.u), lmin), T(min_(size_t(max.u), size_t(lmax))) }; - case type_int: return { max_(T(min.i), lmin), T(min_(size_t(max.i), size_t(lmax))) }; - default: case type_none: return { lmin, lmax }; + { + fm_assert(type == type_float); + return { T(min.i), T(max.i) }; + } } } |
