diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-18 11:19:38 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-18 11:51:43 +0100 |
commit | ec4f8323fe075e8b8d716128996658a2a1a300d7 (patch) | |
tree | 39dccf5dd4a273f1dba8ad5e25574f3ccb6589ca /entity | |
parent | 7bd1ca56bd9bc561d987fce90e0ba52eeb6636d9 (diff) |
entity: whitespace
Diffstat (limited to 'entity')
-rw-r--r-- | entity/entity.hpp | 75 | ||||
-rw-r--r-- | entity/name-of.hpp | 4 | ||||
-rw-r--r-- | entity/util.hpp | 2 |
3 files changed, 35 insertions, 46 deletions
diff --git a/entity/entity.hpp b/entity/entity.hpp index 4754204c..1dedebf0 100644 --- a/entity/entity.hpp +++ b/entity/entity.hpp @@ -126,22 +126,10 @@ constexpr CORRADE_ALWAYS_INLINE bool find_in_tuple(F&& fun, Tuple&& tuple) return false; } -template<typename T> struct decay_tuple_; -template<typename... Ts> struct decay_tuple_<std::tuple<Ts...>> { - using type = std::tuple<std::decay_t<Ts>...>; -}; - -template<typename T> -using decay_tuple = typename decay_tuple_<T>::type; - -template<typename T> -struct accessors_for_ -{ - using type = decay_tuple<std::decay_t<decltype(T::accessors())>>; -}; - -template<typename T> -using accessors_for = typename accessors_for_<T>::type; +template<typename T> struct decay_tuple_; template<typename... Ts> struct decay_tuple_<std::tuple<Ts...>> { using type = std::tuple<std::decay_t<Ts>...>; }; +template<typename T> using decay_tuple = typename decay_tuple_<T>::type; +template<typename T> struct accessors_for_ { using type = decay_tuple<std::decay_t<decltype(T::accessors())>>; }; +template<typename T> using accessors_for = typename accessors_for_<T>::type; } // namespace detail @@ -165,33 +153,36 @@ struct entity_field : entity_field_base<Obj, Type> { constexpr decltype(auto) read(const Obj& x) const { return read(reader, x); } constexpr void write(Obj& x, move_qualified<Type> value) const { write(writer, x, value); } constexpr entity_field(StringView name, R r, W w) noexcept : name{name}, reader{r}, writer{w} {} + constexpr erased_accessor erased() const; +}; - constexpr erased_accessor erased() const { - using reader_t = typename erased_accessor::erased_reader_t; - using writer_t = typename erased_accessor::erased_writer_t; - constexpr auto obj_name = name_of<Obj>, field_name = name_of<Type>; +template<typename Obj, typename Type, FieldReader<Obj, Type> R, FieldWriter<Obj, Type> W> +constexpr erased_accessor entity_field<Obj, Type, R, W>::erased() const +{ + using reader_t = typename erased_accessor::erased_reader_t; + using writer_t = typename erased_accessor::erased_writer_t; + constexpr auto obj_name = name_of<Obj>, field_name = name_of<Type>; - constexpr auto reader_fn = [](const void* obj, const reader_t* reader, void* value) - { - const auto& obj_ = *reinterpret_cast<const Obj*>(obj); - const auto& reader_ = *reinterpret_cast<const R*>(reader); - auto& value_ = *reinterpret_cast<Type*>(value); - value_ = read(reader_, obj_); - }; - constexpr auto writer_fn = [](void* obj, const writer_t* writer, void* value) - { - auto& obj_ = *reinterpret_cast<Obj*>(obj); - const auto& writer_ = *reinterpret_cast<const W*>(writer); - move_qualified<Type> value_ = std::move(*reinterpret_cast<Type*>(value)); - write(writer_, obj_, value_); - }; - return erased_accessor{ - (void*)&reader, (void*)&writer, - obj_name, field_name, - reader_fn, writer_fn, - }; - } -}; + constexpr auto reader_fn = [](const void* obj, const reader_t* reader, void* value) + { + const auto& obj_ = *reinterpret_cast<const Obj*>(obj); + const auto& reader_ = *reinterpret_cast<const R*>(reader); + auto& value_ = *reinterpret_cast<Type*>(value); + value_ = read(reader_, obj_); + }; + constexpr auto writer_fn = [](void* obj, const writer_t* writer, void* value) + { + auto& obj_ = *reinterpret_cast<Obj*>(obj); + const auto& writer_ = *reinterpret_cast<const W*>(writer); + move_qualified<Type> value_ = std::move(*reinterpret_cast<Type*>(value)); + write(writer_, obj_, value_); + }; + return erased_accessor { + (void*)&reader, writer ? (void*)&writer : nullptr, + obj_name, field_name, + reader_fn, writer_fn, + }; +} template<typename Obj> struct Entity final { @@ -239,7 +230,7 @@ template<typename T> requires std::is_same_v<T, std::decay_t<T>> class entity_metadata final { template<typename... Ts> - static constexpr auto erased_helper(const std::tuple<Ts...>& tuple) + static consteval auto erased_helper(const std::tuple<Ts...>& tuple) { std::array<entities::erased_accessor, sizeof...(Ts)> array { std::get<Ts>(tuple).erased()..., }; return array; diff --git a/entity/name-of.hpp b/entity/name-of.hpp index 592f07c1..39e1b8c9 100644 --- a/entity/name-of.hpp +++ b/entity/name-of.hpp @@ -8,11 +8,11 @@ #endif template<typename T> -static constexpr auto _name_of() { +static constexpr auto _name_of() { // NOLINT(bugprone-reserved-identifier) using namespace Corrade::Containers; using SVF = StringViewFlag; constexpr const char* str = FM_PRETTY_FUNCTION; return StringView { str, Implementation::strlen_(str), SVF::Global|SVF::NullTerminated }; } -template<typename T> constexpr inline Corrade::Containers::StringView name_of = _name_of<T>(); +template<typename T> constexpr inline auto name_of = _name_of<T>(); diff --git a/entity/util.hpp b/entity/util.hpp index 073745e9..3643866d 100644 --- a/entity/util.hpp +++ b/entity/util.hpp @@ -2,10 +2,8 @@ #include <type_traits> namespace Corrade::Containers { - template<typename T> class BasicStringView; using StringView = BasicStringView<const char>; - } // namespace Corrade::Containers namespace floormat::entities { |