Show default options, missing in config files (#908)

This commit is contained in:
Kargatum
2018-06-05 18:14:57 +07:00
committed by José González
parent e222cbbc0a
commit f122ed57bf
2 changed files with 87 additions and 58 deletions

View File

@@ -6,6 +6,7 @@
#include "Config.h"
#include "Errors.h"
#include "Log.h"
// Defined here as it must not be exposed to end-users.
bool ConfigMgr::GetValueHelper(const char* name, ACE_TString &result)
@@ -86,6 +87,15 @@ bool ConfigMgr::LoadData(char const* file)
std::string ConfigMgr::GetStringDefault(const char* name, const std::string &def)
{
ACE_TString val;
if (GetValueHelper(name, val))
return val.c_str();
else
{
sLog->outError("-> Not found option '%s'. The default value is used (%s)", name, def.c_str());
return def;
}
return GetValueHelper(name, val) ? val.c_str() : def;
}
@@ -94,7 +104,10 @@ bool ConfigMgr::GetBoolDefault(const char* name, bool def)
ACE_TString val;
if (!GetValueHelper(name, val))
{
def ? sLog->outError("-> Not found option '%s'. The default value is used (Yes)", name) : sLog->outError(">> Not found option '%s'. The default value is used (No)", name);
return def;
}
return (val == "true" || val == "TRUE" || val == "yes" || val == "YES" ||
val == "1");
@@ -103,13 +116,27 @@ bool ConfigMgr::GetBoolDefault(const char* name, bool def)
int ConfigMgr::GetIntDefault(const char* name, int def)
{
ACE_TString val;
return GetValueHelper(name, val) ? atoi(val.c_str()) : def;
if (GetValueHelper(name, val))
return atoi(val.c_str());
else
{
sLog->outError("-> Not found option '%s'. The default value is used (%i)", name, def);
return def;
}
}
float ConfigMgr::GetFloatDefault(const char* name, float def)
{
ACE_TString val;
return GetValueHelper(name, val) ? (float)atof(val.c_str()) : def;
if (GetValueHelper(name, val))
return (float)atof(val.c_str());
else
{
sLog->outError("-> Not found option '%s'. The default value is used (%f)", name, def);
return def;
}
}
std::list<std::string> ConfigMgr::GetKeysByString(std::string const& name)