Added ability to save to ConfigFile
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "ResourceManager.h"
|
||||
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
@@ -20,15 +19,28 @@ private:
|
||||
|
||||
public:
|
||||
template <typename T>
|
||||
T GetValue(std::string key, T defaultValue)
|
||||
{
|
||||
return m_ptree.get<T>(key, defaultValue);
|
||||
}
|
||||
T GetValue(std::string key, T defaultValue);
|
||||
template <typename T>
|
||||
void SetValue(std::string key, T value);
|
||||
|
||||
void SaveToDisk();
|
||||
|
||||
private:
|
||||
boost::property_tree::ptree m_ptree;
|
||||
|
||||
std::string m_Path;
|
||||
boost::property_tree::ptree m_Ptree;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
T ConfigFile::GetValue(std::string key, T defaultValue)
|
||||
{
|
||||
return m_Ptree.get<T>(key, defaultValue);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void ConfigFile::SetValue(std::string key, T value)
|
||||
{
|
||||
m_Ptree.put<T>(key, value);
|
||||
}
|
||||
|
||||
};
|
||||
#endif // ConfigFile_h__
|
||||
|
||||
@@ -3,5 +3,15 @@
|
||||
|
||||
dd::ConfigFile::ConfigFile(std::string path)
|
||||
{
|
||||
boost::property_tree::ini_parser::read_ini(path, m_ptree);
|
||||
}
|
||||
m_Path = path;
|
||||
try {
|
||||
boost::property_tree::ini_parser::read_ini(path, m_Ptree);
|
||||
} catch (boost::property_tree::ptree_error& e) {
|
||||
LOG_ERROR("Failed to load %s", path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void dd::ConfigFile::SaveToDisk()
|
||||
{
|
||||
boost::property_tree::ini_parser::write_ini(m_Path, m_Ptree);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user