scsl  1.1.1
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 
120  static std::string GetGlobal(const char *key);
121 
132  static std::string GetGlobal(const char *key, const std::string &defaultValue);
133 
144  static std::string GetGlobal(std::string &key, const std::string &defaultValue);
145 
148  static void PutGlobal(std::string &key, const std::string &value);
149 
152  static void PutGlobal(const char *key, const std::string &value);
153 #endif
154 
157 
160  explicit SimpleConfig(std::string &prefix);
161 
166  int Load(const char *path);
167 
172  int Load(std::string& path);
173 
178  void SetPrefix(const std::string &prefix);
179 
186  std::vector<std::string> KeyList();
187 
193  std::string Get(std::string &key);
194 
200  std::string Get(const char *key);
201 
210  std::string Get(std::string &key, std::string defaultValue);
211 
220  std::string Get(const char *key, std::string defaultValue);
221 
228  void Put(std::string &key, const std::string value);
229 
236  void Put(const char *key, const std::string value);
237 private:
238  std::string envPrefix;
239  std::map<std::string, std::string> vars;
240 };
241 
242 
243 } // namespace scsl
244 
245 
246 #endif //SCSL_SIMPLECONFIG_H
SimpleConfig is a basic configuration for projects.
Definition: SimpleConfig.h:67
void Put(const char *key, const std::string value)
Set a configuration value. This will override any value set.
void Put(std::string &key, const std::string value)
Set a configuration value. This will override any value set.
std::string Get(const char *key)
Get the value stored for the key from the config.
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.
std::string Get(const char *key, std::string defaultValue)
Get the value stored for the key from 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