From 0533360642ff320a1a7d25ed2911a6c44de8d6e9 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 19 Nov 2022 07:27:49 +0100 Subject: entity: add field enablement predicate --- entity/metadata.hpp | 4 ++-- test/entity.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/entity/metadata.hpp b/entity/metadata.hpp index a35e0cc6..dc7d9f1d 100644 --- a/entity/metadata.hpp +++ b/entity/metadata.hpp @@ -211,10 +211,10 @@ constexpr erased_accessor entity_field::erased() const return erased_accessor { (void*)&reader, writer ? (void*)&writer : nullptr, - std::is_same_v ? (const void*)&predicate : nullptr, + !std::is_same_v ? (const void*)&predicate : nullptr, name, obj_name, field_name, reader_fn, writer ? writer_fn : writer_stub_fn, - std::is_same_v ? predicate_fn : predicate_stub_fn, + !std::is_same_v ? predicate_fn : predicate_stub_fn, }; } diff --git a/test/entity.cpp b/test/entity.cpp index 858c5a11..5db83974 100644 --- a/test/entity.cpp +++ b/test/entity.cpp @@ -155,6 +155,22 @@ constexpr bool test_null_writer() return true; } +void test_predicate() +{ + constexpr TestAccessors x{0, 0, 0}; + constexpr auto m_foo = entity::type::field{"foo"_s, &TestAccessors::foo, &TestAccessors::foo, + [](const TestAccessors&) { return false; }}; + static_assert(!m_foo.is_enabled(m_foo.predicate, x)); + fm_assert(!m_foo.erased().is_enabled(x)); + constexpr auto m_foo2 = entity::type::field{"foo"_s, &TestAccessors::foo, &TestAccessors::foo, + [](const TestAccessors&) { return true; }}; + static_assert(m_foo2.is_enabled(m_foo2.predicate, x)); + fm_assert(m_foo2.erased().is_enabled(x)); + constexpr auto m_foo3 = entity::type::field{"foo"_s, &TestAccessors::foo, &TestAccessors::foo}; + static_assert(m_foo3.is_enabled(m_foo3.predicate, x)); + fm_assert(m_foo3.erased().is_enabled(x)); +} + } // namespace static constexpr bool test_names() @@ -179,6 +195,7 @@ void test_app::test_entity() static_assert(test_visitor()); static_assert(test_null_writer()); static_assert(test_names()); + test_predicate(); test_fun2(); test_erasure(); test_type_name(); -- cgit v1.2.3