scsl  1.0.2
Shimmering Clarity Standard Library
SimpleConfig.h
Go to the documentation of this file.
1 
27 #ifndef SCSL_SIMPLECONFIG_H
28 #define SCSL_SIMPLECONFIG_H
29 
30 
31 #include <map>
32 #include <string>
33 #include <vector>
34 
35 
36 namespace scsl {
37 
38 
67 class SimpleConfig {
68 public:
69 #if defined(SCSL_DESKTOP_BUILD)
76  static int LoadGlobal(const char *path);
77 
84  static int LoadGlobal(std::string &path);
85 
92  static void SetPrefixGlobal(const std::string &prefix);
93 
102  static std::vector<std::string> KeyListGlobal();
103 
111  static std::string GetGlobal(std::string &key);
112 
123  static std::string GetGlobal(std::string &key, const std::string &defaultValue);
124 #endif
125 
128 
131  explicit SimpleConfig(std::string &prefix);
132 
137  int Load(const char *path);
138 
143  int Load(std::string& path);
144 
149  void SetPrefix(const std::string &prefix);
150 
157  std::vector<std::string> KeyList();
158 
164  std::string Get(std::string &key);
165 
174  std::string Get(std::string &key, std::string defaultValue);
175 
176 private:
177  std::string envPrefix;
178  std::map<std::string, std::string> vars;
179 };
180 
181 
182 } // namespace scsl
183 
184 
185 #endif //SCSL_SIMPLECONFIG_H
SimpleConfig is a basic configuration for projects.
Definition: SimpleConfig.h:67
std::string Get(std::string &key, std::string defaultValue)
Get the value stored for the key from the config.
int Load(std::string &path)
Load key-value pairs from a file.
std::string Get(std::string &key)
Get the value stored for the key from the config.
std::vector< std::string > KeyList()
Return the keys cached in the config.
int Load(const char *path)
Load key-value pairs from a file.
SimpleConfig()
The constructor doesn't need any initialisation.
void SetPrefix(const std::string &prefix)
Set the prefix in use by the config.
SimpleConfig(std::string &prefix)
The constructor can explicitly set the environment prefix.
scsl is the top-level namespace containing all the code in this library.
Definition: scsl.h:43