2011-04-06 21:46:58 +02:00
|
|
|
#ifndef CONFIGS_H
|
|
|
|
#define CONFIGS_H
|
2010-11-21 22:48:58 +01:00
|
|
|
|
2011-07-13 23:12:36 +02:00
|
|
|
#include <global.h>
|
2010-11-21 22:48:58 +01:00
|
|
|
|
2011-05-20 02:03:15 +02:00
|
|
|
struct ConfigValueProxy {
|
2011-07-27 01:13:27 +02:00
|
|
|
ConfigValueProxy(const std::string& v) : value(v) { }
|
2011-07-13 23:12:36 +02:00
|
|
|
operator std::string() const { return convert<std::string>(value); }
|
|
|
|
operator float() const { return convert<float>(value); }
|
|
|
|
operator int() const { return convert<int>(value); }
|
|
|
|
operator bool() const { return convert<bool>(value); }
|
2011-05-20 01:56:27 +02:00
|
|
|
std::string value;
|
|
|
|
};
|
|
|
|
|
2011-04-06 21:46:58 +02:00
|
|
|
class Configs
|
2010-11-21 22:48:58 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool load(const std::string& fileName);
|
|
|
|
void save();
|
|
|
|
|
2011-07-13 23:12:36 +02:00
|
|
|
template<class T>
|
|
|
|
void set(const std::string& key, const T& value) { m_confsMap[key] = convert<std::string>(value); }
|
|
|
|
|
2011-07-27 01:13:27 +02:00
|
|
|
ConfigValueProxy get(const std::string& key) { return ConfigValueProxy(m_confsMap[key]); }
|
2010-11-21 22:48:58 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_fileName;
|
|
|
|
std::map<std::string, std::string> m_confsMap;
|
|
|
|
};
|
|
|
|
|
2011-04-06 22:53:00 +02:00
|
|
|
extern Configs g_configs;
|
2010-11-21 22:48:58 +01:00
|
|
|
|
2011-04-06 21:46:58 +02:00
|
|
|
#endif // CONFIGS_H
|