2018-06-10 16:28:03 +00:00
|
|
|
#ifndef SAPPHIRE_CONFIGMGR_H
|
|
|
|
#define SAPPHIRE_CONFIGMGR_H
|
|
|
|
|
|
|
|
#include <boost/property_tree/ptree.hpp>
|
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
namespace Core {
|
|
|
|
class ConfigMgr
|
2018-06-10 16:28:03 +00:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
public:
|
|
|
|
ConfigMgr() = default;
|
|
|
|
|
|
|
|
~ConfigMgr() = default;
|
|
|
|
|
|
|
|
bool loadConfig( const std::string& configName );
|
|
|
|
|
|
|
|
template< class T >
|
|
|
|
T getValue( const std::string& name, T defaultValue = T() )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return m_propTree.get< T >( name );
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template< class T >
|
|
|
|
void setValue( const std::string& name, T defaultValue = T() )
|
|
|
|
{
|
|
|
|
m_propTree.put( name, defaultValue );
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool copyDefaultConfig( const std::string& configName );
|
|
|
|
|
|
|
|
boost::property_tree::ptree m_propTree;
|
|
|
|
const std::string m_globalConfigFile = "global.ini";
|
|
|
|
const std::string m_configFolderRoot = "./config/";
|
|
|
|
const std::string m_configDefaultSuffix = ".default";
|
|
|
|
};
|
2018-06-10 16:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif //SAPPHIRE_CONFIGMGR_H
|