From e55a98c2a0281419c0cec1fa1ebefbbf09268a32 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Thu, 27 Jun 2024 16:51:25 +0300 Subject: [PATCH] Add ecs::accessor::contains(uuid) --- libs/ecs/include/psemek/ecs/accessor.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libs/ecs/include/psemek/ecs/accessor.hpp b/libs/ecs/include/psemek/ecs/accessor.hpp index 678b2177..daa681fb 100644 --- a/libs/ecs/include/psemek/ecs/accessor.hpp +++ b/libs/ecs/include/psemek/ecs/accessor.hpp @@ -61,6 +61,15 @@ namespace psemek::ecs template bool contains() const; + /** Check if the entity contains this component type by uuid. + * + * @param uuid The uuid of the component + * @return True if the entity contains a component with the specified + * uuid, false otherwise + * @pre The accessor is valid + */ + bool contains(util::uuid const & uuid) const; + private: detail::table * table_ = nullptr; std::uint32_t row_ = 0; @@ -120,6 +129,11 @@ namespace psemek::ecs return get_if() != nullptr; } + inline bool accessor::contains(util::uuid const & uuid) const + { + return table_->column_index(uuid) != std::nullopt; + } + inline accessor::accessor(detail::table * table, std::uint32_t row) : table_(table) , row_(row)