Core/ApplicationBase: GetComponent can no longer fail
This commit is contained in:
parent
35c498bf21
commit
580b3c8804
|
|
@ -36,8 +36,8 @@ namespace Nz
|
|||
|
||||
inline void ClearComponents();
|
||||
|
||||
template<typename T> T* GetComponent();
|
||||
template<typename T> const T* GetComponent() const;
|
||||
template<typename T> T& GetComponent();
|
||||
template<typename T> const T& GetComponent() const;
|
||||
|
||||
int Run();
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue