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 {
45  class TGUI_API BaseThemeLoader
46  {
47  public:
48 
52  virtual ~BaseThemeLoader() = default;
53 
54 
61  virtual void preload(const std::string& primary);
62 
63 
75  virtual const std::map<sf::String, sf::String>& load(const std::string& primary, const std::string& secondary) = 0;
76 
77 
79  };
80 
81 
91  class TGUI_API DefaultThemeLoader : public BaseThemeLoader
92  {
93  public:
94 
103  virtual void preload(const std::string& filename) override;
104 
105 
118  virtual const std::map<sf::String, sf::String>& load(const std::string& filename, const std::string& section) override;
119 
120 
128  static void flushCache(const std::string& filename = "");
129 
130 
132  protected:
133 
141  virtual void readFile(const std::string& filename, std::stringstream& contents) const;
142 
143 
145  private:
146  static std::map<std::string, std::map<std::string, std::map<sf::String, sf::String>>> m_propertiesCache;
147 
148  friend struct DefaultThemeLoaderTest; // Used for testing m_propertiesCache
149  };
150 
151 
153 }
154 
156 
157 #endif // TGUI_THEME_LOADER_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Default implementation for theme loading.
Definition: ThemeLoader.hpp:91
Base class for theme loader implementations.
Definition: ThemeLoader.hpp:45