mirror of
https://github.com/edubart/otclient.git
synced 2025-12-19 15:17:12 +01:00
merge total remake
This commit is contained in:
33
src/framework/core/configmanager.h
Normal file
33
src/framework/core/configmanager.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef CONFIGMANAGER_H
|
||||
#define CONFIGMANAGER_H
|
||||
|
||||
#include <global.h>
|
||||
|
||||
struct ConfigValueProxy {
|
||||
ConfigValueProxy(const std::string& v) : value(v) { }
|
||||
operator std::string() const { return aux::unsafe_cast<std::string>(value); }
|
||||
operator float() const { return aux::unsafe_cast<float>(value); }
|
||||
operator int() const { return aux::unsafe_cast<int>(value); }
|
||||
operator bool() const { return aux::unsafe_cast<bool>(value); }
|
||||
std::string value;
|
||||
};
|
||||
|
||||
class ConfigManager
|
||||
{
|
||||
public:
|
||||
bool load(const std::string& fileName);
|
||||
bool save();
|
||||
|
||||
template<class T>
|
||||
void set(const std::string& key, const T& value) { m_confsMap[key] = aux::unsafe_cast<std::string>(value); }
|
||||
|
||||
ConfigValueProxy get(const std::string& key) { return ConfigValueProxy(m_confsMap[key]); }
|
||||
|
||||
private:
|
||||
std::string m_fileName;
|
||||
std::map<std::string, std::string> m_confsMap;
|
||||
};
|
||||
|
||||
extern ConfigManager g_configs;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user