TGUI  0.9-dev
ThemeLoader.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2020 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 <memory>
32 #include <string>
33 #include <vector>
34 #include <map>
35 
37 
38 namespace tgui
39 {
43  class TGUI_API BaseThemeLoader
44  {
45  public:
46 
50  virtual ~BaseThemeLoader() = default;
51 
52 
58  virtual void preload(const String& primary);
59 
60 
71  virtual const std::map<String, String>& load(const String& primary, const String& secondary) = 0;
72 
73 
84  virtual bool canLoad(const String& primary, const String& secondary) = 0;
85 
86 
88  };
89 
90 
99  class TGUI_API DefaultThemeLoader : public BaseThemeLoader
100  {
101  public:
102 
110  void preload(const String& filename) override;
111 
112 
124  const std::map<String, String>& load(const String& filename, const String& section) override;
125 
126 
135  bool canLoad(const String& filename, const String& section) override;
136 
137 
144  static void flushCache(const String& filename = "");
145 
146 
148  protected:
149 
157  virtual void readFile(const String& filename, std::stringstream& contents) const;
158 
159 
161  private:
162  static std::map<String, std::map<String, std::map<String, String>>> m_propertiesCache;
163 
164  friend struct DefaultThemeLoaderTest; // Used for testing m_propertiesCache
165  };
166 
167 
169 }
170 
172 
173 #endif // TGUI_THEME_LOADER_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:35
Base class for theme loader implementations.
Definition: ThemeLoader.hpp:43
Default implementation for theme loading.
Definition: ThemeLoader.hpp:99
Wrapper class to store strings.
Definition: String.hpp:70