Make ecs::entity_accessor::get throw the documented exception

This commit is contained in:
Nikita Lisitsa 2023-08-24 16:19:49 +03:00
parent 6bab38a545
commit d3fa7fdfea

View file

@ -19,10 +19,10 @@ namespace psemek::ecs
using query_cache = std::shared_ptr<detail::query_cache>;
struct component_exception
struct component_not_found_exception
: util::exception
{
component_exception(std::type_info const & type, entity_handle const & handle, boost::stacktrace::stacktrace stacktrace = {})
component_not_found_exception(std::type_info const & type, entity_handle const & handle, boost::stacktrace::stacktrace stacktrace = {})
: util::exception(util::to_string("Component ", util::type_name(type), " not found for entity ", handle), std::move(stacktrace))
, type_(type)
, handle_(handle)
@ -60,7 +60,7 @@ namespace psemek::ecs
/** Obtain a reference to the specified component type
* of the accessed entity.
* If the entity doesn't contain this component type,
* an exception of type `component_exception` is thrown.
* an exception of type `component_not_found_exception` is thrown.
*/
template <typename Component>
Component & get();
@ -323,8 +323,7 @@ namespace psemek::ecs
{
if (auto ptr = get_if<Component>())
return *ptr;
assert(false);
__builtin_unreachable();
throw component_not_found_exception(typeid(Component), table_->get_entity_handles()[row_]);
}
template <typename Component>