Smolgui
Immediate gui library based on SFML
Loading...
Searching...
No Matches
ResourcesHolder.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4#include <memory>
5#include <string>
6#include <cassert>
7#include <unordered_map>
8#include <spdlog/spdlog.h>
9
10namespace sgui
11{
18template <typename Resource, typename Identifier = std::string>
20{
21public:
26 template <typename... Parameters>
27 bool load (
28 const Identifier& id,
29 const std::string& filename,
30 Parameters&&... args);
34 template <typename... Parameters>
35 bool reload (
36 const Identifier& id,
37 Parameters&&... args);
41 const Resource& get (const Identifier& id) const;
45 Resource& get (const Identifier& id);
46private:
47 // Hold resource and check that it has a unique id
48 void holdResource (
49 std::unique_ptr <Resource>&& resource,
50 const Identifier& id,
51 const std::string& filename);
52private:
53 std::unordered_map <Identifier, std::vector <std::string>> m_filesPath;
54 using PtrResource = std::unique_ptr <Resource>;
55 std::unordered_map <Identifier, PtrResource> m_resources;
56};
57
58} // namespace sgui
59
63// Forward declaration
64namespace sf {
65 class Texture;
66 class Shader;
67 class Font;
68 class SoundBuffer;
69}
70namespace sgui {
71 class TextContainer;
72 class TextureAtlas;
73 class Layout;
74 // sfml
75 using TextureHolder = ResourcesHolder <sf::Texture>;
76 using ShaderHolder = ResourcesHolder <sf::Shader>;
77 using SoundHolder = ResourcesHolder <sf::SoundBuffer>;
78 using FontHolder = ResourcesHolder <sf::Font>;
79 // sgui
80 using LayoutHolder = ResourcesHolder <Layout>;
81 using AtlasHolder = ResourcesHolder <TextureAtlas>;
82 using TextHolder = ResourcesHolder <TextContainer>;
83}
84
allow to store and load Gui layou
Definition Layout.h:33
load and hold resources of all kind (image, music, etc.), that can be retrieved with Identifier that ...
Definition ResourcesHolder.h:20
const Resource & get(const Identifier &id) const
get resource from its identifier, return first element if id was not registered
Resource & get(const Identifier &id)
get mutable resource from its identifier, return first element if id was not registered
bool reload(const Identifier &id, Parameters &&... args)
reload resource from file (will not work if load was not called before)
bool load(const Identifier &id, const std::string &filename, Parameters &&... args)
load resource from file. Note that for TextContainer or GuiLayout, you can store resource in several ...
store text accessible with a string key, with option to load and store text for a given tongue,...
Definition TextContainer.h:15
Contains texture position and sub-box of all sprites for a given sprite sheet. Animations ca be handl...
Definition TextureAtlas.h:28
Definition Interpolation.h:9
Definition Interpolation.h:16
ResourcesHolder< sf::Font > FontHolder
Definition ResourcesHolder.h:78
ResourcesHolder< sf::Shader > ShaderHolder
Definition ResourcesHolder.h:76
ResourcesHolder< sf::SoundBuffer > SoundHolder
Definition ResourcesHolder.h:77
ResourcesHolder< sf::Texture > TextureHolder
Definition ResourcesHolder.h:75
ResourcesHolder< TextureAtlas > AtlasHolder
Definition ResourcesHolder.h:81
ResourcesHolder< TextContainer > TextHolder
Definition ResourcesHolder.h:82
ResourcesHolder< Layout > LayoutHolder
Definition ResourcesHolder.h:80