mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-30 08:07:46 +00:00
69 lines
2.2 KiB
C++
69 lines
2.2 KiB
C++
#ifndef SAPPHIRE_CONFIGMGR_H
|
|
#define SAPPHIRE_CONFIGMGR_H
|
|
|
|
#include <memory>
|
|
#include <type_traits>
|
|
#include <inih/INIReader.h>
|
|
#include <string>
|
|
#include <stdint.h>
|
|
|
|
namespace Core {
|
|
class ConfigMgr
|
|
{
|
|
public:
|
|
ConfigMgr() = default;
|
|
|
|
~ConfigMgr() = default;
|
|
|
|
bool loadConfig( const std::string& configName );
|
|
|
|
template<class T> struct always_false : std::false_type {};
|
|
|
|
template< class T >
|
|
T getValue( const std::string& name, T defaultValue = T() )
|
|
{
|
|
if constexpr (std::is_same_v<T, uint32_t>)
|
|
return m_pInih->GetInteger( "", name, defaultValue );
|
|
else if constexpr (std::is_same_v<T, int32_t>)
|
|
return m_pInih->GetInteger( "", name, defaultValue );
|
|
else if constexpr (std::is_same_v<T, uint16_t>)
|
|
return m_pInih->GetInteger( "", name, defaultValue );
|
|
else if constexpr (std::is_same_v<T, int16_t>)
|
|
return m_pInih->GetInteger( "", name, defaultValue );
|
|
else if constexpr (std::is_same_v<T, uint8_t>)
|
|
return m_pInih->GetInteger( "", name, defaultValue );
|
|
else if constexpr (std::is_same_v<T, int8_t>)
|
|
return m_pInih->GetInteger( "", name, defaultValue );
|
|
else if constexpr (std::is_same_v<T, long>)
|
|
return m_pInih->GetInteger( "", name, defaultValue );
|
|
else if constexpr (std::is_same_v<T, double>)
|
|
return m_pInih->GetReal( "", name, defaultValue );
|
|
else if constexpr (std::is_same_v<T, float>)
|
|
return m_pInih->GetReal( "", name, defaultValue );
|
|
else if constexpr (std::is_same_v<T, std::string>)
|
|
return m_pInih->Get( "", name, defaultValue );
|
|
else if constexpr (std::is_same_v<T, bool>)
|
|
return m_pInih->GetBoolean( "", name, defaultValue );
|
|
else
|
|
static_assert(always_false<T>::value, "non-exhaustive getter!");
|
|
}
|
|
|
|
template< class T >
|
|
void setValue( const std::string& name, T defaultValue = T() )
|
|
{
|
|
// TODO: reimplement this...
|
|
//m_propTree.put( name, defaultValue );
|
|
}
|
|
|
|
private:
|
|
bool copyDefaultConfig( const std::string& configName );
|
|
|
|
std::unique_ptr< INIReader > m_pInih;
|
|
|
|
const std::string m_globalConfigFile = "global.ini";
|
|
const std::string m_configFolderRoot = "./config/";
|
|
const std::string m_configDefaultSuffix = ".default";
|
|
};
|
|
}
|
|
|
|
#endif //SAPPHIRE_CONFIGMGR_H
|