From bd0cd145010b7f076e0080c50eda8b4e2ed10758 Mon Sep 17 00:00:00 2001 From: Razakhel Date: Tue, 29 Sep 2020 18:33:27 +0200 Subject: [PATCH] [World] getSystem() can now be called from a constant World --- include/RaZ/World.hpp | 7 ++++++- include/RaZ/World.inl | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/RaZ/World.hpp b/include/RaZ/World.hpp index 13899532..01f609a0 100644 --- a/include/RaZ/World.hpp +++ b/include/RaZ/World.hpp @@ -26,8 +26,13 @@ class World { /// Gets a given system contained by the world. /// This system must be present within the world. If not, an exception is thrown. /// \tparam Sys Type of the system to be fetched. + /// \return Constant reference to the found system. + template const Sys& getSystem() const; + /// Gets a given system contained by the world. + /// This system must be present within the world. If not, an exception is thrown. + /// \tparam Sys Type of the system to be fetched. /// \return Reference to the found system. - template Sys& getSystem(); + template Sys& getSystem() { return const_cast(static_cast(this)->getSystem()); } /// Adds a given system to the world. /// \tparam Sys Type of the system to be added. /// \tparam Args Types of the arguments to be forwarded to the given system. diff --git a/include/RaZ/World.inl b/include/RaZ/World.inl index a690cba9..f27f62b2 100644 --- a/include/RaZ/World.inl +++ b/include/RaZ/World.inl @@ -11,11 +11,11 @@ bool World::hasSystem() const { } template -Sys& World::getSystem() { +const Sys& World::getSystem() const { static_assert(std::is_base_of_v, "Error: Fetched system must be derived from System."); if (hasSystem()) - return static_cast(*m_systems[System::getId()]); + return static_cast(*m_systems[System::getId()]); throw std::runtime_error("Error: No system available of specified type"); }