Making block solids

This commit is contained in:
Zoe Roux
2021-06-06 16:54:27 +02:00
parent 0ebfa77e1a
commit 01ea9053fa
8 changed files with 70 additions and 32 deletions

View File

@@ -79,6 +79,32 @@ namespace WAL
return static_cast<T *>(existing->second.get());
}
//! @brief Get a component of a specific type
//! @tparam The type of the component
//! @throw NotFoundError if the component could not be found
//! @return The component of the requested type.
template<typename T>
const T &getComponent() const
{
const T *ret = this->tryGetComponent<T>();
if (ret == nullptr)
throw NotFoundError("No component could be found with the type \"" + std::string(typeid(T).name()) + "\".");
return *ret;
}
//! @brief Get a component of a specific type or null if not found.
//! @tparam The type of the component
//! @return The component or nullptr if not found.
template<typename T>
const T *tryGetComponent() const
{
const std::type_index &type = typeid(T);
auto existing = this->_components.find(type);
if (existing == this->_components.end())
return nullptr;
return static_cast<T *>(existing->second.get());
}
//! @brief Check if this entity has a component.
//! @tparam T The type of the component
template<typename T>