Simple SFML GUI  0.2a
Configurator.hpp
1 #ifndef CONFIGURATOR_HPP
2 #define CONFIGURATOR_HPP
3 
4 #include <map>
5 #include <memory>
6 #include "StringConvertible.hpp"
7 #include "PtrStringCovertible.hpp"
8 
9 #define addConfVar(VAR){\
10  auto ptr = std::make_shared<PtrStringConvertible<decltype(VAR)>>(&VAR);\
11  Configurator::connectConfigurationVariable(ptr, #VAR);\
12 }
13 
14 #define addNamedConfVar(NAME, VAR){\
15  auto ptr = std::make_shared<PtrStringConvertible<decltype(VAR)>>(&VAR);\
16  Configurator::connectConfigurationVariable(ptr, #NAME);\
17 }
18 
19 #define delConfVar(VAR) Configurator::detachConfigurationVariable(#VAR)
20 
21 #define relConfVar(VAR) Configurator::reloadVarFromCache(#VAR)
22 
23 #define sscMapAddVar(MAP,VAR) MAP[#VAR]=std::make_shared<PtrStringConvertible<decltype(VAR)>>(&VAR)
24 
25 #define varPair(VAR) {#VAR, std::make_shared<PtrStringConvertible<decltype(VAR)>>(&VAR)}
26 
27 
28 typedef std::map<std::string, std::string> StringStringMap;
29 typedef std::map<std::string, StringConvertiblePtr> StringStringConvertibleMap;
30 
31 class Configurator {
32 public:
33  static void connectConfigurationVariable(const StringConvertiblePtr&, const std::string&&);
34  static bool detachConfigurationVariable(const std::string&&);
35  static bool save(const std::string& path = "");
36  static bool load(const std::string& path = "", bool logError = true);
37  static std::string getRawParameterValue(const std::string&& name);
38  static std::string getDefaultConfigurationPath();
39  static void setDefaultConfigurationPath(const std::string& value);
40  static bool writeVars(const sf::String&, StringStringConvertibleMap&&, StringStringMap* ssMap = nullptr);
41  static bool loadVars(const sf::String&, StringStringConvertibleMap&&, StringStringMap* ssMap = nullptr, bool logError = true);
42  static bool reloadVarFromCache(const std::string&& s = "");
43 
44 protected:
45  static StringStringConvertibleMap configVars;
46  static StringStringMap configMap;
47  static std::string defaultConfigurationPath;
48 
49 private:
50  Configurator() {}
51 
52 };
53 
54 #endif // CONFIGURATOR_HPP
Definition: Configurator.hpp:31