Add ecs::accessor::contains(uuid)

This commit is contained in:
Nikita Lisitsa 2024-06-27 16:51:25 +03:00
parent b73a37deea
commit e55a98c2a0

View file

@ -61,6 +61,15 @@ namespace psemek::ecs
template <typename Component>
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<Component const>() != 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)