// Copyright (C) 2022 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 #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(const std::string& name) { std::shared_ptr ref = Query(name); if (!ref) NazaraError("Object \"" + name + "\" is not present"); return ref; } /*! * \brief Checks whether the library has the object with that name * \return true if it the case */ template bool ObjectLibrary::Has(const std::string& name) { return m_library.find(name) != m_library.end(); } /*! * \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(const std::string& name, std::shared_ptr object) { m_library.emplace(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(const std::string& 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(const std::string& name) { m_library.erase(name); } } #include