You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.2 KiB
42 lines
1.2 KiB
/* Config.h |
|
* |
|
* Loads and stores configuration data in an INI-like format. |
|
*/ |
|
|
|
#pragma once |
|
|
|
#include <sstream> |
|
#include <string> |
|
#include <unordered_map> |
|
|
|
namespace PlipSdl { |
|
class Config { |
|
public: |
|
const std::string &GetValue(const std::string &key); |
|
const std::string &GetValue(const std::string §ion, const std::string &key); |
|
bool LoadFile(const std::string &filename); |
|
void SetValue(const std::string &key, const std::string &value); |
|
void SetValue(const std::string §ion, const std::string &key, const std::string &value); |
|
|
|
template<typename T> |
|
T GetValue(const std::string &key) { |
|
return GetValue<T>(global, key); |
|
} |
|
|
|
template<typename T> |
|
T GetValue(const std::string §ion, const std::string &key) { |
|
auto val = GetValue(section, key); |
|
T output; |
|
|
|
std::stringstream conversion(val); |
|
conversion >> output; |
|
return output; |
|
} |
|
|
|
const std::string global = "\x01"; |
|
const std::string empty = "\xff"; |
|
|
|
private: |
|
std::unordered_map<std::string, std::unordered_map<std::string, std::string>> m_section; |
|
}; |
|
}
|
|
|