diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-06-07 03:43:44 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-06-07 03:43:44 +0200 |
commit | 7724937b96187b6d6d35818ab4c5eb24721adfee (patch) | |
tree | 5ab92280ffa6a69988a954d9679e42584b7fbdd0 | |
parent | 7fb2ba3b4b7d45eceb289356eef67a0118d12c89 (diff) |
use StringView in resource api
-rw-r--r-- | loader-impl.cpp | 24 | ||||
-rw-r--r-- | 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 <Corrade/Containers/Optional.h> +#include <Corrade/Containers/StringView.h> #include <Corrade/PluginManager/PluginManager.h> #include <Corrade/Utility/Resource.h> #include <Magnum/Trade/AbstractImporter.h> #include <Magnum/Trade/ImageData.h> -#include <string> #include <unordered_map> #include <utility> @@ -23,23 +23,23 @@ struct loader_impl final : loader_ std::unordered_map<std::string, atlas_ptr> 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; } @@ -1,5 +1,6 @@ #pragma once +#include <Corrade/Containers/StringView.h> #include <Magnum/Trade/ImageData.h> #include <string> @@ -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<atlas_texture> 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<atlas_texture> tile_atlas(const Containers::StringView& filename, Vector2i size) = 0; static void destroy(); loader_(const loader_&) = delete; |