TGUI  0.8-dev
ThemeLoader.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2017 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/Config.hpp>
31 #include <SFML/System/String.hpp>
32 #include <memory>
33 #include <string>
34 #include <vector>
35 #include <map>
36 
38 
39 namespace tgui
40 {
44  class TGUI_API BaseThemeLoader
45  {
46  public:
47 
51  virtual ~BaseThemeLoader() = default;
52 
53 
59  virtual void preload(const std::string& primary);
60 
61 
72  virtual const std::map<sf::String, sf::String>& load(const std::string& primary, const std::string& secondary) = 0;
73 
74 
85  virtual bool canLoad(const std::string& primary, const std::string& secondary) = 0;
86 
87 
89  };
90 
91 
100  class TGUI_API DefaultThemeLoader : public BaseThemeLoader
101  {
102  public:
103 
111  void preload(const std::string& filename) override;
112 
113 
125  const std::map<sf::String, sf::String>& load(const std::string& filename, const std::string& section) override;
126 
127 
136  bool canLoad(const std::string& filename, const std::string& section) override;
137 
138 
145  static void flushCache(const std::string& filename = "");
146 
147 
149  protected:
150 
158  virtual void readFile(const std::string& filename, std::stringstream& contents) const;
159 
160 
162  private:
163  static std::map<std::string, std::map<std::string, std::map<sf::String, sf::String>>> m_propertiesCache;
164 
165  friend struct DefaultThemeLoaderTest; // Used for testing m_propertiesCache
166  };
167 
168 
170 }
171 
173 
174 #endif // TGUI_THEME_LOADER_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Default implementation for theme loading.
Definition: ThemeLoader.hpp:100
Base class for theme loader implementations.
Definition: ThemeLoader.hpp:44