From 7724937b96187b6d6d35818ab4c5eb24721adfee Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 7 Jun 2022 03:43:44 +0200 Subject: use StringView in resource api --- loader-impl.cpp | 24 ++++++++++++------------ loader.hpp | 7 ++++--- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/loader-impl.cpp b/loader-impl.cpp index 2e82faf5..a0f316c8 100644 --- a/loader-impl.cpp +++ b/loader-impl.cpp @@ -2,11 +2,11 @@ #include "loader.hpp" #include "atlas.hpp" #include +#include #include #include #include #include -#include #include #include @@ -23,23 +23,23 @@ struct loader_impl final : loader_ std::unordered_map atlas_map; - std::string shader(const std::string& filename) override; - Trade::ImageData2D tile_texture(const std::string& filename) override; - atlas_ptr tile_atlas(const std::string& filename, Vector2i size) override; + std::string shader(const Containers::StringView& filename) override; + Trade::ImageData2D tile_texture(const Containers::StringView& filename) override; + atlas_ptr tile_atlas(const Containers::StringView& filename, Vector2i size) override; explicit loader_impl(); ~loader_impl() override; }; -std::string loader_impl::shader(const std::string& filename) +std::string loader_impl::shader(const Containers::StringView& filename) { - auto ret = shader_res.get(filename); - if (ret.empty()) - ABORT("can't find shader resource '%s'", filename.c_str()); + auto ret = shader_res.getString(filename); + if (ret.isEmpty()) + ABORT("can't find shader resource '%s'", filename.cbegin()); return ret; } -atlas_ptr loader_impl::tile_atlas(const std::string& name, Vector2i size) +atlas_ptr loader_impl::tile_atlas(const Containers::StringView& name, Vector2i size) { auto it = atlas_map.find(name); if (it != atlas_map.end()) @@ -49,13 +49,13 @@ atlas_ptr loader_impl::tile_atlas(const std::string& name, Vector2i size) return atlas; } -Trade::ImageData2D loader_impl::tile_texture(const std::string& filename) +Trade::ImageData2D loader_impl::tile_texture(const Containers::StringView& filename) { if(!tga_importer || !tga_importer->openFile(filename)) - ABORT("can't open tile image '%s'", filename.c_str()); + ABORT("can't open tile image '%s'", filename.cbegin()); auto img = tga_importer->image2D(0); if (!img) - ABORT("can't allocate tile image for '%s'", filename.c_str()); + ABORT("can't allocate tile image for '%s'", filename.cbegin()); auto ret = std::move(*img); return ret; } diff --git a/loader.hpp b/loader.hpp index 4a0f8855..5608614c 100644 --- a/loader.hpp +++ b/loader.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -12,9 +13,9 @@ struct atlas_texture; struct loader_ { - virtual std::string shader(const std::string& filename) = 0; - virtual Trade::ImageData2D tile_texture(const std::string& filename) = 0; - virtual std::shared_ptr tile_atlas(const std::string& filename, Vector2i size) = 0; + virtual std::string shader(const Containers::StringView& filename) = 0; + virtual Trade::ImageData2D tile_texture(const Containers::StringView& filename) = 0; + virtual std::shared_ptr tile_atlas(const Containers::StringView& filename, Vector2i size) = 0; static void destroy(); loader_(const loader_&) = delete; -- cgit v1.2.3