Core/ApplicationBase: GetComponent can no longer fail

This commit is contained in:
SirLynix
2023-05-20 21:35:10 +02:00
parent 35c498bf21
commit 580b3c8804
2 changed files with 10 additions and 10 deletions

View File

@@ -51,23 +51,23 @@ namespace Nz
}
template<typename T>
T* ApplicationBase::GetComponent()
T& ApplicationBase::GetComponent()
{
std::size_t componentIndex = ApplicationComponentRegistry<T>::GetComponentId();
if (componentIndex >= m_components.size())
return nullptr;
if (componentIndex >= m_components.size() || !m_components[componentIndex])
throw std::runtime_error("component not found");
return static_cast<T*>(m_components[componentIndex].get());
return static_cast<T&>(*m_components[componentIndex]);
}
template<typename T>
const T* ApplicationBase::GetComponent() const
const T& ApplicationBase::GetComponent() const
{
std::size_t componentIndex = ApplicationComponentRegistry<T>::GetComponentId();
if (componentIndex >= m_components.size())
return nullptr;
if (componentIndex >= m_components.size() || !m_components[componentIndex])
throw std::runtime_error("component not found");
return static_cast<const T*>(m_components[componentIndex].get());
return static_cast<const T&>(*m_components[componentIndex]);
}
inline void ApplicationBase::Quit()