// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include namespace Nz { /*! * \ingroup core * \class Nz::ObjectLibrary * \brief Core class containing a collection of objects */ /*! * \brief Clears the library, freeing every object it contains */ template void ObjectLibrary::Clear() { m_library.clear(); } /*! * \brief Gets the std::shared_ptr object by name * \return Optional reference * * \param name Name of the object * * \remark Produces a NazaraError if object not found */ template std::shared_ptr ObjectLibrary::Get(std::string_view name) { std::shared_ptr ref = Query(name); if (!ref) NazaraErrorFmt("Object \"{}\" is not present", name); return ref; } /*! * \brief Checks whether the library has the object with that name * \return true if it the case */ template bool ObjectLibrary::Has(std::string_view name) { return m_library.contains(name); } /*! * \brief Registers the std::shared_ptr object with that name * * \param name Name of the object * \param object Object to stock */ template void ObjectLibrary::Register(std::string name, std::shared_ptr object) { m_library.emplace(std::move(name), object); } /*! * \brief Gets the std::shared_ptr object by name * \return Optional reference * * \param name Name of the object */ template std::shared_ptr ObjectLibrary::Query(std::string_view name) { auto it = m_library.find(name); if (it != m_library.end()) return it->second; else return nullptr; } /*! * \brief Unregisters the std::shared_ptr object with that name * * \param name Name of the object */ template void ObjectLibrary::Unregister(std::string_view name) { m_library.erase(name); } } #include