TGUI  0.9-dev
ThemeLoader.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2021 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25
26#ifndef TGUI_THEME_LOADER_HPP
27#define TGUI_THEME_LOADER_HPP
28
29
30#include <TGUI/String.hpp>
31#include <TGUI/Loading/DataIO.hpp>
32#include <memory>
33#include <string>
34#include <vector>
35#include <map>
36#include <set>
37
39
40namespace tgui
41{
45 class TGUI_API BaseThemeLoader
46 {
47 public:
48
52 virtual ~BaseThemeLoader() = default;
53
54
60 virtual void preload(const String& primary);
61
62
73 virtual const std::map<String, String>& load(const String& primary, const String& secondary) = 0;
74
75
86 virtual bool canLoad(const String& primary, const String& secondary) = 0;
87
88
90 protected:
91
92
94 // Turns texture and font filenames into paths relative to the theme file
96 void injectThemePath(const std::unique_ptr<DataIO::Node>& node, const String& path) const;
97
98
100 // Resolves references to sections
102 void resolveReferences(std::map<String, std::reference_wrapper<const std::unique_ptr<DataIO::Node>>>& sections, const std::unique_ptr<DataIO::Node>& node) const;
103
104
106 };
107
108
117 class TGUI_API DefaultThemeLoader : public BaseThemeLoader
118 {
119 public:
120
128 void preload(const String& filename) override;
129
130
142 const std::map<String, String>& load(const String& filename, const String& section) override;
143
144
153 bool canLoad(const String& filename, const String& section) override;
154
155
162 static void flushCache(const String& filename = "");
163
164
166 protected:
167
175 virtual std::unique_ptr<DataIO::Node> readFile(const String& filename) const;
176
177
179 protected:
180 static std::map<String, std::map<String, std::map<String, String>>> m_propertiesCache;
181 };
182
183
185}
186
188
189#endif // TGUI_THEME_LOADER_HPP
Base class for theme loader implementations.
Definition: ThemeLoader.hpp:46
virtual bool canLoad(const String &primary, const String &secondary)=0
Check if the requested property-value pairs are available.
virtual void preload(const String &primary)
Optionally already do some work when only the primary parameter is known yet.
virtual const std::map< String, String > & load(const String &primary, const String &secondary)=0
Loads the property-value pairs from the theme.
virtual ~BaseThemeLoader()=default
Virtual destructor.
Default implementation for theme loading.
Definition: ThemeLoader.hpp:118
static void flushCache(const String &filename="")
Empties the caches and force files to be reloaded.
bool canLoad(const String &filename, const String &section) override
Check if the requested property-value pairs are available.
const std::map< String, String > & load(const String &filename, const String &section) override
Loads the property-value pairs from the theme file.
virtual std::unique_ptr< DataIO::Node > readFile(const String &filename) const
Reads and return the contents of the entire file.
void preload(const String &filename) override
Loads the theme file in cache.
Wrapper class to store strings.
Definition: String.hpp:79
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36