From ec4f8323fe075e8b8d716128996658a2a1a300d7 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 18 Nov 2022 11:19:38 +0100 Subject: entity: whitespace --- entity/entity.hpp | 75 ++++++++++++++++++++++++------------------------------ entity/name-of.hpp | 4 +-- entity/util.hpp | 2 -- test/entity.cpp | 1 - 4 files changed, 35 insertions(+), 47 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 struct decay_tuple_; -template struct decay_tuple_> { - using type = std::tuple...>; -}; - -template -using decay_tuple = typename decay_tuple_::type; - -template -struct accessors_for_ -{ - using type = decay_tuple>; -}; - -template -using accessors_for = typename accessors_for_::type; +template struct decay_tuple_; template struct decay_tuple_> { using type = std::tuple...>; }; +template using decay_tuple = typename decay_tuple_::type; +template struct accessors_for_ { using type = decay_tuple>; }; +template using accessors_for = typename accessors_for_::type; } // namespace detail @@ -165,33 +153,36 @@ struct entity_field : entity_field_base { constexpr decltype(auto) read(const Obj& x) const { return read(reader, x); } constexpr void write(Obj& x, move_qualified 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, field_name = name_of; +template R, FieldWriter W> +constexpr erased_accessor entity_field::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, field_name = name_of; - constexpr auto reader_fn = [](const void* obj, const reader_t* reader, void* value) - { - const auto& obj_ = *reinterpret_cast(obj); - const auto& reader_ = *reinterpret_cast(reader); - auto& value_ = *reinterpret_cast(value); - value_ = read(reader_, obj_); - }; - constexpr auto writer_fn = [](void* obj, const writer_t* writer, void* value) - { - auto& obj_ = *reinterpret_cast(obj); - const auto& writer_ = *reinterpret_cast(writer); - move_qualified value_ = std::move(*reinterpret_cast(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(obj); + const auto& reader_ = *reinterpret_cast(reader); + auto& value_ = *reinterpret_cast(value); + value_ = read(reader_, obj_); + }; + constexpr auto writer_fn = [](void* obj, const writer_t* writer, void* value) + { + auto& obj_ = *reinterpret_cast(obj); + const auto& writer_ = *reinterpret_cast(writer); + move_qualified value_ = std::move(*reinterpret_cast(value)); + write(writer_, obj_, value_); + }; + return erased_accessor { + (void*)&reader, writer ? (void*)&writer : nullptr, + obj_name, field_name, + reader_fn, writer_fn, + }; +} template struct Entity final { @@ -239,7 +230,7 @@ template requires std::is_same_v> class entity_metadata final { template - static constexpr auto erased_helper(const std::tuple& tuple) + static consteval auto erased_helper(const std::tuple& tuple) { std::array array { std::get(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 -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 constexpr inline Corrade::Containers::StringView name_of = _name_of(); +template constexpr inline auto name_of = _name_of(); 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 namespace Corrade::Containers { - template class BasicStringView; using StringView = BasicStringView; - } // namespace Corrade::Containers namespace floormat::entities { diff --git a/test/entity.cpp b/test/entity.cpp index 2b46cbeb..8f966572 100644 --- a/test/entity.cpp +++ b/test/entity.cpp @@ -129,7 +129,6 @@ static void test_metadata() static void test_type_name() { - using namespace entities; struct foobar; constexpr StringView name = name_of; fm_assert(name.contains("foobar"_s)); -- cgit v1.2.3