loader.hpp 868 B

123456789101112131415161718192021222324252627282930313233
  1. #ifndef ENTT_RESOURCE_LOADER_HPP
  2. #define ENTT_RESOURCE_LOADER_HPP
  3. #include <memory>
  4. #include <utility>
  5. #include "fwd.hpp"
  6. namespace entt {
  7. /**
  8. * @brief Transparent loader for shared resources.
  9. * @tparam Type Type of resources created by the loader.
  10. */
  11. template<typename Type>
  12. struct resource_loader {
  13. /*! @brief Result type. */
  14. using result_type = std::shared_ptr<Type>;
  15. /**
  16. * @brief Constructs a shared pointer to a resource from its arguments.
  17. * @tparam Args Types of arguments to use to construct the resource.
  18. * @param args Parameters to use to construct the resource.
  19. * @return A shared pointer to a resource of the given type.
  20. */
  21. template<typename... Args>
  22. result_type operator()(Args &&...args) const {
  23. return std::make_shared<Type>(std::forward<Args>(args)...);
  24. }
  25. };
  26. } // namespace entt
  27. #endif